diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index 42be2f5..9b532b2 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -422,9 +422,6 @@ EOT; * @param outage|null $outage Outage or null if no scheduled outage. */ private static function maintenance_config_log(outage $outage) { - // Not output logging info in php unit test. - if (PHPUNIT_TEST) return; - mtrace(get_string('logformaintmodeconfig', 'auth_outage')); $timezone = ' (Timezone ' . \core_date::get_server_timezone_object()->getName() . ')'; mtrace('... updated at ' . date('H:i:s')); diff --git a/tests/phpunit/installation_test.php b/tests/phpunit/installation_test.php index 1c5936b..bd54723 100644 --- a/tests/phpunit/installation_test.php +++ b/tests/phpunit/installation_test.php @@ -63,7 +63,11 @@ class auth_outage_installation_test extends auth_outage_base_testcase { 'title' => 'Title', 'description' => 'Description', ]); + ob_start(); \auth_outage\dml\outagedb::save($outage); + $text = trim(ob_get_contents()); + ob_end_clean(); + self::assertStringContainsString('Update maintenance mode configuration', $text); self::assertSame(1, $DB->count_records_select('event', "eventtype = 'auth_outage'", null)); // Uninstall plugin. diff --git a/tests/phpunit/local/cli/create_test.php b/tests/phpunit/local/cli/create_test.php index b293c97..61e9163 100644 --- a/tests/phpunit/local/cli/create_test.php +++ b/tests/phpunit/local/cli/create_test.php @@ -159,8 +159,8 @@ class auth_outage_create_test extends auth_outage_cli_testcase { $text = $this->execute($cli); self::assertStringContainsString('created', $text); // Check creted outage. - list(, $id) = explode(':', $text); - $id = (int)$id; + $clioutput = explode(':', $text); + $id = (int)end($clioutput); $outage = outagedb::get_by_id($id); self::assertSame($now, $outage->starttime); self::assertSame(10, $outage->get_warning_duration()); @@ -223,8 +223,8 @@ class auth_outage_create_test extends auth_outage_cli_testcase { $text = $this->execute($cli); self::assertStringContainsString('created', $text); // Check creted outage. - list(, $id) = explode(':', $text); - $id = (int)$id; + $clioutput = explode(':', $text); + $id = (int)end($clioutput); $outage = outagedb::get_by_id($id); self::assertSame($now + 50, $outage->starttime, 'Wrong starttime.'); self::assertSame($outage->starttime - 100, $outage->warntime, 'Wrong warntime.'); diff --git a/tests/phpunit/local/outagelib_test.php b/tests/phpunit/local/outagelib_test.php index 942fa1b..9fae62d 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/phpunit/local/outagelib_test.php @@ -60,7 +60,11 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase { ]); set_config('maintenance_message', 'A message.'); + ob_start(); outagedb::save($outage); + $text = trim(ob_get_contents()); + ob_end_clean(); + self::assertStringContainsString('Update maintenance mode configuration', $text); self::assertFalse((bool)get_config('moodle', 'maintenance_message')); self::assertCount(2, $this->getDebuggingMessages()); $this->resetDebugging(); @@ -94,7 +98,11 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase { 'title' => 'Title', 'description' => 'Description', ]); + ob_start(); $outage->id = outagedb::save($outage); + $text = trim(ob_get_contents()); + ob_end_clean(); + self::assertStringContainsString('Update maintenance mode configuration', $text); outagelib::reset_injectcalled(); // Get full header to avoid interactions with other single inject plugins. @@ -136,7 +144,11 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase { 'title' => 'Title', 'description' => 'Description', ]); + ob_start(); $outage->id = outagedb::save($outage); + $text = trim(ob_get_contents()); + ob_end_clean(); + self::assertStringContainsString('Update maintenance mode configuration', $text); $_GET = ['auth_outage_preview' => (string)$outage->id]; @@ -175,8 +187,11 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase { 'title' => 'Title', 'description' => 'Description', ]); + ob_start(); $outage->id = outagedb::save($outage); - + $text = trim(ob_get_contents()); + ob_end_clean(); + self::assertStringContainsString('Update maintenance mode configuration', $text); $_GET = ['auth_outage_preview' => (string)$outage->id, 'auth_outage_delta' => '500']; outagelib::reset_injectcalled(); $header = outagelib::get_inject_code(); @@ -282,7 +297,11 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase { 'title' => 'Title', 'description' => 'Description', ]); + ob_start(); $outage->id = outagedb::save($outage); + $text = trim(ob_get_contents()); + ob_end_clean(); + self::assertStringContainsString('Update maintenance mode configuration', $text); // Pretend we are there... $_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test. @@ -538,8 +557,11 @@ EOT; 'title' => 'Title', 'description' => 'Description', ]); + ob_start(); $outage->id = outagedb::save($outage); - + $text = trim(ob_get_contents()); + ob_end_clean(); + self::assertStringContainsString('Update maintenance mode configuration', $text); // Pretend we are there... $_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test. $_SERVER['SCRIPT_NAME'] = '/admin/settings.php';