mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Modified unit tests to remove autostart, and quickstart guide and readme.
This commit is contained in:
committed by
Brendan Heywood
parent
ffda33329c
commit
ac29a02402
@@ -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,
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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. */ |
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user