Make Moodle linter happy. Mainly tests.

This commit is contained in:
Srdjan
2023-07-04 12:17:41 +10:00
parent 143862e25a
commit 4aa5976ea8
27 changed files with 105 additions and 80 deletions

View File

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

View File

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

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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();
}

View File

@@ -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');
/**

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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.
*/

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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.
*/

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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());

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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.

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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.
*/

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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.
*/

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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();

View File

@@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* auth_outage_cli_testcase class.
* cli_testcase class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -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 <daniel.roperto@catalyst-au.net>
* @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();

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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.
*/

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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.
*/

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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.
*/

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@@ -0,0 +1,7 @@
a {
font-size: 200%;
}
div {
background-image: url('/moodle/auth/outage/tests/local/controllers/fixtures/catalyst.png');
}

View File

@@ -0,0 +1,7 @@
a {
font-size: 200%;
}
div {
background-image: url(/moodle/auth/outage/tests/local/controllers/fixtures/catalyst.png);
}

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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.
*/

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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
'<html><head><title>Title</title></head>'.
'<body><div style="'.$stylecontent.'">Content</div></body></html>';
// 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')
);
}
/**

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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;

View File

@@ -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 <daniel.roperto@catalyst-au.net>
* @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();
}
}

View File

@@ -1,7 +0,0 @@
a {
font-size: 200%;
}
div {
background-image: url('/moodle/auth/outage/tests/phpunit/local/controllers/fixtures/catalyst.png');
}

View File

@@ -1,7 +0,0 @@
a {
font-size: 200%;
}
div {
background-image: url(/moodle/auth/outage/tests/phpunit/local/controllers/fixtures/catalyst.png);
}