diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index 0597162..fc470a0 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -189,7 +189,9 @@ class outagelib { // Do not inject into admin/settings.php. if ($_SERVER['SCRIPT_NAME'] == '/'.$CFG->admin.'/settings.php') { - return false; + if (optional_param('section', '', PARAM_RAW) === 'additionalhtml') { + return false; + } } // Check if warning bar should be hidden. diff --git a/tests/phpunit/local/outagelib_test.php b/tests/phpunit/local/outagelib_test.php index 736f85c..4b1f808 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/phpunit/local/outagelib_test.php @@ -256,9 +256,7 @@ class outagelib_test extends advanced_testcase { } /** - * Check if outagelib::inject() does not inject on admin/settings.php - * - * See Issue #65. + * Check if outagelib::inject() does not inject on admin/settings.php?section=additionalhtml */ public function test_inject_settings() { global $CFG; @@ -280,6 +278,7 @@ class outagelib_test extends advanced_testcase { // Pretend we are there... $_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test. $_SERVER['SCRIPT_NAME'] = '/admin/settings.php'; + $_GET['section'] = 'additionalhtml'; outagelib::reinject(); self::assertEmpty($CFG->additionalhtmltopofbody); @@ -525,4 +524,33 @@ EOT; // This file should not exist even if the statement above fails as Moodle does not create it immediately but test anyway. self::assertFileNotExists($CFG->dataroot.'/climaintenance.html'); } + + /** + * Regression test for issue #85. + */ + public function test_it_can_inject_in_settings_if_not_additional_html() { + global $CFG; + + $this->resetAfterTest(true); + self::setAdminUser(); + $now = time(); + $outage = new outage([ + 'autostart' => true, + 'warntime' => $now, + 'starttime' => $now + 100, + 'stoptime' => $now + 200, + 'title' => 'Title', + 'description' => 'Description', + ]); + $outage->id = outagedb::save($outage); + self::assertEmpty($CFG->additionalhtmltopofbody); + + // Pretend we are there... + $_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test. + $_SERVER['SCRIPT_NAME'] = '/admin/settings.php'; + $_GET['section'] = 'notadditionalhtml'; + outagelib::reinject(); + + self::assertNotEmpty($CFG->additionalhtmltopofbody); + } }