diff --git a/classes/local/cli/clibase.php b/classes/local/cli/clibase.php index a22c096..2505284 100644 --- a/classes/local/cli/clibase.php +++ b/classes/local/cli/clibase.php @@ -102,6 +102,15 @@ abstract class clibase { $this->time = $time; } + /** + * Gets the reference time for creating outages. + */ + public function get_referencetime() + { + return $this->time; + } + + /** * Generates all options (parameters) available for the CLI command. * @return mixed[] Options. diff --git a/tests/phpunit/dml/outagedb_test.php b/tests/phpunit/dml/outagedb_test.php index d19bb6a..9d81721 100644 --- a/tests/phpunit/dml/outagedb_test.php +++ b/tests/phpunit/dml/outagedb_test.php @@ -95,6 +95,8 @@ class outagedb_test extends auth_outage_base_testcase { $outage = $this->createoutage(2); $outage->id = $id; outagedb::save($outage); + // Ensure an id was given. + self::assertNotEquals(0, $id); } /** diff --git a/tests/phpunit/form/forms_test.php b/tests/phpunit/form/forms_test.php index c7d2b2e..3621d73 100644 --- a/tests/phpunit/form/forms_test.php +++ b/tests/phpunit/form/forms_test.php @@ -44,14 +44,16 @@ class forms_test extends auth_outage_base_testcase { * Create a delete form. */ public function test_delete() { - new delete(); + $form = new delete(); + self::assertNotNull($form); } /** * Create a finish form. */ public function test_finish() { - new finish(); + $form = new finish(); + self::assertNotNull($form); } /** @@ -164,6 +166,7 @@ class forms_test extends auth_outage_base_testcase { ]); $edit = new edit(); $edit->set_data($outage); + self::assertTrue(true, "set_data did not return any error"); } /** diff --git a/tests/phpunit/local/cli/cli_test.php b/tests/phpunit/local/cli/cli_test.php index d05fa7f..e4e6c6b 100644 --- a/tests/phpunit/local/cli/cli_test.php +++ b/tests/phpunit/local/cli/cli_test.php @@ -61,8 +61,12 @@ class cli_test extends auth_outage_cli_testcase { */ public function test_setreferencetime() { $cli = new create(['start' => 0]); + $cli->set_referencetime(1); + self::assertEquals(1, $cli->get_referencetime()); + $cli->set_referencetime(60 * 60 * 24 * 7); + self::assertEquals(604800, $cli->get_referencetime()); } /** diff --git a/tests/phpunit/local/cli/finish_test.php b/tests/phpunit/local/cli/finish_test.php index 4defa93..0bcf3c5 100644 --- a/tests/phpunit/local/cli/finish_test.php +++ b/tests/phpunit/local/cli/finish_test.php @@ -121,10 +121,16 @@ class finish_test extends auth_outage_cli_testcase { 'title' => 'Title', 'description' => 'Description', ])); + $outage = outagedb::get_by_id($id); + self::assertNull($outage->finished, "outage should not be finished"); + $this->set_parameters(['-id='.$id]); $cli = new finish(); $cli->set_referencetime($now); $this->execute($cli); + + $outage = outagedb::get_by_id($id); + self::assertNotNull($outage->finished, "outage should be finished"); } /** diff --git a/tests/phpunit/local/controllers/infopage_test.php b/tests/phpunit/local/controllers/infopage_test.php index 9c3bc5a..ca1620b 100644 --- a/tests/phpunit/local/controllers/infopage_test.php +++ b/tests/phpunit/local/controllers/infopage_test.php @@ -43,7 +43,8 @@ class infopagecontroller_test extends auth_outage_base_testcase { * Tests the constructor. */ public function test_constructor() { - new infopage(); + $infopage = new infopage(); + self::assertNotNull($infopage); } /** @@ -51,7 +52,8 @@ class infopagecontroller_test extends auth_outage_base_testcase { */ public function test_constructor_withparams() { $_GET = ['id' => 1, 'static' => 'true']; - new infopage(); + $infopage = new infopage(); + self::assertNotNull($infopage); } /** diff --git a/tests/phpunit/local/controllers/maintenance_static_page_test.php b/tests/phpunit/local/controllers/maintenance_static_page_test.php index 2318ff8..6c59fac 100644 --- a/tests/phpunit/local/controllers/maintenance_static_page_test.php +++ b/tests/phpunit/local/controllers/maintenance_static_page_test.php @@ -60,7 +60,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase { } public function test_createfromoutage() { - // How to fetch a page from PHPUnit environment? + self::markTestSkipped("How to fetch a page from PHPUnit environment?"); } public function test_createfromhtml() { @@ -403,7 +403,6 @@ class maintenance_static_page_test extends auth_outage_base_testcase { $page->set_max_refresh_time(5); $page->generate(); $generated = trim(file_get_contents($page->get_io()->get_template_file())); - return $generated; self::assertContains('', $generated); } @@ -412,7 +411,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase { * Data provider for test_get_urls_from_stylesheet * @return array */ - public function test_get_urls_from_stylesheet_provider() { + public function get_urls_from_stylesheet_provider() { return [ // Empty string. ["", 0], @@ -434,7 +433,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase { /** * Tests get_urls_from_stylesheet() method to get all appropriate URLS from the file. * - * @dataProvider test_get_urls_from_stylesheet_provider + * @dataProvider get_urls_from_stylesheet_provider * @param string $filecontent Content of the file * @param int $count Expected quantity of found URLs * @throws coding_exception diff --git a/tests/phpunit/local/outagelib_test.php b/tests/phpunit/local/outagelib_test.php index c37715e..4277e3a 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/phpunit/local/outagelib_test.php @@ -187,7 +187,8 @@ class outagelib_test extends auth_outage_base_testcase { */ public function test_inject_noactive() { outagelib::reset_injectcalled(); - outagelib::get_inject_code(); + $code = outagelib::get_inject_code(); + self::assertNull($code); } /**