Refactored tests.

This commit is contained in:
Daniel Thee Roperto
2016-12-16 10:23:52 +11:00
parent b8aa1dd233
commit 6efbb0c2c7
2 changed files with 31 additions and 62 deletions

View File

@@ -184,7 +184,13 @@ class forms_test extends auth_outage_base_testcase {
'sesskey' => sesskey(),
'_qf__auth_outage_form_outage_edit' => '1',
'warningduration' => ['number' => '1', 'timeunit' => '60'],
'starttime' => ['day' => '1', 'month' => '2', 'year' => '2013', 'hour' => '14', 'minute' => '15'],
'starttime' => [
'day' => '1',
'month' => '2',
'year' => '2013',
'hour' => '14',
'minute' => '15',
],
'outageduration' => ['number' => '2', 'timeunit' => '3600'],
'title' => 'The title.',
'description' => ['text' => 'The <b>description</b>.', 'format' => '1'],

View File

@@ -393,19 +393,7 @@ EOT;
public function test_preparenextoutage_notautostart() {
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',
]);
set_config('allowedips', '127.0.0.1', 'auth_outage');
outagedb::save($outage);
$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) {
@@ -420,30 +408,7 @@ EOT;
public function test_when_we_change_allowed_ips_in_settings_it_updates_the_templates() {
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',
]);
set_config('allowedips', '127.0.0.1', 'auth_outage');
outagedb::save($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);
}
// Enable outage plugin so settings can be changed.
set_config('auth', 'outage');
\core\session\manager::gc(); // Remove stale sessions.
core_plugin_manager::reset_caches();
$this->create_outage();
// Change settings.
admin_write_settings((object)[
@@ -463,30 +428,7 @@ EOT;
public function test_when_we_change_remove_selectors_in_settings_it_updates_the_templates() {
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',
]);
set_config('allowedips', '127.0.0.1', 'auth_outage');
outagedb::save($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);
}
// Enable outage plugin so settings can be changed.
set_config('auth', 'outage');
\core\session\manager::gc(); // Remove stale sessions.
core_plugin_manager::reset_caches();
$this->create_outage();
// Change settings.
admin_write_settings((object)[
@@ -553,4 +495,25 @@ EOT;
self::assertNotEmpty($CFG->additionalhtmltopofbody);
}
private function create_outage() {
$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',
]);
set_config('allowedips', '127.0.0.1', 'auth_outage');
outagedb::save($outage);
// Enable outage plugin so settings can be changed.
set_config('auth', 'outage');
\core\session\manager::gc(); // Remove stale sessions.
core_plugin_manager::reset_caches();
}
}