Issue #55 - Fixed: cannot create or edit outage using GUI because field autostart is missing.

This commit is contained in:
Daniel Thee Roperto
2016-09-25 13:22:30 +10:00
parent 5b964fd29f
commit 09c8c645c5
4 changed files with 55 additions and 37 deletions

View File

@@ -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(),

View File

@@ -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.';

View File

@@ -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),

View File

@@ -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 <b>{stop}</b>. |
| s_auth_outage_css | /* Some CSS. */ |
| s_auth_outage_default_autostart | <autostart> |
| s_auth_outage_default_warning_duration | <warning> |
| s_auth_outage_default_duration | <duration> |
| s_auth_outage_default_title | <title> |
| s_auth_outage_default_description | <description> |
| s_auth_outage_css | <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 <b>{stop}</b>. |
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 | <warning> |
| s_auth_outage_default_duration | <duration> |
| s_auth_outage_default_title | <title> |
| s_auth_outage_default_description | <description> |
| s_auth_outage_css | /* Some CSS. */ |
And I press "Save changes"
Then I should <seeornot> "Changes saved"
| autostart | <autostart> |
| warningduration[number] | <warning> |
| warningduration[timeunit] | 60 |
| outageduration[number] | <duration> |
| outageduration[timeunit] | 60 |
| title | <title> |
| description[text] | <description> |
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 <b>HTML</b>. | /* 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 | <warning> |
## | s_auth_outage_default_duration | <duration> |
## | s_auth_outage_default_title | <title> |
## | s_auth_outage_default_description | <description> |
## | s_auth_outage_css | /* Some CSS. */ |
## And I press "Save changes"
## Then I should <seeornot> "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 |
#