From fbef0f52cff7d683ec3c9a9537dea7f9fa5d72ec Mon Sep 17 00:00:00 2001 From: Daniel Thee Roperto Date: Sat, 24 Sep 2016 22:21:18 +1000 Subject: [PATCH] Issue #46 - Improved behat for default settings. --- settings.php | 17 ++++--- tests/behat/behat_auth_outage.php | 43 +++++++++++++++--- tests/behat/default_settings.feature | 67 ++++++++++++++++++++-------- tests/behat/manage_outages.feature | 20 +++++++++ 4 files changed, 115 insertions(+), 32 deletions(-) create mode 100644 tests/behat/manage_outages.feature diff --git a/settings.php b/settings.php index 7faac82..d7b7e5b 100644 --- a/settings.php +++ b/settings.php @@ -34,15 +34,7 @@ if ($hassiteconfig && is_enabled_auth('outage')) { 'auth_outage/default_autostart', get_string('defaultoutageautostart', 'auth_outage'), get_string('defaultoutageautostartdescription', 'auth_outage'), - $defaults['default_autostart'], - PARAM_BOOL - )); - $settings->add(new admin_setting_configtext( - 'auth_outage/default_duration', - get_string('defaultoutageduration', 'auth_outage'), - get_string('defaultoutagedurationdescription', 'auth_outage'), - $defaults['default_duration'], - PARAM_INT + $defaults['default_autostart'] )); $settings->add(new admin_setting_configtext( 'auth_outage/default_warning_duration', @@ -51,6 +43,13 @@ if ($hassiteconfig && is_enabled_auth('outage')) { $defaults['default_warning_duration'], PARAM_INT )); + $settings->add(new admin_setting_configtext( + 'auth_outage/default_duration', + get_string('defaultoutageduration', 'auth_outage'), + get_string('defaultoutagedurationdescription', 'auth_outage'), + $defaults['default_duration'], + PARAM_INT + )); $settings->add(new admin_setting_configtext( 'auth_outage/default_warning_title', get_string('defaultwarningtitle', 'auth_outage'), diff --git a/tests/behat/behat_auth_outage.php b/tests/behat/behat_auth_outage.php index 4a011d8..f8f703d 100644 --- a/tests/behat/behat_auth_outage.php +++ b/tests/behat/behat_auth_outage.php @@ -25,15 +25,48 @@ // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. -require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); +use Behat\Behat\Tester\Exception\PendingException; +use Behat\Gherkin\Node\TableNode; +use Behat\Mink\Exception\ExpectationException; + +require_once(__DIR__.'/../../../../lib/behat/behat_base.php'); class behat_auth_outage extends behat_base { /** - * @Given /^The authentication plugin "([^"]*)" is enabled$/ + * @Given the authentication plugin :name is enabled */ - public function theAuthenticationPluginIsEnabled($auth) { - set_config('auth', $auth); + public function the_authentication_plugin_is_enabled($name) { + set_config('auth', $name); \core\session\manager::gc(); // Remove stale sessions. core_plugin_manager::reset_caches(); } -} \ No newline at end of file + + /** + * @Given /^I am on Outage Management Page$/ + */ + public function i_am_on_outage_management_page() { + $this->getSession()->visit($this->locate_path('/auth/outage/manage.php')); + } + + /** + * @Given /^I am an administrator$/ + */ + public function i_am_an_administrator() { + // Visit login page. + $this->getSession()->visit($this->locate_path('login/index.php')); + + // Enter username and password. + $this->execute('behat_forms::i_set_the_field_to', array('Username', $this->escape('admin'))); + $this->execute('behat_forms::i_set_the_field_to', array('Password', $this->escape('admin'))); + + // Press log in button, no need to check for exceptions as it will checked after this step execution. + $this->execute('behat_forms::press_button', get_string('login')); + } + + /** + * @Given /^I visit the Create Outage Page$/ + */ + public function i_visit_the_create_outage_page() { + $this->getSession()->visit($this->locate_path('/auth/outage/new.php')); + } +} diff --git a/tests/behat/default_settings.feature b/tests/behat/default_settings.feature index 3198d6d..cd2e4f8 100644 --- a/tests/behat/default_settings.feature +++ b/tests/behat/default_settings.feature @@ -1,23 +1,54 @@ -@auth @auth_outage @javascript +@dev @auth @auth_outage @javascript Feature: Test changing the default settings. - In order to check if I can set the default settings + In order to easily create outages As an admin - I need to go set the default values and check if they are using for new outages + I need to configure the outage defaults - Background: Always login as admin and enable the auth_outage plugin. - Given The authentication plugin "outage" is enabled - And I log in as "admin" + Rules: + - Times should be expressed in minutes. - Scenario: Check if I can navigate to the default settings. - Given I navigate to "Default Settings" node in "Site administration > Plugins > Authentication > Outage manager" - When I set the following fields to these values: - | s_auth_outage_default_autostart | bool | - | s_auth_outage_default_duration | 123 | - | s_auth_outage_default_warning_duration | 456 | - | s_auth_outage_default_warning_title | My Behat Outage {{start}} | - | s_auth_outage_default_warning_description | My outage {{stop}}. | - | s_auth_outage_css | /* Some CSS. */ | + Background: + Given the authentication plugin "outage" is enabled + And I am an administrator + + Scenario: 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. */ | And I press "Save changes" - And I should see "Changes Saved" -# And I wait "600" seconds -# And I should see "This is a test outage." + 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 | <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 | + diff --git a/tests/behat/manage_outages.feature b/tests/behat/manage_outages.feature new file mode 100644 index 0000000..fad9901 --- /dev/null +++ b/tests/behat/manage_outages.feature @@ -0,0 +1,20 @@ +@auth @auth_outage @javascript +Feature: Test the outage management functionality. + In order to check if I can manage outages + As an admin + I need to create, edit, delete, clone and finish an outage. + + Background: Always login as admin, enable the auth_outage plugin and go to the outage management page. + Given The authentication plugin "outage" is enabled + And I log in as "admin" + + Scenario: Check if I can navigate to management page. + Given I am on homepage + When I navigate to "Manage" node in "Site administration > Plugins > Authentication > Outage manager" + Then I should see "Create Outage" + Then I should see "Planned outages" + Then I should see "Outage history" + + Scenario: Check if creating outages uses the configured defaults. + Given I am on Outage Management Page + When I click on "([^"]|\"*)" "<string>"