mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Issue #22 - Self-refresh maintenance page every 5 minutes or the outage duration, whatever is lower.
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
use auth_outage\local\cli\clibase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@@ -43,6 +42,11 @@ abstract class auth_outage_cli_testcase extends auth_outage_base_testcase {
|
||||
* Always enable the auth outage plugin, resets after test and set no parameters.
|
||||
*/
|
||||
public function setUp() {
|
||||
global $CFG;
|
||||
|
||||
// PHPUnit does not load config.php
|
||||
$CFG->auth_outage_bootstrap_loaded = true;
|
||||
|
||||
// Enable auth plugins.
|
||||
set_config('auth', 'outage');
|
||||
\core\session\manager::gc(); // Remove stale sessions.
|
||||
@@ -55,6 +59,7 @@ abstract class auth_outage_cli_testcase extends auth_outage_base_testcase {
|
||||
|
||||
/**
|
||||
* Mocks the command line parameters.
|
||||
*
|
||||
* @param string[] $options Options to use as parameters.
|
||||
*/
|
||||
protected function set_parameters(array $options) {
|
||||
@@ -65,7 +70,9 @@ abstract class auth_outage_cli_testcase extends auth_outage_base_testcase {
|
||||
|
||||
/**
|
||||
* Executes the CLI.
|
||||
*
|
||||
* @param clibase $cli CLI to execute.
|
||||
*
|
||||
* @return string The output text.
|
||||
*/
|
||||
protected function execute(clibase $cli) {
|
||||
@@ -81,6 +88,7 @@ abstract class auth_outage_cli_testcase extends auth_outage_base_testcase {
|
||||
|
||||
/**
|
||||
* Sets the expected exception as cli_exception with the given error code.
|
||||
*
|
||||
* @param int $errorcode Error code.
|
||||
*/
|
||||
protected function set_expected_cli_exception($errorcode) {
|
||||
|
||||
@@ -63,7 +63,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
|
||||
public function test_createfromhtml() {
|
||||
$html = "<!DOCTYPE html>\n<html><head><title>Title</title></head><body>Content</body></html>";
|
||||
self::assertSame($html, $this->generated_page_html($html));
|
||||
$expected = "<!DOCTYPE html>\n<html><head><title>Title</title><meta http-equiv=\"refresh\" content=\"300\">".
|
||||
"</head><body>Content</body></html>";
|
||||
self::assertSame($expected, $this->generated_page_html($html));
|
||||
}
|
||||
|
||||
public function test_removescripttags() {
|
||||
@@ -366,4 +368,30 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertContains('removeme', $generated);
|
||||
self::assertContains('Goodbye cruel world', $generated);
|
||||
}
|
||||
|
||||
public function test_meta_refresh_5minutes() {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
'<html><head><title>Title</title></head>'.
|
||||
'<body>Content<b id="removeme">Goodbye cruel world.</b></body></html>';
|
||||
set_config('remove_selectors', '#invalidid', 'auth_outage');
|
||||
$generated = $this->generated_page_html($html);
|
||||
|
||||
self::assertContains('<meta http-equiv="refresh" content="300">', $generated);
|
||||
}
|
||||
|
||||
public function test_meta_refresh_maximum_5seconds() {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
'<html><head><title>Title</title></head>'.
|
||||
'<body>Content<b id="removeme">Goodbye cruel world.</b></body></html>';
|
||||
set_config('remove_selectors', '#invalidid', 'auth_outage');
|
||||
$page = maintenance_static_page::create_from_html($html);
|
||||
$page->set_max_refresh_time(5);
|
||||
$page->generate();
|
||||
$generated = trim(file_get_contents($page->get_io()->get_template_file()));
|
||||
return $generated;
|
||||
|
||||
self::assertContains('<meta http-equiv="refresh" content="5">', $generated);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user