Modified unit tests to remove autostart, and quickstart guide and readme.

This commit is contained in:
abhinavgandham
2026-01-20 17:29:24 +10:00
committed by Brendan Heywood
parent bf51ff6de9
commit 5e0a3c015d
23 changed files with 18 additions and 186 deletions

View File

@@ -98,9 +98,8 @@ Execute the commands from your Moodle instalation directory and leave the browse
1) Create an outage
This command will create an outage starting in 30 seconds, with a warning period of 15 seconds.
It will automatically start (trigger maintenance mode).
`php auth/outage/cli/create.php -w=20 -s=30 --autostart=Y`
`php auth/outage/cli/create.php -w=20 -s=30`
Refresh the page but you will not see anything yet.

View File

@@ -168,7 +168,6 @@ Creates a new outage.
-h, --help shows parameters help.
-c, --clone clone another outage except for the start time.
-a, --autostart must be Y or N, sets if the outage automatically triggers maintenance mode.
-w, --warn how many seconds before it starts to display a warning.
-s, --start in how many seconds should this outage start or unix time to start outage. Required.
-d, --duration how many seconds should the outage last.

View File

@@ -100,11 +100,6 @@ class outagedb {
$outage->modifiedby = $USER->id;
$outage->lastmodified = time();
// Setting autostart to false if the default autostart is configured to "Force off".
if (get_config('default_autostart', 'auth_outage') === '2') {
$outage->autostart = 0;
}
if ($outage->id === null) {
// If new outage, set its creator.
$outage->createdby = $USER->id;
@@ -347,37 +342,6 @@ class outagedb {
return (count($data) == 0) ? null : new outage(array_shift($data));
}
/**
* Gets the next outage which has not started yet and has the autostart flag set to true.
* @param null $time Timestamp reference for current time.
* @return outage|null The outage or null if not found.
* @throws coding_exception
*/
public static function get_next_autostarting($time = null) {
global $DB;
if ($time === null) {
$time = time();
}
if (!is_int($time) || ($time <= 0)) {
throw new coding_exception('$time must be null or a positive int.', $time);
}
$data = $DB->get_records_select(
'auth_outage',
'(:datetime <= starttime) AND (autostart = 1)',
['datetime' => $time],
'starttime ASC',
'*',
0,
1
);
// Not using $DB->get_record_select instead because there is no 'limit' parameter.
// Allowing multiple records still raises an internal error.
return (count($data) == 0) ? null : new outage(array_shift($data));
}
/**
* Gets an ongoing outage (between start and stop time but not finished).
* @param int|null $time Timestamp considered to check for outages, null for current date/time.

View File

@@ -136,7 +136,6 @@ class edit extends moodleform {
}
$outagedata = [
'id' => ($data->id === 0) ? null : $data->id,
'autostart' => (isset($data->autostart) && ($data->autostart == 1)),
'starttime' => $data->starttime,
'stoptime' => $data->starttime + $data->outageduration,
'warntime' => $data->starttime - $data->warningduration,
@@ -161,7 +160,6 @@ class edit extends moodleform {
if ($outage instanceof outage) {
$this->_form->setDefaults([
'id' => $outage->id,
'autostart' => $outage->autostart,
'starttime' => $outage->starttime,
'outageduration' => $outage->get_duration_planned(),
'warningduration' => $outage->get_warning_duration(),

View File

@@ -43,7 +43,6 @@ class create extends clibase {
return [
'help' => false,
'clone' => null,
'autostart' => null,
'warn' => null,
'start' => null,
'duration' => null,
@@ -60,7 +59,6 @@ class create extends clibase {
*/
public function generate_shortcuts() {
return [
'a' => 'autostart',
'b' => 'block',
'c' => 'clone',
'd' => 'duration',
@@ -165,7 +163,6 @@ class create extends clibase {
// an outage 47 years in advance.
$start = $options['start'] > 1500000000 ? $options['start'] : $this->time + $options['start'];
$outage = new outage([
'autostart' => $options['autostart'],
'warntime' => $start - $options['warn'],
'starttime' => $start,
'stoptime' => $start + $options['duration'],
@@ -199,7 +196,6 @@ class create extends clibase {
$outage = outagedb::get_by_id((int)$id);
$this->set_defaults([
'autostart' => $outage->autostart,
'warn' => $outage->get_warning_duration(),
'duration' => $outage->get_duration_planned(),
'title' => $outage->title,
@@ -222,10 +218,6 @@ class create extends clibase {
$options[$param] = $this->merge_options_check_parameters_string_nonempty($options[$param], $param);
}
foreach (['autostart'] as $param) {
$options[$param] = $this->merge_options_check_parameters_bool($options[$param], $param);
}
return $options;
}

View File

@@ -58,11 +58,6 @@ class outage {
*/
public $id = null;
/**
* @var bool|null Maintenance mode auto start flag.
*/
public $autostart = null;
/**
* @var int|null Start Time timestamp.
*/
@@ -294,9 +289,6 @@ class outage {
foreach ($fs as $f) {
$this->$f = ($this->$f === null) ? null : (int)$this->$f;
}
// Adjust bool fields.
$this->autostart = ($this->autostart === null) ? null : (bool)$this->autostart;
}
/**

View File

@@ -173,7 +173,6 @@ class outagelib {
'allowedips' => '',
'css' => '',
'default_time' => '',
'default_autostart' => '0',
'default_duration' => (string)(60 * 60),
'default_warning_duration' => (string)(60 * 60),
'default_title' => get_string('defaulttitlevalue', 'auth_outage'),
@@ -223,7 +222,7 @@ class outagelib {
* @param outage|null $outage Outage or null if no scheduled outage.
*/
private static function update_maintenance_later($outage) {
if (is_null($outage) || !$outage->autostart || get_config('default_autostart', 'auth_outage') === '2') {
if (is_null($outage)) {
unset_config('maintenance_later');
} else {
$message = get_config('moodle', 'maintenance_message');

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="auth/outage/db" VERSION="20260114" COMMENT="XMLDB file for Moodle auth/outage"
<XMLDB PATH="auth/outage/db" VERSION="20260120" COMMENT="XMLDB file for Moodle auth/outage"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@@ -7,7 +7,6 @@
<TABLE NAME="auth_outage" COMMENT="Table used for auth/outage plugin. Holds information about all past, current and future outages.">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="autostart" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="If the maintenance mode should be automatically triggered once this outage startes."/>
<FIELD NAME="warntime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When the outage will start showing a warning for that outage."/>
<FIELD NAME="starttime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When outage starts."/>
<FIELD NAME="stoptime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When outage ends."/>

View File

@@ -75,7 +75,16 @@ function xmldb_auth_outage_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2026011301, 'auth', 'outage');
}
if ($oldversion < 2026011302) {
if ($oldversion < 2024081902) {
// Getting the table auth_outage and target field to remove from the table.
$table = new xmldb_table('auth_outage');
$field = new xmldb_field('autostart');
// Conditionally launch drop field autostart.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// Removing the default_autostart config as it is no longer used.
unset_config('default_autostart', 'auth_outage');

View File

@@ -83,7 +83,6 @@ if ($clone) {
}
$outage = new outage([
'autostart' => $config->default_autostart,
'starttime' => $time,
'stoptime' => $time + $config->default_duration,
'warntime' => $time - $config->default_warning_duration,

View File

@@ -79,7 +79,6 @@ abstract class base_testcase extends \advanced_testcase {
return new outage([
'id' => 1,
'autostart' => false,
'warntime' => $now - 100,
'starttime' => $now + 100,
'stoptime' => $now + 200,

View File

@@ -88,7 +88,6 @@ class behat_auth_outage extends behat_base {
*/
public function there_is_a_outage($type) {
$data = [
'autostart' => false,
'finished' => null,
'title' => 'Example of ' . $type . ' outage',
'description' => 'An outage: ' . $type,
@@ -272,7 +271,6 @@ class behat_auth_outage extends behat_base {
// Set defaults.
$row = array_merge(
[
'autostart' => 'no',
'warnbefore' => 60,
'startsin' => 0,
'stopsafter' => 60,
@@ -282,16 +280,12 @@ class behat_auth_outage extends behat_base {
],
$row
);
if (($row['autostart'] != 'yes') && ($row['autostart'] != 'no')) {
throw new Exception('autostart must be yes or no, found: ' . $row['autostart']);
}
if ($row['finished'] == '') {
$row['finished'] = null;
}
$starttime = $time + $row['startsin'];
$this->outage = new outage([
'autostart' => ($row['autostart'] == 'yes'),
'warntime' => $starttime - $row['warnbefore'],
'starttime' => $starttime,
'stoptime' => $starttime + $row['stopsafter'],

View File

@@ -14,7 +14,6 @@ Feature: Change the default settings
Scenario Outline: Check if I can save the default settings.
When I navigate to "Plugins > Authentication > Outage manager > Settings" in site administration
And I set the following fields to these values:
| s_auth_outage_default_autostart | <autostart> |
| s_auth_outage_default_warning_duration[v] | <warning> |
| s_auth_outage_default_warning_duration[u] | 60 |
| s_auth_outage_default_duration[v] | <duration> |
@@ -26,7 +25,6 @@ Feature: Change the default settings
Then I should see "Changes saved"
When I visit the Create Outage Page
Then the following fields match these values:
| autostart | <autostart> |
| warningduration[number] | <warning> |
| warningduration[timeunit] | 60 |
| outageduration[number] | <duration> |
@@ -35,6 +33,6 @@ Feature: Change the default settings
| description[text] | <description> |
Examples:
| autostart | warning | duration | title | description | css |
| 1 | 15 | 30 | An Outage | My outage until {stop}. | /* Some CSS. */ |
| 0 | 30 | 45 | My Behat Outage {start} | My outage with <b>HTML</b>. | /* More CSS. */ |
warning | duration | title | description | css |
15 | 30 | An Outage | My outage until {stop}. | /* Some CSS. */ |
30 | 45 | My Behat Outage {start} | My outage with <b>HTML</b>. | /* More CSS. */ |

View File

@@ -55,7 +55,6 @@ final class calendar_test extends \advanced_testcase {
$time = time();
self::$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $time - 100,
'starttime' => $time,
'stoptime' => $time + (2 * 60 * 60),
@@ -76,7 +75,6 @@ final class calendar_test extends \advanced_testcase {
$time = time();
self::$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $time - 100,
'starttime' => $time,
'stoptime' => $time + (2 * 60 * 60),
@@ -100,7 +98,6 @@ final class calendar_test extends \advanced_testcase {
$time = time();
self::$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $time - 100,
'starttime' => $time,
'stoptime' => $time + (2 * 60 * 60),
@@ -125,7 +122,6 @@ final class calendar_test extends \advanced_testcase {
$time = time();
$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $time - 100,
'starttime' => $time,
'stoptime' => $time + (2 * 60 * 60),

View File

@@ -62,7 +62,6 @@ final class events_test extends \advanced_testcase {
// Save new outage.
$now = time();
$outage = new outage([
'autostart' => false,
'warntime' => $now - 60,
'starttime' => 60,
'stoptime' => 120,
@@ -95,7 +94,6 @@ final class events_test extends \advanced_testcase {
// Save new outage.
$now = time();
$outage = new outage([
'autostart' => false,
'warntime' => $now - 60,
'starttime' => 60,
'stoptime' => 120,
@@ -133,7 +131,6 @@ final class events_test extends \advanced_testcase {
// Save new outage.
$now = time();
$outage = new outage([
'autostart' => false,
'warntime' => $now - 60,
'starttime' => 60,
'stoptime' => 120,

View File

@@ -56,10 +56,9 @@ final class installation_test extends \auth_outage\base_testcase {
static::setAdminUser();
$dbman = $DB->get_manager();
// Create a future outage with autostart.
// Create a future outage.
$now = time();
$outage = new outage([
'autostart' => true,
'starttime' => $now + (1 * 60 * 60),
'stoptime' => $now + (2 * 60 * 60),
'warntime' => $now - (2 * 60 * 60),

View File

@@ -56,7 +56,6 @@ final class outagedb_test extends \auth_outage\base_testcase {
/**
* Helper function to create an outage then save it to the database.
*
* @param bool $autostart If outage should automatically start.
* @param int $now Timestamp for now, such as time().
* @param int $warning In how many hours the warning starts. Can be negative.
* @param int $start In how many hours this outage starts. Can be negative.
@@ -65,9 +64,8 @@ final class outagedb_test extends \auth_outage\base_testcase {
* @param int|null $finished In how many hours this outage is marked as finished. Can be negative or null.
* @return int Id the of created outage.
*/
private static function saveoutage($autostart, $now, $warning, $start, $stop, $title, $finished = null) {
private static function saveoutage($now, $warning, $start, $stop, $title, $finished = null) {
return outagedb::save(new outage([
'autostart' => $autostart,
'warntime' => $now + ($warning * 60 * 60),
'starttime' => $now + ($start * 60 * 60),
'stoptime' => $now + ($stop * 60 * 60),
@@ -497,7 +495,6 @@ final class outagedb_test extends \auth_outage\base_testcase {
$this->resetAfterTest(true);
$time = time();
$outage = new outage([
'autostart' => false,
'warntime' => $time + (60 * 60 * 24 * 1),
'starttime' => $time + (60 * 60 * 24 * 2),
'stoptime' => $time + (60 * 60 * 24 * 3),
@@ -521,15 +518,6 @@ final class outagedb_test extends \auth_outage\base_testcase {
outagedb::get_next_starting(-1);
}
/**
* Tests the outagedb::get_next_autostarting() with an invalid parameter.
*/
public function test_getnextautostartinginvalid(): void {
$this->resetAfterTest(true);
$this->set_expected_exception('coding_exception');
outagedb::get_next_autostarting(-1);
}
/**
* Helper function to create an outage for tests.
* @param int $i Used to populate the information.
@@ -537,7 +525,6 @@ final class outagedb_test extends \auth_outage\base_testcase {
*/
private function createoutage($i) {
return new outage([
'autostart' => ($i % 2 == 0),
'starttime' => $i * 100,
'stoptime' => $i * 100 + 50,
'warntime' => $i * 60,

View File

@@ -67,7 +67,6 @@ final class forms_test extends \auth_outage\base_testcase {
self::assertFalse($edit->is_cancelled());
$outage = $edit->get_data();
self::assertInstanceOf('\\auth_outage\\local\\outage', $outage);
self::assertSame(false, $outage->autostart);
self::assertSame(60, $outage->get_warning_duration());
self::assertSame(mktime(14, 15, 0, 2, 1, 2013), $outage->starttime);
self::assertSame(2 * 60 * 60, $outage->get_duration_planned());
@@ -155,7 +154,6 @@ final class forms_test extends \auth_outage\base_testcase {
*/
public function test_setdata(): void {
$outage = new outage([
'autostart' => false,
'warntime' => time() - 60,
'starttime' => time(),
'stoptime' => time() + 60,

View File

@@ -147,7 +147,6 @@ final class create_test extends cli_testcase {
*/
public function test_create_withoptions(): void {
$this->set_parameters([
'--autostart=true',
'--warn=10',
'--start=0',
'--duration=30',
@@ -177,7 +176,6 @@ final class create_test extends cli_testcase {
public function test_create_onlyid(): void {
$this->set_parameters([
'--onlyid',
'--autostart=N',
'--warn=10',
'--start=0',
'--duration=30',
@@ -214,7 +212,6 @@ final class create_test extends cli_testcase {
$cli = new create();
$cli->set_referencetime($now);
$cli->set_defaults([
'autostart' => false,
'warn' => 50,
'start' => 200,
'duration' => 300,
@@ -243,7 +240,6 @@ final class create_test extends cli_testcase {
$now = time();
// Create the outage to clone.
$original = new outage([
'autostart' => false,
'warntime' => $now - 120,
'starttime' => $now,
'stoptime' => $now + 120,
@@ -288,7 +284,6 @@ final class create_test extends cli_testcase {
public function test_create_withblock(): void {
// Not an extensive test in the blocking API, cliwaitforit tests should cover them deeper.
$this->set_parameters([
'--autostart=N',
'--block',
'--warn=60',
'--start=0',
@@ -312,21 +307,4 @@ final class create_test extends cli_testcase {
$this->set_expected_exception('coding_exception');
$cli->set_defaults(['aninvalidparameter' => 'value']);
}
/**
* Tests with an invalud autostart bool value.
*/
public function test_invalid_bool(): void {
$this->set_parameters([
'--autostart=maybe',
'--warn=60',
'--start=0',
'--duration=600',
'--title=Title',
'--description=Description',
]);
$cli = new create();
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
$cli->execute();
}
}

View File

@@ -93,7 +93,6 @@ final class finish_test extends cli_testcase {
self::setAdminUser();
$now = time();
$id = outagedb::save(new outage([
'autostart' => false,
'warntime' => $now - 200,
'starttime' => $now - 100,
'stoptime' => $now - 50,
@@ -114,7 +113,6 @@ final class finish_test extends cli_testcase {
self::setAdminUser();
$now = time();
$id = outagedb::save(new outage([
'autostart' => false,
'warntime' => $now - 200,
'starttime' => $now - 100,
'stoptime' => $now + 100,

View File

@@ -120,7 +120,6 @@ final class waitforit_test extends cli_testcase {
self::setAdminUser();
$now = time();
$id = outagedb::save(new outage([
'autostart' => false,
'warntime' => $now - 200,
'starttime' => $now - 100,
'stoptime' => $now - 50,
@@ -141,7 +140,6 @@ final class waitforit_test extends cli_testcase {
self::setAdminUser();
$now = time();
outagedb::save(new outage([
'autostart' => false,
'warntime' => $now - 10,
'starttime' => $now + 1,
'stoptime' => $now + 10,
@@ -164,7 +162,6 @@ final class waitforit_test extends cli_testcase {
self::setAdminUser();
$now = time();
outagedb::save(new outage([
'autostart' => false,
'warntime' => $now,
'starttime' => $now + 45,
'stoptime' => $now + (60 * 60),
@@ -193,7 +190,6 @@ final class waitforit_test extends cli_testcase {
self::setAdminUser();
$now = time();
$id = outagedb::save(new outage([
'autostart' => false,
'warntime' => $now,
'starttime' => $now + (2 * 60 * 60),
'stoptime' => $now + (60 * 60),

View File

@@ -48,7 +48,6 @@ final class outage_test extends \auth_outage\base_testcase {
public function test_constructor_object(): void {
$obj = new \stdClass();
$obj->id = 1;
$obj->autostart = true;
$obj->warntime = 2;
$obj->starttime = 3;
$obj->finished = 4;
@@ -57,7 +56,6 @@ final class outage_test extends \auth_outage\base_testcase {
$obj->description = 'Description';
$outage = new outage($obj);
self::assertSame($obj->id, $outage->id);
self::assertSame($obj->autostart, $outage->autostart);
self::assertSame($obj->warntime, $outage->warntime);
self::assertSame($obj->starttime, $outage->starttime);
self::assertSame($obj->finished, $outage->finished);

View File

@@ -42,7 +42,6 @@ final class outagelib_test extends \auth_outage\base_testcase {
$now = time();
$outage = new outage([
'autostart' => true,
'warntime' => $now,
'starttime' => $now + 100,
'stoptime' => $now + 200,
@@ -82,7 +81,6 @@ final class outagelib_test extends \auth_outage\base_testcase {
self::setAdminUser();
$now = time();
$outage = new outage([
'autostart' => true,
'warntime' => $now,
'starttime' => $now + 100,
'stoptime' => $now + 200,
@@ -128,7 +126,6 @@ final class outagelib_test extends \auth_outage\base_testcase {
self::setAdminUser();
$now = time();
$outage = new outage([
'autostart' => true,
'warntime' => $now,
'starttime' => $now + 100,
'stoptime' => $now + 200,
@@ -171,7 +168,6 @@ final class outagelib_test extends \auth_outage\base_testcase {
self::setAdminUser();
$now = time();
$outage = new outage([
'autostart' => true,
'warntime' => $now,
'starttime' => $now + 100,
'stoptime' => $now + 200,
@@ -205,7 +201,6 @@ final class outagelib_test extends \auth_outage\base_testcase {
$this->resetAfterTest(true);
$keys = [
'css',
'default_autostart',
'default_description',
'default_duration',
'default_title',
@@ -236,7 +231,6 @@ final class outagelib_test extends \auth_outage\base_testcase {
$keys = [
'allowedips',
'css',
'default_autostart',
'default_description',
'default_duration',
'default_title',
@@ -257,7 +251,6 @@ final class outagelib_test extends \auth_outage\base_testcase {
// Set config with invalid values.
set_config('allowedips', " \n", 'auth_outage');
set_config('css', " \n", 'auth_outage');
set_config('default_autostart', " \n", 'auth_outage');
set_config('default_description', " \n", 'auth_outage');
set_config('default_duration', " \n", 'auth_outage');
set_config('default_title', " \n", 'auth_outage');
@@ -281,7 +274,6 @@ final class outagelib_test extends \auth_outage\base_testcase {
self::setAdminUser();
$now = time();
$outage = new outage([
'autostart' => true,
'warntime' => $now,
'starttime' => $now + 100,
'stoptime' => $now + 200,
@@ -531,21 +523,6 @@ EOT;
}
}
/**
* Related to Issue #70: Creating ongoing outage does not trigger maintenance file creation.
*/
public function test_preparenextoutage_notautostart(): void {
global $CFG;
$this->create_outage();
// The method outagelib::prepare_next_outage() should have been called by save().
foreach ([$CFG->dataroot . '/climaintenance.template.html', $CFG->dataroot . '/climaintenance.php'] as $file) {
self::assertFileExists($file);
unlink($file);
}
}
/**
* Regression Test - Issue #82: When changing the IP address list it should recreate the maintenance files.
*/
@@ -582,36 +559,6 @@ EOT;
}
}
/**
* Related to Issue #72: IP Block still triggers cli maintenance mode even without autostart.
*/
public function test_preparenextoutage_noautostarttrigger(): void {
global $CFG;
$this->resetAfterTest(true);
self::setAdminUser();
$now = time();
$outage = new outage([
'autostart' => false,
'warntime' => $now - 200,
'starttime' => $now - 100,
'stoptime' => $now + 200,
'title' => 'Title',
'description' => 'Description',
]);
outagedb::save($outage);
// The method outagelib::prepare_next_outage() should have been called by save().
self::assertFalse(get_config('moodle', 'maintenance_later'));
// This file should not exist even if the statement above fails as Moodle does not create it immediately but test anyway.
// Backwards compatibility with older PHPUnit - use old assertFile method.
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist($CFG->dataroot . '/climaintenance.html');
} else {
self::assertFileNotExists($CFG->dataroot . '/climaintenance.html');
}
}
/**
* Regression test for issue #85.
*/
@@ -622,7 +569,6 @@ EOT;
self::setAdminUser();
$now = time();
$outage = new outage([
'autostart' => true,
'warntime' => $now,
'starttime' => $now + 100,
'stoptime' => $now + 200,
@@ -652,7 +598,6 @@ EOT;
self::setAdminUser();
$now = time();
$outage = new outage([
'autostart' => false,
'warntime' => $now - 200,
'starttime' => $now - 100,
'stoptime' => $now + 200,
@@ -768,7 +713,6 @@ EOT;
self::setAdminUser();
$now = time();
$outage = new outage([
'autostart' => false,
'warntime' => $now - 200,
'starttime' => $now - 100,
'stoptime' => $now + 200,