From 4aa5976ea83247373ba73839f8e0e93c42d25195 Mon Sep 17 00:00:00 2001 From: Srdjan Date: Tue, 4 Jul 2023 12:17:41 +1000 Subject: [PATCH] Make Moodle linter happy. Mainly tests. --- bootstrap.php | 5 +++- classes/privacy/provider.php | 6 +--- tests/{phpunit => }/base_testcase.php | 8 ++++-- tests/behat/behat_auth_outage.php | 1 + .../{phpunit => }/calendar/calendar_test.php | 6 ++-- tests/{phpunit/event => dml}/events_test.php | 6 ++-- tests/{phpunit => dml}/installation_test.php | 13 +++++---- tests/{phpunit => }/dml/outagedb_test.php | 6 ++-- .../form => form/outage}/forms_test.php | 10 +++---- tests/{phpunit => }/lib_test.php | 7 +++-- tests/{phpunit => }/local/cli/cli_test.php | 8 +++--- .../{phpunit => }/local/cli/cli_testcase.php | 10 +++---- tests/{phpunit => }/local/cli/create_test.php | 7 +++-- tests/{phpunit => }/local/cli/finish_test.php | 7 +++-- .../local/cli/waitforit_test.php | 7 +++-- .../local/controllers/fixtures/catalyst.png | Bin .../local/controllers/fixtures/simple.css | 0 .../fixtures/subdir/withurls-subdir.css | 0 .../controllers/fixtures/withurls-quoted.css | 7 +++++ tests/local/controllers/fixtures/withurls.css | 7 +++++ .../local/controllers/infopage_test.php | 7 +++-- .../maintenance_static_page_test.php | 26 ++++++++++-------- tests/{phpunit => }/local/outage_test.php | 7 +++-- tests/{phpunit => }/local/outagelib_test.php | 10 +++---- tests/{phpunit => }/phpunit.xml | 0 .../controllers/fixtures/withurls-quoted.css | 7 ----- .../local/controllers/fixtures/withurls.css | 7 ----- 27 files changed, 105 insertions(+), 80 deletions(-) rename tests/{phpunit => }/base_testcase.php (94%) rename tests/{phpunit => }/calendar/calendar_test.php (97%) rename tests/{phpunit/event => dml}/events_test.php (97%) rename tests/{phpunit => dml}/installation_test.php (89%) rename tests/{phpunit => }/dml/outagedb_test.php (99%) rename tests/{phpunit/form => form/outage}/forms_test.php (96%) rename tests/{phpunit => }/lib_test.php (95%) rename tests/{phpunit => }/local/cli/cli_test.php (94%) rename tests/{phpunit => }/local/cli/cli_testcase.php (92%) rename tests/{phpunit => }/local/cli/create_test.php (98%) rename tests/{phpunit => }/local/cli/finish_test.php (97%) rename tests/{phpunit => }/local/cli/waitforit_test.php (97%) rename tests/{phpunit => }/local/controllers/fixtures/catalyst.png (100%) rename tests/{phpunit => }/local/controllers/fixtures/simple.css (100%) rename tests/{phpunit => }/local/controllers/fixtures/subdir/withurls-subdir.css (100%) create mode 100644 tests/local/controllers/fixtures/withurls-quoted.css create mode 100644 tests/local/controllers/fixtures/withurls.css rename tests/{phpunit => }/local/controllers/infopage_test.php (96%) rename tests/{phpunit => }/local/controllers/maintenance_static_page_test.php (96%) rename tests/{phpunit => }/local/outage_test.php (98%) rename tests/{phpunit => }/local/outagelib_test.php (99%) rename tests/{phpunit => }/phpunit.xml (100%) delete mode 100644 tests/phpunit/local/controllers/fixtures/withurls-quoted.css delete mode 100644 tests/phpunit/local/controllers/fixtures/withurls.css diff --git a/bootstrap.php b/bootstrap.php index cbbacc6..c1f83d6 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -29,13 +29,16 @@ * @var stdClass $CFG */ +define('MOODLE_INTERNAL', true); +defined('MOODLE_INTERNAL') || die(); // Make sniffer happy. +// // We need the CFG->dataroot, if not set yet this script is called too early in config.php file. if (!isset($CFG->dataroot)) { return; } // 1) Make sure we replace the configurations for behat as we have not ran 'lib/setup.php' yet. -if (!empty($CFG->behat_wwwroot) or !empty($CFG->behat_dataroot) or !empty($CFG->behat_prefix)) { +if (!empty($CFG->behat_wwwroot) || !empty($CFG->behat_dataroot) || !empty($CFG->behat_prefix)) { require_once(__DIR__.'/../../lib/behat/lib.php'); behat_update_vars_for_process(); if (behat_is_test_site()) { diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 42c00d6..8cfaf14 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -23,8 +23,6 @@ namespace auth_outage\privacy; -use core_privacy\local\legacy_polyfill; - /** * Privacy provider for the authentication manual. * @@ -34,8 +32,6 @@ use core_privacy\local\legacy_polyfill; class provider implements \core_privacy\local\metadata\null_provider { - use legacy_polyfill; - /** * Get the language string identifier with the component's language * file to explain why this plugin stores no data. @@ -45,7 +41,7 @@ class provider implements * * @return string */ - public static function _get_reason() { + public static function get_reason() : string { return 'privacy:no_data_reason'; } diff --git a/tests/phpunit/base_testcase.php b/tests/base_testcase.php similarity index 94% rename from tests/phpunit/base_testcase.php rename to tests/base_testcase.php index 59e2884..c236d74 100644 --- a/tests/phpunit/base_testcase.php +++ b/tests/base_testcase.php @@ -31,18 +31,20 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace auth_outage; + use auth_outage\dml\outagedb; use auth_outage\local\outage; /** - * auth_outage_base_testcase class. + * base_testcase 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 auth_outage_base_testcase extends advanced_testcase { +abstract class base_testcase extends \advanced_testcase { /** * Checks PHPUnit version and calls the functions accordingly. * @param string $exception Expected exception class. @@ -71,7 +73,7 @@ abstract class auth_outage_base_testcase extends advanced_testcase { global $DB; $guestrole = $DB->get_record('role', array('shortname' => 'guest')); - role_change_permission($guestrole->id, context_system::instance(), 'auth/outage:viewinfo', CAP_PREVENT); + role_change_permission($guestrole->id, \context_system::instance(), 'auth/outage:viewinfo', CAP_PREVENT); $this->setGuestUser(); } diff --git a/tests/behat/behat_auth_outage.php b/tests/behat/behat_auth_outage.php index fb166e0..1f3ea30 100644 --- a/tests/behat/behat_auth_outage.php +++ b/tests/behat/behat_auth_outage.php @@ -30,6 +30,7 @@ use auth_outage\local\outage; use Behat\Gherkin\Node\TableNode; use Behat\Mink\Exception\ExpectationException; +defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/../../../../lib/behat/behat_base.php'); /** diff --git a/tests/phpunit/calendar/calendar_test.php b/tests/calendar/calendar_test.php similarity index 97% rename from tests/phpunit/calendar/calendar_test.php rename to tests/calendar/calendar_test.php index e37267e..9481256 100644 --- a/tests/phpunit/calendar/calendar_test.php +++ b/tests/calendar/calendar_test.php @@ -23,7 +23,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use auth_outage\calendar\calendar; +namespace auth_outage\calendar; + use auth_outage\local\outage; /** @@ -36,8 +37,9 @@ use auth_outage\local\outage; * @author Daniel Thee Roperto * @copyright Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \auth_outage\calendar\calendar */ -class auth_outage_calendar_test extends advanced_testcase { +class calendar_test extends \advanced_testcase { /** * @var outage|null The calendar entry owner. */ diff --git a/tests/phpunit/event/events_test.php b/tests/dml/events_test.php similarity index 97% rename from tests/phpunit/event/events_test.php rename to tests/dml/events_test.php index 61a52e9..d2a9d85 100644 --- a/tests/phpunit/event/events_test.php +++ b/tests/dml/events_test.php @@ -23,7 +23,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use auth_outage\dml\outagedb; +namespace auth_outage\dml; + use auth_outage\local\outage; /** @@ -36,8 +37,9 @@ use auth_outage\local\outage; * @author Daniel Thee Roperto * @copyright Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \auth_outage\dml\outagedb */ -class auth_outage_events_test extends advanced_testcase { +class events_test extends \advanced_testcase { /** * @var outage|null Outage used in the tests. */ diff --git a/tests/phpunit/installation_test.php b/tests/dml/installation_test.php similarity index 89% rename from tests/phpunit/installation_test.php rename to tests/dml/installation_test.php index bd54723..bd28a40 100644 --- a/tests/phpunit/installation_test.php +++ b/tests/dml/installation_test.php @@ -25,10 +25,12 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace auth_outage\dml; + use auth_outage\local\outage; defined('MOODLE_INTERNAL') || die(); -require_once(__DIR__.'/base_testcase.php'); +require_once(__DIR__.'/../base_testcase.php'); /** * installation_test test class. @@ -39,8 +41,9 @@ 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 + * @covers \auth_outage\dml\outagedb */ -class auth_outage_installation_test extends auth_outage_base_testcase { +class installation_test extends \auth_outage\base_testcase { /** * Checks if plugin cleans up data after uninstall. * @@ -64,7 +67,7 @@ class auth_outage_installation_test extends auth_outage_base_testcase { 'description' => 'Description', ]); ob_start(); - \auth_outage\dml\outagedb::save($outage); + outagedb::save($outage); $text = trim(ob_get_contents()); ob_end_clean(); self::assertStringContainsString('Update maintenance mode configuration', $text); @@ -72,8 +75,8 @@ class auth_outage_installation_test extends auth_outage_base_testcase { // Uninstall plugin. require_once($CFG->libdir.'/adminlib.php'); - $progress = new progress_trace_buffer(new text_progress_trace(), false); - core_plugin_manager::instance()->uninstall_plugin('auth_outage', $progress); + $progress = new \progress_trace_buffer(new \text_progress_trace(), false); + \core_plugin_manager::instance()->uninstall_plugin('auth_outage', $progress); $progress->finished(); self::assertStringContainsString('++ Success ++', $progress->get_buffer()); diff --git a/tests/phpunit/dml/outagedb_test.php b/tests/dml/outagedb_test.php similarity index 99% rename from tests/phpunit/dml/outagedb_test.php rename to tests/dml/outagedb_test.php index def70b1..07b4a01 100644 --- a/tests/phpunit/dml/outagedb_test.php +++ b/tests/dml/outagedb_test.php @@ -23,7 +23,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use auth_outage\dml\outagedb; +namespace auth_outage\dml; + use auth_outage\local\outage; defined('MOODLE_INTERNAL') || die(); @@ -36,8 +37,9 @@ 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 + * @covers \auth_outage\dml\outagedb */ -class auth_outage_outagedb_test extends auth_outage_base_testcase { +class outagedb_test extends \auth_outage\base_testcase { /** * Creates an array of ids in from the given outages array. * @param outage[] $outages An array of outages. diff --git a/tests/phpunit/form/forms_test.php b/tests/form/outage/forms_test.php similarity index 96% rename from tests/phpunit/form/forms_test.php rename to tests/form/outage/forms_test.php index 47e30f4..0f28f55 100644 --- a/tests/phpunit/form/forms_test.php +++ b/tests/form/outage/forms_test.php @@ -23,13 +23,12 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use auth_outage\form\outage\delete; -use auth_outage\form\outage\edit; -use auth_outage\form\outage\finish; +namespace auth_outage\form\outage; + use auth_outage\local\outage; defined('MOODLE_INTERNAL') || die(); -require_once(__DIR__.'/../base_testcase.php'); +require_once(__DIR__.'/../../base_testcase.php'); /** * forms_test test class. @@ -38,8 +37,9 @@ 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 + * @covers \auth_outage\form\outage\edit */ -class auth_outage_forms_test extends auth_outage_base_testcase { +class forms_test extends \auth_outage\base_testcase { /** * Create a delete form. */ diff --git a/tests/phpunit/lib_test.php b/tests/lib_test.php similarity index 95% rename from tests/phpunit/lib_test.php rename to tests/lib_test.php index 757cd63..169fcdc 100644 --- a/tests/phpunit/lib_test.php +++ b/tests/lib_test.php @@ -23,9 +23,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace auth_outage; + defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/base_testcase.php'); -require_once(__DIR__.'/../../lib.php'); +require_once(__DIR__.'/../lib.php'); /** * tests for lib.php @@ -34,8 +36,9 @@ require_once(__DIR__.'/../../lib.php'); * @author Daniel Thee Roperto * @copyright 2017 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers ::auth_outage_get_climaintenance_resource_file */ -class auth_outage_lib_test extends auth_outage_base_testcase { +class lib_test extends base_testcase { /** * Test this plugin gets climaintenance resource file. */ diff --git a/tests/phpunit/local/cli/cli_test.php b/tests/local/cli/cli_test.php similarity index 94% rename from tests/phpunit/local/cli/cli_test.php rename to tests/local/cli/cli_test.php index b019b21..87b172d 100644 --- a/tests/phpunit/local/cli/cli_test.php +++ b/tests/local/cli/cli_test.php @@ -23,8 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use auth_outage\local\cli\cli_exception; -use auth_outage\local\cli\create; +namespace auth_outage\local\cli; defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/cli_testcase.php'); @@ -36,8 +35,9 @@ 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 + * @covers \auth_outage\local\cli\create */ -class auth_outage_cli_test extends auth_outage_cli_testcase { +class cli_test extends cli_testcase { /** * Tests providing an unknown parameter. */ @@ -100,7 +100,7 @@ class auth_outage_cli_test extends auth_outage_cli_testcase { // Disable all auth plugins. set_config('auth', ''); \core\session\manager::gc(); // Remove stale sessions. - core_plugin_manager::reset_caches(); + \core_plugin_manager::reset_caches(); // Try to create an CLI object. $this->set_expected_cli_exception(cli_exception::ERROR_PLUGIN_CONFIGURATION); new create(); diff --git a/tests/phpunit/local/cli/cli_testcase.php b/tests/local/cli/cli_testcase.php similarity index 92% rename from tests/phpunit/local/cli/cli_testcase.php rename to tests/local/cli/cli_testcase.php index 6e082ce..b39a601 100644 --- a/tests/phpunit/local/cli/cli_testcase.php +++ b/tests/local/cli/cli_testcase.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * auth_outage_cli_testcase class. + * cli_testcase class. * * @package auth_outage * @author Daniel Thee Roperto @@ -23,20 +23,20 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use auth_outage\local\cli\clibase; +namespace auth_outage\local\cli; defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/../../base_testcase.php'); /** - * auth_outage_cli_testcase class. + * cli_testcase 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 auth_outage_cli_testcase extends auth_outage_base_testcase { +abstract class cli_testcase extends \auth_outage\base_testcase { /** * Always enable the auth outage plugin, resets after test and set no parameters. */ @@ -49,7 +49,7 @@ abstract class auth_outage_cli_testcase extends auth_outage_base_testcase { // Enable auth plugins. set_config('auth', 'outage'); \core\session\manager::gc(); // Remove stale sessions. - core_plugin_manager::reset_caches(); + \core_plugin_manager::reset_caches(); $this->set_parameters([]); parent::setUp(); diff --git a/tests/phpunit/local/cli/create_test.php b/tests/local/cli/create_test.php similarity index 98% rename from tests/phpunit/local/cli/create_test.php rename to tests/local/cli/create_test.php index 61e9163..ec5b548 100644 --- a/tests/phpunit/local/cli/create_test.php +++ b/tests/local/cli/create_test.php @@ -23,9 +23,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace auth_outage\local\cli; + use auth_outage\dml\outagedb; -use auth_outage\local\cli\cli_exception; -use auth_outage\local\cli\create; use auth_outage\local\outage; defined('MOODLE_INTERNAL') || die(); @@ -38,8 +38,9 @@ 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 + * @covers \auth_outage\local\cli\create */ -class auth_outage_create_test extends auth_outage_cli_testcase { +class create_test extends cli_testcase { /** * Tests without any arguments. */ diff --git a/tests/phpunit/local/cli/finish_test.php b/tests/local/cli/finish_test.php similarity index 97% rename from tests/phpunit/local/cli/finish_test.php rename to tests/local/cli/finish_test.php index c1ff7fd..163a28b 100644 --- a/tests/phpunit/local/cli/finish_test.php +++ b/tests/local/cli/finish_test.php @@ -23,9 +23,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace auth_outage\local\cli; + use auth_outage\dml\outagedb; -use auth_outage\local\cli\cli_exception; -use auth_outage\local\cli\finish; use auth_outage\local\outage; defined('MOODLE_INTERNAL') || die(); @@ -38,8 +38,9 @@ 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 + * @covers \auth_outage\local\cli\finish */ -class auth_outage_finish_test extends auth_outage_cli_testcase { +class finish_test extends cli_testcase { /** * Tests the constructor. */ diff --git a/tests/phpunit/local/cli/waitforit_test.php b/tests/local/cli/waitforit_test.php similarity index 97% rename from tests/phpunit/local/cli/waitforit_test.php rename to tests/local/cli/waitforit_test.php index a2e8031..db596e9 100644 --- a/tests/phpunit/local/cli/waitforit_test.php +++ b/tests/local/cli/waitforit_test.php @@ -23,9 +23,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace auth_outage\local\cli; + use auth_outage\dml\outagedb; -use auth_outage\local\cli\cli_exception; -use auth_outage\local\cli\waitforit; use auth_outage\local\outage; defined('MOODLE_INTERNAL') || die(); @@ -38,8 +38,9 @@ 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 + * @covers \auth_outage\local\cli\waitforit */ -class auth_outage_waitforit_test extends auth_outage_cli_testcase { +class waitforit_test extends cli_testcase { /** * Tests the constructor. */ diff --git a/tests/phpunit/local/controllers/fixtures/catalyst.png b/tests/local/controllers/fixtures/catalyst.png similarity index 100% rename from tests/phpunit/local/controllers/fixtures/catalyst.png rename to tests/local/controllers/fixtures/catalyst.png diff --git a/tests/phpunit/local/controllers/fixtures/simple.css b/tests/local/controllers/fixtures/simple.css similarity index 100% rename from tests/phpunit/local/controllers/fixtures/simple.css rename to tests/local/controllers/fixtures/simple.css diff --git a/tests/phpunit/local/controllers/fixtures/subdir/withurls-subdir.css b/tests/local/controllers/fixtures/subdir/withurls-subdir.css similarity index 100% rename from tests/phpunit/local/controllers/fixtures/subdir/withurls-subdir.css rename to tests/local/controllers/fixtures/subdir/withurls-subdir.css diff --git a/tests/local/controllers/fixtures/withurls-quoted.css b/tests/local/controllers/fixtures/withurls-quoted.css new file mode 100644 index 0000000..abfd76d --- /dev/null +++ b/tests/local/controllers/fixtures/withurls-quoted.css @@ -0,0 +1,7 @@ +a { + font-size: 200%; +} + +div { + background-image: url('/moodle/auth/outage/tests/local/controllers/fixtures/catalyst.png'); +} diff --git a/tests/local/controllers/fixtures/withurls.css b/tests/local/controllers/fixtures/withurls.css new file mode 100644 index 0000000..9b6ef0f --- /dev/null +++ b/tests/local/controllers/fixtures/withurls.css @@ -0,0 +1,7 @@ +a { + font-size: 200%; +} + +div { + background-image: url(/moodle/auth/outage/tests/local/controllers/fixtures/catalyst.png); +} diff --git a/tests/phpunit/local/controllers/infopage_test.php b/tests/local/controllers/infopage_test.php similarity index 96% rename from tests/phpunit/local/controllers/infopage_test.php rename to tests/local/controllers/infopage_test.php index e9a844c..3cd582d 100644 --- a/tests/phpunit/local/controllers/infopage_test.php +++ b/tests/local/controllers/infopage_test.php @@ -23,8 +23,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use auth_outage\local\controllers\infopage; +namespace auth_outage\local\controllers; + use auth_outage\local\outage; +use context_system; defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/../../base_testcase.php'); @@ -36,8 +38,9 @@ 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 + * @covers \auth_outage\local\controllers\infopage */ -class auth_outage_infopagecontroller_test extends auth_outage_base_testcase { +class infopage_test extends \auth_outage\base_testcase { /** * Tests the constructor. */ diff --git a/tests/phpunit/local/controllers/maintenance_static_page_test.php b/tests/local/controllers/maintenance_static_page_test.php similarity index 96% rename from tests/phpunit/local/controllers/maintenance_static_page_test.php rename to tests/local/controllers/maintenance_static_page_test.php index 0bfa6f5..51bd68f 100644 --- a/tests/phpunit/local/controllers/maintenance_static_page_test.php +++ b/tests/local/controllers/maintenance_static_page_test.php @@ -23,10 +23,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use auth_outage\local\controllers\maintenance_static_page; -use auth_outage\local\controllers\maintenance_static_page_io; -use auth_outage\local\controllers\maintenance_static_page_generator; +namespace auth_outage\local\controllers; + use auth_outage\task\update_static_page; +use DOMDocument; defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/../../base_testcase.php'); @@ -38,8 +38,9 @@ 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 + * @covers \auth_outage\local\controllers\maintenance_static_page_generator */ -class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase { +class maintenance_static_page_test extends \auth_outage\base_testcase { /** * Test template file. */ @@ -121,7 +122,7 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase $page->generate(); // Check for css file. - self::assertFileExists($page->get_io()->get_resources_folder().'/d8643101d96b093e642b15544e4d1f7815b5ba55.dGV4dC9wbGFpbg'); + self::assertFileExists($page->get_io()->get_resources_folder().'/53365950336b070c0b26ca50e7d0dad962c364e6.dGV4dC9wbGFpbg'); // Check for catalyst.png file referenced in url(..) of css. self::assertFileExists($page->get_io()->get_resources_folder().'/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n'); @@ -139,7 +140,7 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase $page->generate(); // Check for css file. - self::assertFileExists($page->get_io()->get_resources_folder().'/9fe2374b03953e1949d54ab750be2d8706891c03.dGV4dC9wbGFpbg'); + self::assertFileExists($page->get_io()->get_resources_folder().'/e0b34925c1f939c247a4b50d6bf08c76088def39.dGV4dC9wbGFpbg'); // Check for catalyst.png file referenced in url(..) of css. self::assertFileExists($page->get_io()->get_resources_folder().'/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n'); @@ -231,11 +232,11 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase 'Title'. '
Content
'; - // Temporarily disable debugging to prevent errors because file does not exist + // Temporarily disable debugging to prevent errors because file does not exist. $debuglevel = $CFG->debug; $CFG->debug = ''; $generated = $this->generated_page_html($html); - // Restore debugging level + // Restore debugging level. $CFG->debug = $debuglevel; $matches = $generator->get_url_from_inline_style($stylecontent); if ($rewrite) { @@ -324,7 +325,7 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase // We can still assert the contents really match, not just the hash. $found = file_get_contents($file); - $expected = file_get_contents($CFG->dirroot.'/auth/outage/tests/phpunit/local/controllers/fixtures/catalyst.png'); + $expected = file_get_contents(__DIR__.'/fixtures/catalyst.png'); self::assertSame($found, $expected); } @@ -336,7 +337,7 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase * @return string */ private function get_fixture_path($file) { - return (string)new moodle_url('/auth/outage/tests/phpunit/local/controllers/fixtures/'.$file); + return (string)new \moodle_url('/auth/outage/tests/local/controllers/fixtures/'.$file); } /** @@ -362,7 +363,10 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase */ public function test_get_url_for_file() { $io = new maintenance_static_page_io(); - self::assertStringContainsString('www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png')); + self::assertStringContainsString( + 'www.example.com/moodle/auth/outage/file.php?file=img.png', + $io->get_url_for_file('img.png') + ); } /** diff --git a/tests/phpunit/local/outage_test.php b/tests/local/outage_test.php similarity index 98% rename from tests/phpunit/local/outage_test.php rename to tests/local/outage_test.php index d31f462..81ce522 100644 --- a/tests/phpunit/local/outage_test.php +++ b/tests/local/outage_test.php @@ -23,7 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use auth_outage\local\outage; +namespace auth_outage\local; defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/../base_testcase.php'); @@ -35,8 +35,9 @@ 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 + * @covers \auth_outage\local\outage */ -class auth_outage_outage_test extends auth_outage_base_testcase { +class outage_test extends \auth_outage\base_testcase { /** * Tests the constructor. */ @@ -54,7 +55,7 @@ class auth_outage_outage_test extends auth_outage_base_testcase { * Tests the constructor, giving data as an object. */ public function test_constructor_object() { - $obj = new stdClass(); + $obj = new \stdClass(); $obj->id = 1; $obj->autostart = true; $obj->warntime = 2; diff --git a/tests/phpunit/local/outagelib_test.php b/tests/local/outagelib_test.php similarity index 99% rename from tests/phpunit/local/outagelib_test.php rename to tests/local/outagelib_test.php index 9845386..8a6618c 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/local/outagelib_test.php @@ -23,12 +23,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace auth_outage\local; + use auth_outage\dml\outagedb; -use auth_outage\local\outage; -use auth_outage\local\outagelib; defined('MOODLE_INTERNAL') || die(); - global $CFG; require_once($CFG->libdir.'/adminlib.php'); require_once(__DIR__.'/../base_testcase.php'); @@ -40,8 +39,9 @@ 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 + * @covers \auth_outage\local\outagelib */ -class auth_outage_outagelib_test extends auth_outage_base_testcase { +class outagelib_test extends \auth_outage\base_testcase { /** * Check if maintenance message is disabled as needed. */ @@ -594,6 +594,6 @@ EOT; // Enable outage plugin so settings can be changed. set_config('auth', 'outage'); \core\session\manager::gc(); // Remove stale sessions. - core_plugin_manager::reset_caches(); + \core_plugin_manager::reset_caches(); } } diff --git a/tests/phpunit/phpunit.xml b/tests/phpunit.xml similarity index 100% rename from tests/phpunit/phpunit.xml rename to tests/phpunit.xml diff --git a/tests/phpunit/local/controllers/fixtures/withurls-quoted.css b/tests/phpunit/local/controllers/fixtures/withurls-quoted.css deleted file mode 100644 index 884fef7..0000000 --- a/tests/phpunit/local/controllers/fixtures/withurls-quoted.css +++ /dev/null @@ -1,7 +0,0 @@ -a { - font-size: 200%; -} - -div { - background-image: url('/moodle/auth/outage/tests/phpunit/local/controllers/fixtures/catalyst.png'); -} \ No newline at end of file diff --git a/tests/phpunit/local/controllers/fixtures/withurls.css b/tests/phpunit/local/controllers/fixtures/withurls.css deleted file mode 100644 index c5b57fa..0000000 --- a/tests/phpunit/local/controllers/fixtures/withurls.css +++ /dev/null @@ -1,7 +0,0 @@ -a { - font-size: 200%; -} - -div { - background-image: url(/moodle/auth/outage/tests/phpunit/local/controllers/fixtures/catalyst.png); -} \ No newline at end of file