diff --git a/classes/form/outage/edit.php b/classes/form/outage/edit.php
index df00b48..e32fd60 100644
--- a/classes/form/outage/edit.php
+++ b/classes/form/outage/edit.php
@@ -18,6 +18,7 @@ namespace auth_outage\form\outage;
use auth_outage\local\outage;
use coding_exception;
+use moodleform;
defined('MOODLE_INTERNAL') || die();
@@ -31,7 +32,7 @@ require_once($CFG->libdir.'/formslib.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class edit extends \moodleform {
+class edit extends moodleform {
const TITLE_MAX_CHARS = 100;
/**
@@ -44,6 +45,9 @@ class edit extends \moodleform {
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
+ $mform->addElement('checkbox', 'autostart', get_string('autostart', 'auth_outage'));
+ $mform->addHelpButton('autostart', 'autostart', 'auth_outage');
+
$mform->addElement('duration', 'warningduration', get_string('warningduration', 'auth_outage'));
$mform->addHelpButton('warningduration', 'warningduration', 'auth_outage');
@@ -112,15 +116,17 @@ class edit extends \moodleform {
debugging('Not implemented for format '.$data->description['format'], DEBUG_DEVELOPER);
return null;
}
- // Return an outage.
- return new outage([
+ $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,
'title' => $data->title,
'description' => $data->description['text'],
- ]);
+ ];
+ var_dump($outagedata);
+ return new outage($outagedata);
}
/**
@@ -133,6 +139,7 @@ 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(),
diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php
index d641e1d..82004de 100644
--- a/lang/en/auth_outage.php
+++ b/lang/en/auth_outage.php
@@ -24,6 +24,8 @@
*/
$string['auth_outagedescription'] = 'Auxiliary plugin that warns users about a future outage and prevents them from logging in once the outage starts.';
+$string['autostart'] = 'Auto start maintenance mode.';
+$string['autostart_help'] = 'If selected, when the outage starts it will automatically turn on Moodle maintenance mode.';
$string['clicreatehelp'] = 'Creates a new outage.';
$string['clicreateparamautostart'] = 'must be Y or N, sets if the outage automatically triggers maintenance mode.';
$string['clicreateparamblock'] = 'blocks until outage starts.';
diff --git a/new.php b/new.php
index 1ca930a..02cfac6 100644
--- a/new.php
+++ b/new.php
@@ -44,6 +44,7 @@ if ($mform->is_cancelled()) {
$config = outagelib::get_config();
$defaults = new outage([
+ 'autostart' => $config->default_autostart,
'starttime' => time(),
'stoptime' => time() + ($config->default_duration * 60),
'warntime' => time() - ($config->default_warning_duration * 60),
diff --git a/tests/behat/default_settings.feature b/tests/behat/default_settings.feature
index 857f94d..f16531a 100644
--- a/tests/behat/default_settings.feature
+++ b/tests/behat/default_settings.feature
@@ -7,51 +7,59 @@ Feature: Test changing the default settings.
Rules:
- Times should be expressed in minutes.
+ Reminder:
+ - If one setting is not valid, but another setting is valid and modified, Moodle will display 'Settings Saved'.
Background:
Given the authentication plugin "outage" is enabled
And I am an administrator
- Scenario: Check if I can save the default settings.
+ Scenario Outline: Check if I can save the default settings.
When I navigate to "Default Settings" node in "Site administration > Plugins > Authentication > Outage manager"
And I set the following fields to these values:
- | s_auth_outage_default_autostart | 1 |
- | s_auth_outage_default_warning_duration | 15 |
- | s_auth_outage_default_duration | 30 |
- | s_auth_outage_default_title | My Behat Outage {start} |
- | s_auth_outage_default_description | My outage {stop}. |
- | s_auth_outage_css | /* Some CSS. */ |
+ | s_auth_outage_default_autostart | |
+ | s_auth_outage_default_warning_duration | |
+ | s_auth_outage_default_duration | |
+ | s_auth_outage_default_title | |
+ | s_auth_outage_default_description | |
+ | s_auth_outage_css | |
+ And I wait "600" seconds
And I press "Save changes"
Then I should see "Changes saved"
When I visit the Create Outage Page
Then the following fields match these values:
- | autostart | 1 |
- | warningduration[number] | 15 |
- | warningduration[timeunit] | 60 |
- | outageduration[number] | 30 |
- | outageduration[timeunit] | 60 |
- | title | My Behat Outage {start} |
- | description[text] | My outage {stop}. |
-
-
- Scenario Outline: Check if I can save invalid values for default settings.
- When I navigate to "Default Settings" node in "Site administration > Plugins > Authentication > Outage manager"
- And I set the following fields to these values:
- | s_auth_outage_default_autostart | 1 |
- | s_auth_outage_default_warning_duration | |
- | s_auth_outage_default_duration | |
- | s_auth_outage_default_title | |
- | s_auth_outage_default_description | |
- | s_auth_outage_css | /* Some CSS. */ |
- And I press "Save changes"
- Then I should "Changes saved"
+ | autostart | |
+ | warningduration[number] | |
+ | warningduration[timeunit] | 60 |
+ | outageduration[number] | |
+ | outageduration[timeunit] | 60 |
+ | title | |
+ | description[text] | |
Examples:
- | warning | duration | title | description | seeornot |
- | 15 | 30 | My Title | My Description | see |
- | -1 | 30 | My Title | My Description | not see |
- | 15 | -1 | My Title | My Description | not see |
- | 15 | 30 | | My Description | not see |
- | 15 | 30 | My Title | | not see |
+ | 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 HTML. | /* More CSS. */ |
+
+## Scenario Outline: Check if I can save invalid values for default settings.
+## When I navigate to "Default Settings" node in "Site administration > Plugins > Authentication > Outage manager"
+## And I set the following fields to these values:
+## | s_auth_outage_default_autostart | 1 |
+## | s_auth_outage_default_warning_duration | |
+## | s_auth_outage_default_duration | |
+## | s_auth_outage_default_title | |
+## | s_auth_outage_default_description | |
+## | s_auth_outage_css | /* Some CSS. */ |
+## And I press "Save changes"
+## Then I should "Changes saved"
+##
+## Examples:
+## | warning | duration | title | description | seeornot |
+## | 15 | 30 | My Title | My Description | see |
+## | -1 | 30 | My Title | My Description | not see |
+## | 15 | -1 | My Title | My Description | not see |
+## | 15 | 30 | | My Description | not see |
+## | 15 | 30 | My Title | | not see |
+#