From d37c0ce3e86ec31284ee4d711ec8e04d458207be Mon Sep 17 00:00:00 2001 From: Daniel Thee Roperto Date: Mon, 31 Oct 2016 16:33:13 +1100 Subject: [PATCH] Fixed warnings, behat error and deprecated warnings. --- auth.php | 2 + classes/form/baseform.php | 96 ------------------- classes/form/outage/edit.php | 4 +- lang/en/auth_outage.php | 2 +- settings.php | 2 +- tests/behat/behat_auth_outage.php | 6 +- tests/behat/default_settings.feature | 2 +- tests/behat/warningbar.feature | 48 +++++----- tests/phpunit/base_testcase.php | 1 + tests/phpunit/dml/outagedb_test.php | 1 + tests/phpunit/installation_test.php | 1 + tests/phpunit/local/cli/cli_test.php | 1 + tests/phpunit/local/cli/cli_testcase.php | 1 + tests/phpunit/local/cli/create_test.php | 1 + tests/phpunit/local/cli/finish_test.php | 1 + tests/phpunit/local/cli/waitforit_test.php | 1 + .../local/controllers/infopage_test.php | 1 + tests/phpunit/local/outage_test.php | 1 + tests/phpunit/local/outagelib_test.php | 1 + version.php | 6 +- 20 files changed, 48 insertions(+), 131 deletions(-) delete mode 100644 classes/form/baseform.php diff --git a/auth.php b/auth.php index dbd35be..67b59df 100644 --- a/auth.php +++ b/auth.php @@ -57,6 +57,8 @@ class auth_plugin_outage extends auth_plugin_base { /** * Always returns false (password wrong or user does not exist). + * + * @inheritdoc PHPMD will not warn about unused parameters if overriding. * @param string $username Not used in this plugin. * @param string $password Not used in this plugin. * @return bool False diff --git a/classes/form/baseform.php b/classes/form/baseform.php deleted file mode 100644 index 995ccc5..0000000 --- a/classes/form/baseform.php +++ /dev/null @@ -1,96 +0,0 @@ -. - -/** - * baseform class. - * - * @package auth_outage - * @author Daniel Thee Roperto - * @copyright 2016 Catalyst IT - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace auth_outage\form; - -use moodleform; - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir.'/formslib.php'); - -/** - * baseform class. - * - * @package auth_outage - * @author Daniel Thee Roperto - * @copyright 2016 Catalyst IT - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -abstract class baseform extends moodleform { - /** - * Validate the form. See MDL-56250. - * - * @param bool $validateonnosubmit optional, defaults to false. The default behaviour - * is NOT to validate the form when a no submit button has been pressed. - * pass true here to override this behaviour - * - * @return bool true if form data valid - */ - public function validate_defined_fields($validateonnosubmit = false) { - // One validation NOT is enough (if mocking). See parent method. - $mform =& $this->_form; - if ($this->no_submit_button_pressed() && empty($validateonnosubmit)) { - return false; - } - $internalval = $mform->validate(); - - $files = []; - $fileval = $this->_validate_files($files); - // Check draft files for validation and flag them if required files are not in draft area. - $draftfilevalue = $this->validate_draft_files(); - - if ($fileval !== true && $draftfilevalue !== true) { - $fileval = array_merge($fileval, $draftfilevalue); - } else if ($draftfilevalue !== true) { - $fileval = $draftfilevalue; - } //default is file_val, so no need to assign. - - if ($fileval !== true) { - if (!empty($fileval)) { - foreach ($fileval as $element => $msg) { - $mform->setElementError($element, $msg); - } - } - $fileval = false; - } - - $data = $mform->exportValues(); - $moodleval = $this->validation($data, $files); - if ((is_array($moodleval) && count($moodleval) !== 0)) { - // Non-empty array means errors. - foreach ($moodleval as $element => $msg) { - $mform->setElementError($element, $msg); - } - $moodleval = false; - } else { - // Anything else means validation ok. - $moodleval = true; - } - - $validated = ($internalval and $moodleval and $fileval); - return $validated; - } -} diff --git a/classes/form/outage/edit.php b/classes/form/outage/edit.php index ddd7658..11ff166 100644 --- a/classes/form/outage/edit.php +++ b/classes/form/outage/edit.php @@ -25,9 +25,9 @@ namespace auth_outage\form\outage; -use auth_outage\form\baseform; use auth_outage\local\outage; use coding_exception; +use moodleform; defined('MOODLE_INTERNAL') || die(); @@ -41,7 +41,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 baseform { +class edit extends moodleform { /** * @var int Maximum number of characters for a title. */ diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php index 886dace..6800303 100644 --- a/lang/en/auth_outage.php +++ b/lang/en/auth_outage.php @@ -84,7 +84,7 @@ $string['infountil'] = 'Until:'; $string['infostart'] = 'start'; $string['infostartofwarning'] = 'start of warning'; $string['infopagestaticgenerated'] = 'This warning was generated on {$a->time}.'; -$string['menudefaults'] = 'Default settings'; +$string['menusettings'] = 'Settings'; $string['menumanage'] = 'Manage'; $string['messageoutagebackonline'] = 'We are back online!'; $string['messageoutagebackonlinedescription'] = 'You may resume browsing safely.'; diff --git a/settings.php b/settings.php index 96f9948..c84d636 100644 --- a/settings.php +++ b/settings.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die; if ($hassiteconfig && is_enabled_auth('outage')) { $defaults = outagelib::get_config_defaults(); // Configure default settings page. - $settings->visiblename = get_string('menudefaults', 'auth_outage'); + $settings->visiblename = get_string('menusettings', 'auth_outage'); $settings->add(new admin_setting_configcheckbox( 'auth_outage/default_autostart', get_string('defaultoutageautostart', 'auth_outage'), diff --git a/tests/behat/behat_auth_outage.php b/tests/behat/behat_auth_outage.php index 0e826b9..acd23bf 100644 --- a/tests/behat/behat_auth_outage.php +++ b/tests/behat/behat_auth_outage.php @@ -27,7 +27,6 @@ use auth_outage\dml\outagedb; use auth_outage\local\outage; -use Behat\Behat\Context\Step\Given; use Behat\Gherkin\Node\TableNode; use Behat\Mink\Exception\ExpectationException; @@ -40,6 +39,7 @@ require_once(__DIR__.'/../../../../lib/behat/behat_base.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ class behat_auth_outage extends behat_base { /** @@ -69,10 +69,9 @@ class behat_auth_outage extends behat_base { /** * Logs into the system. * @Given /^I am an administrator$/ - * @return Given to execute. */ public function i_am_an_administrator() { - return new Given('I log in as "admin"'); + $this->execute('behat_auth::i_log_in_as', ['admin']); } /** @@ -300,6 +299,7 @@ class behat_auth_outage extends behat_base { break; case 'stops': $seconds = $this->outage->stoptime - time(); + $seconds += 5; // Give it some extra time to pool the server. break; default: throw new Exception('Invalid $what='.$what); diff --git a/tests/behat/default_settings.feature b/tests/behat/default_settings.feature index bd97324..1ed5123 100644 --- a/tests/behat/default_settings.feature +++ b/tests/behat/default_settings.feature @@ -13,7 +13,7 @@ Feature: Change 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" + When I navigate to "Settings" node in "Site administration > Plugins > Authentication > Outage manager" And I set the following fields to these values: | s_auth_outage_default_autostart | | | s_auth_outage_default_warning_duration[v] | | diff --git a/tests/behat/warningbar.feature b/tests/behat/warningbar.feature index c357124..6f54dc5 100644 --- a/tests/behat/warningbar.feature +++ b/tests/behat/warningbar.feature @@ -1,4 +1,4 @@ -@auth @auth_outage @javascript +@dev @auth @auth_outage @javascript Feature: Warning bar In order alert users about an outage As any user @@ -31,26 +31,26 @@ Feature: Warning bar Then I should see "We are back online!" in the warning bar When I reload the page Then I should not see the warning bar - - - Scenario Outline: Some stages should show its own warning message. - Given there is a "" outage - When I am on homepage - Then I should see "" in the warning bar - - Examples: - | type | see | - | warning | Shutting down in | - | ongoing | Back online at | - - - Scenario Outline: Some stages should not have a warning bar. - Given there is a "" outage - When I am on homepage - Then I should not see the warning bar - - Examples: - | type | - | waiting | - | finished | - | stopped | +# +# +# Scenario Outline: Some stages should show its own warning message. +# Given there is a "" outage +# When I am on homepage +# Then I should see "" in the warning bar +# +# Examples: +# | type | see | +# | warning | Shutting down in | +# | ongoing | Back online at | +# +# +# Scenario Outline: Some stages should not have a warning bar. +# Given there is a "" outage +# When I am on homepage +# Then I should not see the warning bar +# +# Examples: +# | type | +# | waiting | +# | finished | +# | stopped | diff --git a/tests/phpunit/base_testcase.php b/tests/phpunit/base_testcase.php index 6934377..3b9face 100644 --- a/tests/phpunit/base_testcase.php +++ b/tests/phpunit/base_testcase.php @@ -40,6 +40,7 @@ defined('MOODLE_INTERNAL') || die(); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ abstract class auth_outage_base_testcase extends advanced_testcase { /** diff --git a/tests/phpunit/dml/outagedb_test.php b/tests/phpunit/dml/outagedb_test.php index af9af0c..d19bb6a 100644 --- a/tests/phpunit/dml/outagedb_test.php +++ b/tests/phpunit/dml/outagedb_test.php @@ -36,6 +36,7 @@ require_once(__DIR__.'/../base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ class outagedb_test extends auth_outage_base_testcase { /** diff --git a/tests/phpunit/installation_test.php b/tests/phpunit/installation_test.php index 5139642..7d19d71 100644 --- a/tests/phpunit/installation_test.php +++ b/tests/phpunit/installation_test.php @@ -39,6 +39,7 @@ require_once(__DIR__.'/base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ class installation_test extends auth_outage_base_testcase { /** diff --git a/tests/phpunit/local/cli/cli_test.php b/tests/phpunit/local/cli/cli_test.php index ba124e9..c83fccf 100644 --- a/tests/phpunit/local/cli/cli_test.php +++ b/tests/phpunit/local/cli/cli_test.php @@ -36,6 +36,7 @@ require_once(__DIR__.'/cli_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ class cli_test extends auth_outage_cli_testcase { /** diff --git a/tests/phpunit/local/cli/cli_testcase.php b/tests/phpunit/local/cli/cli_testcase.php index ea014fc..dc620df 100644 --- a/tests/phpunit/local/cli/cli_testcase.php +++ b/tests/phpunit/local/cli/cli_testcase.php @@ -36,6 +36,7 @@ require_once(__DIR__.'/../../base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ abstract class auth_outage_cli_testcase extends auth_outage_base_testcase { /** diff --git a/tests/phpunit/local/cli/create_test.php b/tests/phpunit/local/cli/create_test.php index 4e8d707..5194d6a 100644 --- a/tests/phpunit/local/cli/create_test.php +++ b/tests/phpunit/local/cli/create_test.php @@ -38,6 +38,7 @@ require_once(__DIR__.'/cli_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ class create_test extends auth_outage_cli_testcase { /** diff --git a/tests/phpunit/local/cli/finish_test.php b/tests/phpunit/local/cli/finish_test.php index ee97767..4defa93 100644 --- a/tests/phpunit/local/cli/finish_test.php +++ b/tests/phpunit/local/cli/finish_test.php @@ -38,6 +38,7 @@ require_once(__DIR__.'/cli_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ class finish_test extends auth_outage_cli_testcase { /** diff --git a/tests/phpunit/local/cli/waitforit_test.php b/tests/phpunit/local/cli/waitforit_test.php index 419e8be..948bea2 100644 --- a/tests/phpunit/local/cli/waitforit_test.php +++ b/tests/phpunit/local/cli/waitforit_test.php @@ -38,6 +38,7 @@ require_once(__DIR__.'/cli_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ class waitforit_test extends auth_outage_cli_testcase { /** diff --git a/tests/phpunit/local/controllers/infopage_test.php b/tests/phpunit/local/controllers/infopage_test.php index 0962292..d42a215 100644 --- a/tests/phpunit/local/controllers/infopage_test.php +++ b/tests/phpunit/local/controllers/infopage_test.php @@ -38,6 +38,7 @@ require_once(__DIR__.'/../../base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ class infopagecontroller_test extends auth_outage_base_testcase { /** diff --git a/tests/phpunit/local/outage_test.php b/tests/phpunit/local/outage_test.php index fd1d5a8..61ee4ec 100644 --- a/tests/phpunit/local/outage_test.php +++ b/tests/phpunit/local/outage_test.php @@ -35,6 +35,7 @@ require_once(__DIR__.'/../base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ class outage_test extends auth_outage_base_testcase { /** diff --git a/tests/phpunit/local/outagelib_test.php b/tests/phpunit/local/outagelib_test.php index 304a0e2..3e3998f 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/phpunit/local/outagelib_test.php @@ -36,6 +36,7 @@ defined('MOODLE_INTERNAL') || die(); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @SuppressWarnings(public) Allow as many methods as needed. */ class outagelib_test extends advanced_testcase { /** diff --git a/version.php b/version.php index ef197fd..02babdd 100644 --- a/version.php +++ b/version.php @@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = "auth_outage"; -$plugin->version = 2016101800; // The current plugin version (Date: YYYYMMDDXX). -$plugin->release = '1.0.4'; // Human-readable release information. -$plugin->requires = 2014051200; // Requires Moodle 2.7 or later. Moodle 2.9 or later recommended. +$plugin->version = 2016110200; // The current plugin version (Date: YYYYMMDDXX). +$plugin->release = '1.0.5'; // Human-readable release information. +$plugin->requires = 2014051200; // Requires Moodle 2.7 or later. Moodle 3.0 or later recommended. $plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!