diff --git a/admin/roles/tests/preset_test.php b/admin/roles/tests/preset_test.php
index 4ab0ebc35ed..915565a6fc5 100644
--- a/admin/roles/tests/preset_test.php
+++ b/admin/roles/tests/preset_test.php
@@ -14,19 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_role;
+
+use core_role_preset;
+
/**
* Role XML presets test case.
*
* @package core_role
- * @category phpunit
+ * @category test
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-
-class core_role_preset_testcase extends advanced_testcase {
+class preset_test extends \advanced_testcase {
public function test_xml() {
global $DB;
@@ -61,7 +61,7 @@ class core_role_preset_testcase extends advanced_testcase {
FROM {role_capabilities}
WHERE contextid = :syscontext AND roleid = :roleid
ORDER BY capability ASC",
- array('syscontext'=>context_system::instance()->id, 'roleid'=>$role->id));
+ array('syscontext' => \context_system::instance()->id, 'roleid' => $role->id));
foreach ($capabilities as $cap) {
$this->assertEquals($cap->permission, $info['permissions'][$cap->capability]);
diff --git a/admin/tool/dataprivacy/tests/data_registry_test.php b/admin/tool/dataprivacy/tests/data_registry_test.php
index b565f7280d1..cc234cb134d 100644
--- a/admin/tool/dataprivacy/tests/data_registry_test.php
+++ b/admin/tool/dataprivacy/tests/data_registry_test.php
@@ -14,17 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for the data_registry class.
- *
- * @package tool_dataprivacy
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-use \tool_dataprivacy\data_registry;
+namespace tool_dataprivacy;
/**
* Unit tests for the data_registry class.
@@ -33,7 +23,7 @@ use \tool_dataprivacy\data_registry;
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_dataprivacy_dataregistry_testcase extends advanced_testcase {
+class data_registry_test extends \advanced_testcase {
/**
* Ensure that the get_effective_context_value only errors if provided an inappropriate element.
@@ -41,7 +31,7 @@ class tool_dataprivacy_dataregistry_testcase extends advanced_testcase {
* This test is not great because we only test a limited set of values. This is a fault of the underlying API.
*/
public function test_get_effective_context_value_invalid_element() {
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
data_registry::get_effective_context_value(\context_system::instance(), 'invalid');
}
@@ -51,7 +41,7 @@ class tool_dataprivacy_dataregistry_testcase extends advanced_testcase {
* This test is not great because we only test a limited set of values. This is a fault of the underlying API.
*/
public function test_get_effective_contextlevel_value_invalid_element() {
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
data_registry::get_effective_contextlevel_value(\context_system::instance(), 'invalid');
}
}
diff --git a/admin/tool/dataprivacy/tests/data_request_test.php b/admin/tool/dataprivacy/tests/data_request_test.php
index f15bdd50ce9..bb9f9310c68 100644
--- a/admin/tool/dataprivacy/tests/data_request_test.php
+++ b/admin/tool/dataprivacy/tests/data_request_test.php
@@ -14,19 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for the data_request persistent.
- *
- * @package tool_dataprivacy
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace tool_dataprivacy;
+
+use data_privacy_testcase;
defined('MOODLE_INTERNAL') || die();
require_once('data_privacy_testcase.php');
-use tool_dataprivacy\api;
-
/**
* Tests for the data_request persistent.
*
@@ -34,7 +28,7 @@ use tool_dataprivacy\api;
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_dataprivacy_data_request_testcase extends data_privacy_testcase {
+class data_request_test extends data_privacy_testcase {
/**
* Data provider for testing is_resettable, and is_active.
diff --git a/admin/tool/dataprivacy/tests/expired_contexts_test.php b/admin/tool/dataprivacy/tests/expired_contexts_test.php
index 863cb827e56..13441421f80 100644
--- a/admin/tool/dataprivacy/tests/expired_contexts_test.php
+++ b/admin/tool/dataprivacy/tests/expired_contexts_test.php
@@ -14,25 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Expired contexts tests.
- *
- * @package tool_dataprivacy
- * @copyright 2018 David Monllao
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-use tool_dataprivacy\api;
-use tool_dataprivacy\data_registry;
-use tool_dataprivacy\expired_context;
-use tool_dataprivacy\purpose;
-use tool_dataprivacy\purpose_override;
-use tool_dataprivacy\category;
-use tool_dataprivacy\contextlevel;
-use tool_dataprivacy\expired_contexts_manager;
-
-defined('MOODLE_INTERNAL') || die();
-global $CFG;
+namespace tool_dataprivacy;
/**
* Expired contexts tests.
@@ -41,7 +23,7 @@ global $CFG;
* @copyright 2018 David Monllao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
+class expired_contexts_test extends \advanced_testcase {
/**
* Setup the basics with the specified retention period.
diff --git a/admin/tool/dataprivacy/tests/expired_data_requests_test.php b/admin/tool/dataprivacy/tests/expired_data_requests_test.php
index 32c4f56afa5..4fd6aebdd81 100644
--- a/admin/tool/dataprivacy/tests/expired_data_requests_test.php
+++ b/admin/tool/dataprivacy/tests/expired_data_requests_test.php
@@ -14,21 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Expired data requests tests.
- *
- * @package tool_dataprivacy
- * @copyright 2018 Michael Hawkins
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace tool_dataprivacy;
-use tool_dataprivacy\api;
-use tool_dataprivacy\category;
-use tool_dataprivacy\data_request;
-use tool_dataprivacy\purpose;
+use data_privacy_testcase;
defined('MOODLE_INTERNAL') || die();
-global $CFG;
require_once('data_privacy_testcase.php');
@@ -39,7 +29,7 @@ require_once('data_privacy_testcase.php');
* @copyright 2018 Michael Hawkins
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_dataprivacy_expired_data_requests_testcase extends data_privacy_testcase {
+class expired_data_requests_test extends data_privacy_testcase {
/**
* Test tearDown.
@@ -59,7 +49,7 @@ class tool_dataprivacy_expired_data_requests_testcase extends data_privacy_testc
// Set up test users.
$this->setAdminUser();
$studentuser = $this->getDataGenerator()->create_user();
- $studentusercontext = context_user::instance($studentuser->id);
+ $studentusercontext = \context_user::instance($studentuser->id);
$dpouser = $this->getDataGenerator()->create_user();
$this->assign_site_dpo($dpouser);
diff --git a/admin/tool/dataprivacy/tests/filtered_userlist_test.php b/admin/tool/dataprivacy/tests/filtered_userlist_test.php
index d9c4b249608..331ae911fbf 100644
--- a/admin/tool/dataprivacy/tests/filtered_userlist_test.php
+++ b/admin/tool/dataprivacy/tests/filtered_userlist_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for the filtered_userlist.
- *
- * @package tool_dataprivacy
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace tool_dataprivacy;
/**
* Unit tests for the filtered_userlist.
@@ -29,7 +23,7 @@
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_dataprivacy_filtered_userlist_testcase extends advanced_testcase {
+class filtered_userlist_test extends \advanced_testcase {
/**
* Test the apply_expired_contexts_filters function with arange of options.
*
diff --git a/admin/tool/dataprivacy/tests/manager_observer_test.php b/admin/tool/dataprivacy/tests/manager_observer_test.php
index a68bd886ef3..de898abf7d0 100644
--- a/admin/tool/dataprivacy/tests/manager_observer_test.php
+++ b/admin/tool/dataprivacy/tests/manager_observer_test.php
@@ -14,6 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace tool_dataprivacy;
+
+use data_privacy_testcase;
+
+defined('MOODLE_INTERNAL') || die();
+require_once('data_privacy_testcase.php');
+
/**
* Tests for the manager observer.
*
@@ -21,18 +28,7 @@
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-require_once('data_privacy_testcase.php');
-
-/**
- * API tests.
- *
- * @package tool_dataprivacy
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class tool_dataprivacy_manager_observer_testcase extends data_privacy_testcase {
+class manager_observer_test extends data_privacy_testcase {
/**
* Ensure that when users are configured as DPO, they are sent an message upon failure.
*/
diff --git a/admin/tool/dataprivacy/tests/metadata_registry_test.php b/admin/tool/dataprivacy/tests/metadata_registry_test.php
index 143d6b8dd79..2288507e745 100644
--- a/admin/tool/dataprivacy/tests/metadata_registry_test.php
+++ b/admin/tool/dataprivacy/tests/metadata_registry_test.php
@@ -14,16 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Metadata registry tests.
- *
- * @package tool_dataprivacy
- * @copyright 2018 Adrian Greeve
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-global $CFG;
+namespace tool_dataprivacy;
/**
* Metadata registry tests.
@@ -32,7 +23,7 @@ global $CFG;
* @copyright 2018 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_dataprivacy_metadata_registry_testcase extends advanced_testcase {
+class metadata_registry_test extends \advanced_testcase {
/**
* Fetch the meta data and return it in a form that we can easily unit test.
diff --git a/admin/tool/dataprivacy/tests/user_deleted_observer_test.php b/admin/tool/dataprivacy/tests/user_deleted_observer_test.php
index 5a8b2083d9a..f5839891c47 100644
--- a/admin/tool/dataprivacy/tests/user_deleted_observer_test.php
+++ b/admin/tool/dataprivacy/tests/user_deleted_observer_test.php
@@ -14,18 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for the event observer.
- *
- * @package tool_dataprivacy
- * @copyright 2018 Mihail Geshoski
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace tool_dataprivacy;
-defined('MOODLE_INTERNAL') || die();
-
-use \tool_dataprivacy\event\user_deleted_observer;
-use \tool_dataprivacy\api;
+use tool_dataprivacy\event\user_deleted_observer;
/**
* Event observer test.
@@ -34,7 +25,7 @@ use \tool_dataprivacy\api;
* @copyright 2018 Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_dataprivacy_user_deleted_observer_testcase extends advanced_testcase {
+class user_deleted_observer_test extends \advanced_testcase {
/**
* Ensure that a delete data request is created upon user deletion.
diff --git a/admin/tool/generator/tests/maketestcourse_test.php b/admin/tool/generator/tests/maketestcourse_test.php
index da193663a2a..f3109264e3c 100644
--- a/admin/tool/generator/tests/maketestcourse_test.php
+++ b/admin/tool/generator/tests/maketestcourse_test.php
@@ -14,7 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-defined('MOODLE_INTERNAL') || die();
+namespace tool_generator;
+
+use tool_generator_course_backend;
/**
* Automated unit testing. This tests the 'make large course' backend,
@@ -24,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_generator_maketestcourse_testcase extends advanced_testcase {
+class maketestcourse_test extends \advanced_testcase {
/**
* Creates a small test course and checks all the components have been put in place.
*/
@@ -52,7 +54,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
// Get course details.
$course = get_course($courseid);
- $context = context_course::instance($courseid);
+ $context = \context_course::instance($courseid);
$modinfo = get_fast_modinfo($course);
// Check course names.
@@ -88,7 +90,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
// Check it contains 2 files (the default txt and a dat file).
$fs = get_file_storage();
- $resourcecontext = context_module::instance($resource->id);
+ $resourcecontext = \context_module::instance($resource->id);
$files = $fs->get_area_files($resourcecontext->id, 'mod_resource', 'content', false, 'filename', false);
$files = array_values($files);
$this->assertEquals(2, count($files));
@@ -106,7 +108,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
$this->assertTrue($ok);
// Check it contains 2 files.
- $resourcecontext = context_module::instance($resource->id);
+ $resourcecontext = \context_module::instance($resource->id);
$files = $fs->get_area_files($resourcecontext->id, 'mod_resource', 'content', false, 'filename', false);
$files = array_values($files);
$this->assertEquals(2, count($files));
@@ -155,7 +157,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
$lastusernumber = 0;
$discussionstarters = array();
foreach ($discussions as $discussion) {
- $usernumber = core_user::get_user($discussion->userid, 'id, idnumber')->idnumber;
+ $usernumber = \core_user::get_user($discussion->userid, 'id, idnumber')->idnumber;
// Checks that the users are odd numbers.
$this->assertEquals(1, $usernumber % 2);
@@ -190,7 +192,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
$fs = get_file_storage();
$resources = $modinfo->get_instances_of('resource');
foreach ($resources as $resource) {
- $resourcecontext = context_module::instance($resource->id);
+ $resourcecontext = \context_module::instance($resource->id);
$files = $fs->get_area_files($resourcecontext->id, 'mod_resource', 'content', false, 'filename', false);
foreach ($files as $file) {
if ($file->get_mimetype() == 'application/octet-stream') {
@@ -210,7 +212,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
$fs = get_file_storage();
$resources = $modinfo->get_instances_of('resource');
foreach ($resources as $resource) {
- $resourcecontext = context_module::instance($resource->id);
+ $resourcecontext = \context_module::instance($resource->id);
$files = $fs->get_area_files($resourcecontext->id, 'mod_resource', 'content', false, 'filename', false);
foreach ($files as $file) {
if ($file->get_mimetype() == 'application/octet-stream') {
diff --git a/admin/tool/generator/tests/maketestsite_test.php b/admin/tool/generator/tests/maketestsite_test.php
index 18f6aed73ab..e345b16eeee 100644
--- a/admin/tool/generator/tests/maketestsite_test.php
+++ b/admin/tool/generator/tests/maketestsite_test.php
@@ -22,27 +22,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace tool_generator;
+
+use tool_generator_site_backend;
+
defined('MOODLE_INTERNAL') || die();
-/**
- * Silly class to access site_backend internal methods.
- *
- * @package tool_generator
- * @copyright 2013 David Monllaó
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class testable_tool_generator_site_backend extends tool_generator_site_backend {
-
- /**
- * Public accessor.
- *
- * @return int
- */
- public static function get_last_testcourse_id() {
- return parent::get_last_testcourse_id();
- }
-}
-
/**
* Unit test for the site generator
*
@@ -50,7 +35,7 @@ class testable_tool_generator_site_backend extends tool_generator_site_backend {
* @copyright 2013 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_generator_maketestsite_testcase extends advanced_testcase {
+class maketestsite_test extends \advanced_testcase {
/**
* Checks that site courses shortnames are properly generated.
@@ -102,5 +87,22 @@ class tool_generator_maketestsite_testcase extends advanced_testcase {
$lastshortname = testable_tool_generator_site_backend::get_last_testcourse_id();
$this->assertEquals(20, $lastshortname);
}
+}
+/**
+ * Silly class to access site_backend internal methods.
+ *
+ * @copyright 2013 David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class testable_tool_generator_site_backend extends tool_generator_site_backend {
+
+ /**
+ * Public accessor.
+ *
+ * @return int
+ */
+ public static function get_last_testcourse_id() {
+ return parent::get_last_testcourse_id();
+ }
}
diff --git a/admin/tool/installaddon/tests/installer_test.php b/admin/tool/installaddon/tests/installer_test.php
index cff9578831f..38d900669a4 100644
--- a/admin/tool/installaddon/tests/installer_test.php
+++ b/admin/tool/installaddon/tests/installer_test.php
@@ -15,14 +15,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Provides the unit tests class and some helper classes
- *
- * @package tool_installaddon
- * @category test
- * @copyright 2013 David Mudrak
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace tool_installaddon;
+
+use testable_tool_installaddon_installer;
+use tool_installaddon_installer;
defined('MOODLE_INTERNAL') || die();
@@ -32,10 +28,12 @@ require_once(__DIR__.'/fixtures/testable_installer.php');
/**
* Unit tests for the {@link tool_installaddon_installer} class
*
+ * @package tool_installaddon
+ * @category test
* @copyright 2013 David Mudrak
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_installaddon_installer_testcase extends advanced_testcase {
+class installer_test extends \advanced_testcase {
public function test_get_addons_repository_url() {
$installer = testable_tool_installaddon_installer::instance();
diff --git a/admin/tool/langimport/tests/locale_test.php b/admin/tool/langimport/tests/locale_test.php
index 7b6380c0887..2f36910967c 100644
--- a/admin/tool/langimport/tests/locale_test.php
+++ b/admin/tool/langimport/tests/locale_test.php
@@ -22,15 +22,17 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
+namespace tool_langimport;
/**
* Tests for \tool_langimport\locale class.
*
+ * @package tool_langimport
+ * @category test
* @copyright 2018 Université Rennes 2 {@link https://www.univ-rennes2.fr}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class locale_testcase extends \advanced_testcase {
+class locale_test extends \advanced_testcase {
/**
* Test that \tool_langimport\locale::check_locale_availability() works as expected.
*
@@ -65,7 +67,7 @@ class locale_testcase extends \advanced_testcase {
// Test an invalid parameter.
$locale = new \tool_langimport\locale();
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
$locale->check_locale_availability('');
}
}
diff --git a/admin/tool/monitor/tests/eventobservers_test.php b/admin/tool/monitor/tests/eventobservers_test.php
index ff60740bb6a..b72b1a7f438 100644
--- a/admin/tool/monitor/tests/eventobservers_test.php
+++ b/admin/tool/monitor/tests/eventobservers_test.php
@@ -14,14 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for event observers.
- *
- * @package tool_monitor
- * @category test
- * @copyright 2014 onwards Ankit Agarwal
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace tool_monitor;
defined('MOODLE_INTERNAL') || die();
@@ -30,11 +23,14 @@ require_once($CFG->dirroot . '/blog/locallib.php');
require_once($CFG->dirroot . '/blog/lib.php');
/**
- * Class tool_monitor_eventobservers_testcase
+ * Unit tests for event observers.
*
- * Tests for event observers
+ * @package tool_monitor
+ * @category test
+ * @copyright 2014 onwards Ankit Agarwal
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_monitor_eventobservers_testcase extends advanced_testcase {
+class eventobservers_test extends \advanced_testcase {
/**
* Set up method.
*/
@@ -57,12 +53,12 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$course2 = $this->getDataGenerator()->create_course();
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
- $rule = new stdClass();
+ $rule = new \stdClass();
$rule->userid = $user->id;
$rule->courseid = $course1->id;
$rule->plugin = 'test';
- $sub = new stdClass();
+ $sub = new \stdClass();
$sub->courseid = $course1->id;
$sub->userid = $user->id;
@@ -83,7 +79,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
}
// Add a site rule.
- $rule = new stdClass();
+ $rule = new \stdClass();
$rule->userid = $user->id;
$rule->courseid = 0;
$rule->plugin = 'core';
@@ -135,7 +131,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
// Fire a bunch of events.
// Trigger a bunch of other events.
$eventparams = array(
- 'context' => context_course::instance($course->id)
+ 'context' => \context_course::instance($course->id)
);
for ($i = 0; $i < 5; $i++) {
\core\event\course_viewed::create($eventparams)->trigger();
@@ -148,14 +144,14 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$this->assertEquals(0, $DB->count_records('tool_monitor_events'));
// Now, let's create a rule so an event can be stored.
- $rule = new stdClass();
+ $rule = new \stdClass();
$rule->courseid = $course->id;
$rule->plugin = 'mod_book';
$rule->eventname = '\mod_book\event\course_module_instance_list_viewed';
$rule = $monitorgenerator->create_rule($rule);
// Let's subscribe to this rule.
- $sub = new stdClass;
+ $sub = new \stdClass;
$sub->courseid = $course->id;
$sub->ruleid = $rule->id;
$sub->userid = $user->id;
@@ -187,14 +183,14 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$DB->delete_records('tool_monitor_events');
// Now, let's create a site wide rule.
- $rule = new stdClass();
+ $rule = new \stdClass();
$rule->courseid = 0;
$rule->plugin = 'mod_book';
$rule->eventname = '\mod_book\event\course_module_instance_list_viewed';
$rule = $monitorgenerator->create_rule($rule);
// Let's subscribe to this rule.
- $sub = new stdClass;
+ $sub = new \stdClass;
$sub->courseid = 0;
$sub->ruleid = $rule->id;
$sub->userid = $user->id;
@@ -231,14 +227,14 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$toolgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
- $rulerecord = new stdClass();
+ $rulerecord = new \stdClass();
$rulerecord->courseid = $course->id;
$rulerecord->eventname = '\mod_book\event\course_module_instance_list_viewed';
$rulerecord->frequency = 1;
$rule = $toolgenerator->create_rule($rulerecord);
- $subrecord = new stdClass();
+ $subrecord = new \stdClass();
$subrecord->courseid = $course->id;
$subrecord->ruleid = $rule->id;
$subrecord->userid = $USER->id;
@@ -279,7 +275,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$DB->delete_records('tool_monitor_events');
// Now let us create a rule specific to a module instance.
- $cm = new stdClass();
+ $cm = new \stdClass();
$cm->course = $course->id;
$book = $this->getDataGenerator()->create_module('book', $cm);
$rulerecord->eventname = '\mod_book\event\course_module_viewed';
@@ -290,7 +286,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
// Let us trigger events.
$params = array(
- 'context' => context_module::instance($book->cmid),
+ 'context' => \context_module::instance($book->cmid),
'objectid' => $book->id
);
for ($i = 0; $i < 5; $i++) {
@@ -337,10 +333,10 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$toolgenerator->create_subscription($subrecord);
// Let us trigger events.
- $blog = new blog_entry();
+ $blog = new \blog_entry();
$blog->subject = "Subject of blog";
$blog->userid = $USER->id;
- $states = blog_entry::get_applicable_publish_states();
+ $states = \blog_entry::get_applicable_publish_states();
$blog->publishstate = reset($states);
for ($i = 0; $i < 5; $i++) {
$newblog = fullclone($blog);
@@ -367,14 +363,14 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$toolgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
- $rulerecord = new stdClass();
+ $rulerecord = new \stdClass();
$rulerecord->courseid = $course->id;
$rulerecord->eventname = '\mod_book\event\course_module_instance_list_viewed';
$rulerecord->frequency = 5;
$rule = $toolgenerator->create_rule($rulerecord);
- $subrecord = new stdClass();
+ $subrecord = new \stdClass();
$subrecord->courseid = $course->id;
$subrecord->ruleid = $rule->id;
$subrecord->userid = $USER->id;
@@ -416,7 +412,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
*
* @param phpunit_message_sink $msgsink Message sink
*/
- protected function verify_processed_data(phpunit_message_sink $msgsink) {
+ protected function verify_processed_data(\phpunit_message_sink $msgsink) {
global $DB, $USER;
$recordexists = $DB->count_records('task_adhoc', array('component' => 'tool_monitor'));
@@ -435,7 +431,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
*
* @param phpunit_message_sink $msgsink Message sink
*/
- protected function verify_message_not_sent_yet(phpunit_message_sink $msgsink) {
+ protected function verify_message_not_sent_yet(\phpunit_message_sink $msgsink) {
$msgs = $msgsink->get_messages();
$this->assertCount(0, $msgs);
$msgsink->clear();
@@ -457,12 +453,12 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$context = \context_user::instance($USER->id, IGNORE_MISSING);
// Creating book.
- $cm = new stdClass();
+ $cm = new \stdClass();
$cm->course = $course->id;
$book = $this->getDataGenerator()->create_module('book', $cm);
// Creating rule.
- $rulerecord = new stdClass();
+ $rulerecord = new \stdClass();
$rulerecord->courseid = $course->id;
$rulerecord->eventname = '\mod_book\event\course_module_viewed';
$rulerecord->cmid = $book->cmid;
@@ -478,7 +474,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$rule = $toolgenerator->create_rule($rulerecord);
// Creating subscription.
- $subrecord = new stdClass();
+ $subrecord = new \stdClass();
$subrecord->courseid = $course->id;
$subrecord->ruleid = $rule->id;
$subrecord->userid = $USER->id;
@@ -486,7 +482,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
// Now let us trigger the event.
$params = array(
- 'context' => context_module::instance($book->cmid),
+ 'context' => \context_module::instance($book->cmid),
'objectid' => $book->id
);
@@ -496,7 +492,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$msgs = $msgsink->get_messages();
$msg = array_pop($msgs);
- $modurl = new moodle_url('/mod/book/view.php', array('id' => $book->cmid));
+ $modurl = new \moodle_url('/mod/book/view.php', array('id' => $book->cmid));
$this->assertMatchesRegularExpression('~.*' . preg_quote($event->get_url()->out(), '~') . '.*
~',
$msg->fullmessagehtml);
@@ -529,12 +525,12 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$course2 = $this->getDataGenerator()->create_course();
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
- $rule = new stdClass();
+ $rule = new \stdClass();
$rule->userid = $user->id;
$rule->courseid = $course1->id;
$rule->plugin = 'test';
- $sub = new stdClass();
+ $sub = new \stdClass();
$sub->courseid = $course1->id;
$sub->userid = $user->id;
@@ -585,16 +581,16 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
// Now let us create a rule specific to a module instance.
- $cm = new stdClass();
+ $cm = new \stdClass();
$cm->course = $course1->id;
$book = $this->getDataGenerator()->create_module('book', $cm);
- $rule = new stdClass();
+ $rule = new \stdClass();
$rule->userid = $user->id;
$rule->courseid = $course1->id;
$rule->plugin = 'test';
- $sub = new stdClass();
+ $sub = new \stdClass();
$sub->courseid = $course1->id;
$sub->userid = $user->id;
$sub->cmid = $book->cmid;
diff --git a/admin/tool/monitor/tests/rule_manager_test.php b/admin/tool/monitor/tests/rule_manager_test.php
index fd334e61e50..f29f2d9b886 100644
--- a/admin/tool/monitor/tests/rule_manager_test.php
+++ b/admin/tool/monitor/tests/rule_manager_test.php
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace tool_monitor;
+
/**
* Unit tests for rule manager api.
*
@@ -22,17 +24,7 @@
* @copyright 2014 onwards Simey Lameze
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-/**
- * Tests for rule manager.
- *
- * Class tool_monitor_rule_manager_testcase
- */
-class tool_monitor_rule_manager_testcase extends advanced_testcase {
+class rule_manager_test extends \advanced_testcase {
/**
* Set up method.
@@ -53,7 +45,7 @@ class tool_monitor_rule_manager_testcase extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$now = time();
- $rule = new stdClass();
+ $rule = new \stdClass();
$rule->userid = $user->id;
$rule->courseid = $course->id;
$rule->name = 'test rule 1';
@@ -98,7 +90,7 @@ class tool_monitor_rule_manager_testcase extends advanced_testcase {
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
$rule = $monitorgenerator->create_rule();
- $ruledata = new stdClass;
+ $ruledata = new \stdClass;
$ruledata->id = $rule->id;
$ruledata->frequency = 25;
@@ -119,10 +111,10 @@ class tool_monitor_rule_manager_testcase extends advanced_testcase {
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
- $record = new stdClass();
+ $record = new \stdClass();
$record->courseid = $course1->id;
- $record2 = new stdClass();
+ $record2 = new \stdClass();
$record2->courseid = $course2->id;
$ruleids = array();
@@ -147,10 +139,10 @@ class tool_monitor_rule_manager_testcase extends advanced_testcase {
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
- $record = new stdClass();
+ $record = new \stdClass();
$record->plugin = 'core';
- $record2 = new stdClass();
+ $record2 = new \stdClass();
$record2->plugin = 'mod_assign';
$ruleids = array();
@@ -175,10 +167,10 @@ class tool_monitor_rule_manager_testcase extends advanced_testcase {
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
$rule = $monitorgenerator->create_rule();
- $record = new stdClass();
+ $record = new \stdClass();
$record->eventname = '\core\event\calendar_event_created';
- $record2 = new stdClass();
+ $record2 = new \stdClass();
$record2->eventname = '\core\event\calendar_event_updated';
$ruleids = array();
diff --git a/admin/tool/monitor/tests/subscription_manager_test.php b/admin/tool/monitor/tests/subscription_manager_test.php
index 3a905efe106..39975523f5e 100644
--- a/admin/tool/monitor/tests/subscription_manager_test.php
+++ b/admin/tool/monitor/tests/subscription_manager_test.php
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace tool_monitor;
+
/**
* Unit tests for subscription manager api.
*
@@ -22,17 +24,7 @@
* @copyright 2014 onwards Simey Lameze
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-/**
- * Tests for subscription manager.
- *
- * Class tool_monitor_subscription_manager_testcase.
- */
-class tool_monitor_subscription_manager_testcase extends advanced_testcase {
+class subscription_manager_test extends \advanced_testcase {
/**
* Test count_rule_subscriptions method.
@@ -56,7 +48,7 @@ class tool_monitor_subscription_manager_testcase extends advanced_testcase {
$this->assertEquals(0, $subs);
// Subscribe user 1 to rule 1.
- $record = new stdClass;
+ $record = new \stdClass;
$record->ruleid = $rule1->id;
$record->userid = $user1->id;
$monitorgenerator->create_subscription($record);
@@ -75,4 +67,4 @@ class tool_monitor_subscription_manager_testcase extends advanced_testcase {
$this->assertEquals(2, $subs1);
$this->assertEquals(1, $subs2);
}
-}
\ No newline at end of file
+}
diff --git a/admin/tool/monitor/tests/subscription_test.php b/admin/tool/monitor/tests/subscription_test.php
index 3a71907c696..53e5e17188b 100644
--- a/admin/tool/monitor/tests/subscription_test.php
+++ b/admin/tool/monitor/tests/subscription_test.php
@@ -13,7 +13,8 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-defined('MOODLE_INTERNAL') || exit();
+
+namespace tool_monitor;
/**
* Unit tests for the subscription class.
@@ -24,7 +25,7 @@ defined('MOODLE_INTERNAL') || exit();
* @copyright 2016 Jake Dallimore
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_monitor_subscription_testcase extends advanced_testcase {
+class subscription_test extends \advanced_testcase {
/**
* @var \tool_monitor\subscription $subscription object.
@@ -38,7 +39,7 @@ class tool_monitor_subscription_testcase extends advanced_testcase {
$this->resetAfterTest(true);
// Create the mock subscription.
- $sub = new stdClass();
+ $sub = new \stdClass();
$sub->id = 100;
$sub->name = 'My test rule';
$sub->courseid = 20;
@@ -62,7 +63,7 @@ class tool_monitor_subscription_testcase extends advanced_testcase {
*/
public function test_magic_get() {
$this->assertEquals(20, $this->subscription->courseid);
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
$this->subscription->ruleid;
}
}
diff --git a/admin/tool/monitor/tests/task_check_subscriptions_test.php b/admin/tool/monitor/tests/task_check_subscriptions_test.php
index 10a5e98efa9..85d252e83f9 100644
--- a/admin/tool/monitor/tests/task_check_subscriptions_test.php
+++ b/admin/tool/monitor/tests/task_check_subscriptions_test.php
@@ -13,7 +13,8 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-defined('MOODLE_INTERNAL') || exit();
+
+namespace tool_monitor;
/**
* Unit tests for the tool_monitor clean events task.
@@ -24,7 +25,7 @@ defined('MOODLE_INTERNAL') || exit();
* @copyright 2016 Jake Dallimore
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
+class task_check_subscriptions_test extends \advanced_testcase {
private $course;
private $user;
@@ -45,7 +46,7 @@ class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
$this->user = $this->getDataGenerator()->create_user();
$this->course = $this->getDataGenerator()->create_course();
- $rule = new stdClass();
+ $rule = new \stdClass();
$rule->userid = 2; // Rule created by admin.
$rule->courseid = $this->course->id;
$rule->plugin = 'mod_book';
@@ -54,7 +55,7 @@ class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
$this->rule = $monitorgenerator->create_rule($rule);
- $sub = new stdClass();
+ $sub = new \stdClass();
$sub->courseid = $this->course->id;
$sub->userid = $this->user->id;
$sub->ruleid = $this->rule->id;
@@ -90,7 +91,7 @@ class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
public function test_site_level_subscription() {
// Create a site level subscription.
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
- $sub = new stdClass();
+ $sub = new \stdClass();
$sub->userid = $this->user->id;
$sub->ruleid = $this->rule->id;
$this->subscription = $monitorgenerator->create_subscription($sub);
@@ -104,7 +105,7 @@ class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
$this->assertEquals(false, \tool_monitor\subscription_manager::subscription_is_active($this->subscription));
// Now, assign the user as a teacher role at system context.
- $this->getDataGenerator()->role_assign($this->teacherrole->id, $this->user->id, context_system::instance());
+ $this->getDataGenerator()->role_assign($this->teacherrole->id, $this->user->id, \context_system::instance());
// Run the task.
$task = new \tool_monitor\task\check_subscriptions();
@@ -238,7 +239,7 @@ class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
$book = $this->getDataGenerator()->create_module('book', array('course' => $this->course->id));
// And add a subscription to it.
- $sub = new stdClass();
+ $sub = new \stdClass();
$sub->courseid = $this->course->id;
$sub->userid = $this->user->id;
$sub->ruleid = $this->rule->id;
diff --git a/admin/tool/monitor/tests/task_clean_events_test.php b/admin/tool/monitor/tests/task_clean_events_test.php
index 5f0a13ca58f..94c8c3c48bb 100644
--- a/admin/tool/monitor/tests/task_clean_events_test.php
+++ b/admin/tool/monitor/tests/task_clean_events_test.php
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace tool_monitor;
+
/**
* Unit tests for the tool_monitor clean events task.
*
@@ -22,15 +24,7 @@
* @copyright 2014 Mark Nelson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-/**
- * Class used to test the tool_monitor clean events task.
- */
-class tool_monitor_task_clean_events_testcase extends advanced_testcase {
+class task_clean_events_test extends \advanced_testcase {
/**
* Test set up.
@@ -51,16 +45,16 @@ class tool_monitor_task_clean_events_testcase extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
- $bookcontext = context_module::instance($book->cmid);
+ $bookcontext = \context_module::instance($book->cmid);
$bookchapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
$course2 = $this->getDataGenerator()->create_course();
$book2 = $this->getDataGenerator()->create_module('book', array('course' => $course2->id));
- $book2context = context_module::instance($book2->cmid);
+ $book2context = \context_module::instance($book2->cmid);
$book2chapter = $bookgenerator->create_chapter(array('bookid' => $book2->id));
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
// Let's set some data for the rules we need before we can generate them.
- $rule = new stdClass();
+ $rule = new \stdClass();
$rule->userid = $user->id;
$rule->courseid = $course->id;
$rule->plugin = 'mod_book';
@@ -96,7 +90,7 @@ class tool_monitor_task_clean_events_testcase extends advanced_testcase {
// Let's subscribe to these rules.
- $sub = new stdClass;
+ $sub = new \stdClass;
$sub->courseid = $course->id;
$sub->ruleid = $rule1->id;
$sub->userid = $user->id;
@@ -133,7 +127,7 @@ class tool_monitor_task_clean_events_testcase extends advanced_testcase {
// Trigger a bunch of other events.
$eventparams = array(
- 'context' => context_course::instance($course->id)
+ 'context' => \context_course::instance($course->id)
);
for ($i = 0; $i < 5; $i++) {
\mod_quiz\event\course_module_instance_list_viewed::create($eventparams)->trigger();
@@ -164,7 +158,7 @@ class tool_monitor_task_clean_events_testcase extends advanced_testcase {
$this->assertEquals($course2->id, $event4->courseid);
// Update the timewindow for two of the rules.
- $updaterule = new stdClass();
+ $updaterule = new \stdClass();
$updaterule->id = $rule1->id;
$updaterule->timewindow = 0;
\tool_monitor\rule_manager::update_rule($updaterule);
diff --git a/admin/tool/moodlenet/tests/import_backup_helper_test.php b/admin/tool/moodlenet/tests/import_backup_helper_test.php
index 81ea96a3fde..a6d47020261 100644
--- a/admin/tool/moodlenet/tests/import_backup_helper_test.php
+++ b/admin/tool/moodlenet/tests/import_backup_helper_test.php
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace tool_moodlenet;
+
/**
* Unit tests for the import_backup_helper
*
@@ -22,15 +24,7 @@
* @copyright 2020 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-/**
- * Class import_backup_helper tests
- */
-class tool_moodlenet_import_backup_helper_testcase extends advanced_testcase {
+class import_backup_helper_test extends \advanced_testcase {
/**
* Test that the first available context with the capability to upload backup files is returned.
@@ -47,7 +41,7 @@ class tool_moodlenet_import_backup_helper_testcase extends advanced_testcase {
$user5 = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student');
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'editingteacher');
@@ -55,12 +49,12 @@ class tool_moodlenet_import_backup_helper_testcase extends advanced_testcase {
$category = $this->getDataGenerator()->create_category();
$rolerecord = $DB->get_record('role', ['shortname' => 'manager']);
- $categorycontext = context_coursecat::instance($category->id);
+ $categorycontext = \context_coursecat::instance($category->id);
$this->getDataGenerator()->role_assign($rolerecord->id, $user3->id, $categorycontext->id);
$this->getDataGenerator()->role_assign($rolerecord->id, $user5->id, $categorycontext->id);
$roleid = $this->getDataGenerator()->create_role();
- $sitecontext = context_system::instance();
+ $sitecontext = \context_system::instance();
assign_capability('moodle/restore:uploadfile', CAP_ALLOW, $roleid, $sitecontext->id, true);
accesslib_clear_all_caches_for_unit_testing();
$this->getDataGenerator()->role_assign($roleid, $user4->id, $sitecontext->id);
@@ -81,4 +75,4 @@ class tool_moodlenet_import_backup_helper_testcase extends advanced_testcase {
$this->assertEquals(CONTEXT_COURSECAT, $result->contextlevel);
}
-}
\ No newline at end of file
+}
diff --git a/admin/tool/moodlenet/tests/profile_manager_test.php b/admin/tool/moodlenet/tests/profile_manager_test.php
index 9485fbf90a4..7d6de581cf1 100644
--- a/admin/tool/moodlenet/tests/profile_manager_test.php
+++ b/admin/tool/moodlenet/tests/profile_manager_test.php
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace tool_moodlenet;
+
/**
* Unit tests for the profile manager
*
@@ -22,15 +24,7 @@
* @copyright 2020 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-/**
- * Class profile_manager tests
- */
-class tool_moodlenet_profile_manager_testcase extends advanced_testcase {
+class profile_manager_test extends \advanced_testcase {
/**
* Test that on this site we use the user table to hold moodle net profile information.
@@ -57,7 +51,7 @@ class tool_moodlenet_profile_manager_testcase extends advanced_testcase {
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
- $this->expectException(moodle_exception::class);
+ $this->expectException(\moodle_exception::class);
$this->expectExceptionMessage(get_string('invalidmoodlenetprofile', 'tool_moodlenet'));
$result = new \tool_moodlenet\moodlenet_user_profile("", $user->id);
}
diff --git a/admin/tool/policy/tests/sitepolicy_handler_test.php b/admin/tool/policy/tests/sitepolicy_handler_test.php
index ef5c83a900a..51ec55afa4c 100644
--- a/admin/tool/policy/tests/sitepolicy_handler_test.php
+++ b/admin/tool/policy/tests/sitepolicy_handler_test.php
@@ -14,31 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Provides the {@link tool_policy_sitepolicy_handler_testcase} class.
- *
- * @package tool_policy
- * @category test
- * @copyright 2018 David Mudrák
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace tool_policy;
-use tool_policy\api;
-use tool_policy\policy_version;
use tool_policy\privacy\local\sitepolicy\handler;
use tool_policy\test\helper;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
/**
* Unit tests for the {@link \tool_policy\privacy\local\sitepolicy\handler} class.
*
+ * @package tool_policy
+ * @category test
* @copyright 2018 David Mudrak
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_policy_sitepolicy_handler_testcase extends advanced_testcase {
+class sitepolicy_handler_test extends \advanced_testcase {
/**
* Test behaviour of the {@link \tool_policy\privacy\local\sitepolicy\handler::get_redirect_url()} method.
diff --git a/admin/tool/recyclebin/tests/category_bin_test.php b/admin/tool/recyclebin/tests/category_bin_test.php
index 199fca063c2..1048bc7f708 100644
--- a/admin/tool/recyclebin/tests/category_bin_test.php
+++ b/admin/tool/recyclebin/tests/category_bin_test.php
@@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Recycle bin tests.
- *
- * @package tool_recyclebin
- * @copyright 2015 University of Kent
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace tool_recyclebin;
/**
* Recycle bin category tests.
@@ -31,15 +23,15 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2015 University of Kent
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_recyclebin_category_bin_tests extends advanced_testcase {
+class category_bin_test extends \advanced_testcase {
/**
- * @var stdClass $course
+ * @var \stdClass $course
*/
protected $course;
/**
- * @var stdClass $coursebeingrestored
+ * @var \stdClass $coursebeingrestored
*/
protected $coursebeingrestored;
@@ -96,7 +88,7 @@ class tool_recyclebin_category_bin_tests extends advanced_testcase {
$this->assertEquals(1, $DB->count_records('tool_recyclebin_category'));
// Now let's delete the course category.
- $category = core_course_category::get($this->course->category);
+ $category = \core_course_category::get($this->course->category);
$category->delete_full(false);
// Check that the course was deleted from the category recycle bin.
@@ -242,7 +234,7 @@ class tool_recyclebin_category_bin_tests extends advanced_testcase {
$this->assertEquals(0, count($recyclebin->get_items()));
// Verify that student DOES continue enrolled.
- $this->assertTrue(is_enrolled(context_course::instance($newcourse->id), $student->id));
+ $this->assertTrue(is_enrolled(\context_course::instance($newcourse->id), $student->id));
}
/**
@@ -286,6 +278,6 @@ class tool_recyclebin_category_bin_tests extends advanced_testcase {
$this->assertEquals(0, count($recyclebin->get_items()));
// Verify that student DOES NOT continue enrolled.
- $this->assertFalse(is_enrolled(context_course::instance($newcourse->id), $student->id));
+ $this->assertFalse(is_enrolled(\context_course::instance($newcourse->id), $student->id));
}
}
diff --git a/admin/tool/recyclebin/tests/course_bin_test.php b/admin/tool/recyclebin/tests/course_bin_test.php
index 87c4e86db76..b601b52920b 100644
--- a/admin/tool/recyclebin/tests/course_bin_test.php
+++ b/admin/tool/recyclebin/tests/course_bin_test.php
@@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Recycle bin tests.
- *
- * @package tool_recyclebin
- * @copyright 2015 University of Kent
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace tool_recyclebin;
/**
* Recycle bin course tests.
@@ -31,10 +23,10 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2015 University of Kent
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_recyclebin_course_bin_tests extends advanced_testcase {
+class course_bin_test extends \advanced_testcase {
/**
- * @var stdClass $course
+ * @var \stdClass $course
*/
protected $course;
@@ -72,7 +64,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
course_delete_module($this->quiz->cmid);
// Now, run the course module deletion adhoc task.
- phpunit_util::run_all_adhoc_tasks();
+ \phpunit_util::run_all_adhoc_tasks();
// Check the course module is now in the recycle bin.
$this->assertEquals(1, $DB->count_records('tool_recyclebin_course'));
@@ -116,7 +108,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
course_delete_module($this->quiz->cmid);
// Now, run the course module deletion adhoc task.
- phpunit_util::run_all_adhoc_tasks();
+ \phpunit_util::run_all_adhoc_tasks();
// Try purging.
$recyclebin = new \tool_recyclebin\course_bin($this->course->id);
@@ -141,7 +133,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
course_delete_module($this->quiz->cmid);
// Now, run the course module deletion adhoc task.
- phpunit_util::run_all_adhoc_tasks();
+ \phpunit_util::run_all_adhoc_tasks();
// Set deleted date to the distant past.
$recyclebin = new \tool_recyclebin\course_bin($this->course->id);
@@ -157,7 +149,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
course_delete_module($book->cmid);
// Now, run the course module deletion adhoc task.
- phpunit_util::run_all_adhoc_tasks();
+ \phpunit_util::run_all_adhoc_tasks();
// Should have 2 items now.
$this->assertEquals(2, count($recyclebin->get_items()));
@@ -223,7 +215,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
// Delete quiz.
$cm = get_coursemodule_from_instance('quiz', $this->quiz->id);
course_delete_module($cm->id);
- phpunit_util::run_all_adhoc_tasks();
+ \phpunit_util::run_all_adhoc_tasks();
$quizzes = get_coursemodules_in_course('quiz', $this->course->id);
$this->assertEquals(0, count($quizzes));
@@ -240,7 +232,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
$attempts = quiz_get_user_attempts($cm->instance, $student->id);
$this->assertEquals(1, count($attempts));
$attempt = array_pop($attempts);
- $attemptobj = quiz_attempt::create($attempt->id);
+ $attemptobj = \quiz_attempt::create($attempt->id);
$this->assertEquals($student->id, $attemptobj->get_userid());
$this->assertEquals(true, $attemptobj->is_finished());
}
@@ -270,7 +262,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
// Delete quiz.
$cm = get_coursemodule_from_instance('quiz', $this->quiz->id);
course_delete_module($cm->id);
- phpunit_util::run_all_adhoc_tasks();
+ \phpunit_util::run_all_adhoc_tasks();
$quizzes = get_coursemodules_in_course('quiz', $this->course->id);
$this->assertEquals(0, count($quizzes));
@@ -303,17 +295,17 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
quiz_add_quiz_question($numq->id, $quiz);
// Create quiz attempt.
- $quizobj = quiz::create($quiz->id, $student->id);
- $quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
+ $quizobj = \quiz::create($quiz->id, $student->id);
+ $quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$timenow = time();
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow, false, $student->id);
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
quiz_attempt_save_started($quizobj, $quba, $attempt);
- $attemptobj = quiz_attempt::create($attempt->id);
+ $attemptobj = \quiz_attempt::create($attempt->id);
$tosubmit = array(1 => array('answer' => '0'));
$attemptobj->process_submitted_actions($timenow, false, $tosubmit);
- $attemptobj = quiz_attempt::create($attempt->id);
+ $attemptobj = \quiz_attempt::create($attempt->id);
$attemptobj->process_finish($timenow, false);
}
}
diff --git a/admin/tool/task/tests/form_test.php b/admin/tool/task/tests/form_test.php
index a9b8aa12bf9..ce54533311e 100644
--- a/admin/tool/task/tests/form_test.php
+++ b/admin/tool/task/tests/form_test.php
@@ -14,26 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * File containing tests for the mform class.
- *
- * @package tool_task
- * @copyright 2014 onwards Ankit Agarwal
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
+namespace tool_task;
/**
- * Mform test class.
+ * Test for the task mform class.
*
* @package tool_task
* @copyright 2014 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
*/
-class tool_task_form_testcase extends advanced_testcase {
+class form_test extends \advanced_testcase {
/**
* Test validations for minute field.
diff --git a/admin/tool/uploaduser/tests/cli_test.php b/admin/tool/uploaduser/tests/cli_test.php
index d2af41ce849..22ec7eb0ea6 100644
--- a/admin/tool/uploaduser/tests/cli_test.php
+++ b/admin/tool/uploaduser/tests/cli_test.php
@@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for CLI tool_uploaduser.
- *
- * @package tool_uploaduser
- * @copyright 2020 Marina Glancy
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-use \tool_uploaduser\cli_helper;
+namespace tool_uploaduser;
/**
* Tests for CLI tool_uploaduser.
@@ -31,7 +23,7 @@ use \tool_uploaduser\cli_helper;
* @copyright 2020 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_uploaduser_cli_testcase extends advanced_testcase {
+class cli_test extends \advanced_testcase {
/**
* Generate cli_helper and mock $_SERVER['argv']
@@ -117,7 +109,7 @@ class tool_uploaduser_cli_testcase extends advanced_testcase {
$this->assertEquals('Users created: 2', $stats[0]);
// Users have default values applied.
- $user1 = core_user::get_user_by_username('jonest');
+ $user1 = \core_user::get_user_by_username('jonest');
$this->assertEquals('Brighton', $user1->city);
$this->assertEquals('Purchasing', $user1->department);
}
@@ -149,7 +141,7 @@ class tool_uploaduser_cli_testcase extends advanced_testcase {
$this->assertEquals('Users created: 2', $stats[0]);
// Created users have data in the profile fields.
- $user1 = core_user::get_user_by_username('reznort');
+ $user1 = \core_user::get_user_by_username('reznort');
$profilefields1 = profile_user_record($user1->id);
$this->assertEquals((object)['superfield' => 'Loves cats'], $profilefields1);
}
@@ -244,9 +236,9 @@ class tool_uploaduser_cli_testcase extends advanced_testcase {
$enrols = array_values(enrol_get_course_users($course->id));
$this->assertEqualsCanonicalizing(['jonest'], [$enrols[0]->username]);
// User reznor is not created.
- $this->assertFalse(core_user::get_user_by_username('reznor'));
+ $this->assertFalse(\core_user::get_user_by_username('reznor'));
// User jonest is not updated.
- $this->assertEquals('OLDNAME', core_user::get_user_by_username('jonest')->firstname);
+ $this->assertEquals('OLDNAME', \core_user::get_user_by_username('jonest')->firstname);
}
/**
@@ -287,8 +279,8 @@ class tool_uploaduser_cli_testcase extends advanced_testcase {
$enrols = array_values(enrol_get_course_users($course->id));
$this->assertEqualsCanonicalizing(['jonest'], [$enrols[0]->username]);
// User reznor is not created.
- $this->assertFalse(core_user::get_user_by_username('reznor'));
+ $this->assertFalse(\core_user::get_user_by_username('reznor'));
// User jonest is updated, new first name is Tom.
- $this->assertEquals('Tom', core_user::get_user_by_username('jonest')->firstname);
+ $this->assertEquals('Tom', \core_user::get_user_by_username('jonest')->firstname);
}
}
diff --git a/admin/tool/uploaduser/tests/field_value_validators_test.php b/admin/tool/uploaduser/tests/field_value_validators_test.php
index e74dbe2ccf5..8fd5fea8c34 100644
--- a/admin/tool/uploaduser/tests/field_value_validators_test.php
+++ b/admin/tool/uploaduser/tests/field_value_validators_test.php
@@ -14,20 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for field value validators of tool_uploaduser.
- *
- * @package tool_uploaduser
- * @copyright 2019 Jun Pataleta
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace tool_uploaduser;
use tool_uploaduser\local\field_value_validators;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
/**
* Tests for field value validators of tool_uploaduser.
*
@@ -35,7 +25,7 @@ global $CFG;
* @copyright 2019 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class field_value_validators_testcase extends advanced_testcase {
+class field_value_validators_test extends \advanced_testcase {
/**
* Data provider for \field_value_validators_testcase::test_validate_theme().
diff --git a/admin/tool/usertours/tests/accessdate_filter_test.php b/admin/tool/usertours/tests/accessdate_filter_test.php
index b60247feacf..52b44c3c31b 100644
--- a/admin/tool/usertours/tests/accessdate_filter_test.php
+++ b/admin/tool/usertours/tests/accessdate_filter_test.php
@@ -14,17 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for time filter.
- *
- * @package tool_usertours
- * @copyright 2019 Tom Dickman
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace tool_usertours;
-defined('MOODLE_INTERNAL') || die();
-
-use tool_usertours\tour;
use tool_usertours\local\filter\accessdate;
/**
@@ -34,7 +25,7 @@ use tool_usertours\local\filter\accessdate;
* @copyright 2019 Tom Dickman
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_usertours_accessdate_filter_test extends advanced_testcase {
+class accessdate_filter_test extends \advanced_testcase {
public function setUp(): void {
$this->resetAfterTest(true);
diff --git a/admin/tool/usertours/tests/role_filter_test.php b/admin/tool/usertours/tests/role_filter_test.php
index 8fe97394343..cc93cd50786 100644
--- a/admin/tool/usertours/tests/role_filter_test.php
+++ b/admin/tool/usertours/tests/role_filter_test.php
@@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for role filter.
- *
- * @package tool_usertours
- * @copyright 2016 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace tool_usertours;
/**
* Tests for role filter.
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2016 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_usertours_role_filter_testcase extends advanced_testcase {
+class role_filter_test extends \advanced_testcase {
/**
* @var $course Test course
diff --git a/admin/tool/usertours/tests/theme_filter_test.php b/admin/tool/usertours/tests/theme_filter_test.php
index 75ede939286..e3f7b1fae57 100644
--- a/admin/tool/usertours/tests/theme_filter_test.php
+++ b/admin/tool/usertours/tests/theme_filter_test.php
@@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for theme filter.
- *
- * @package tool_usertours
- * @copyright 2016 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace tool_usertours;
/**
* Tests for theme filter.
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2016 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_usertours_theme_filter_testcase extends advanced_testcase {
+class theme_filter_test extends \advanced_testcase {
/**
* Data Provider for filter_matches function.
diff --git a/admin/tool/usertours/tests/tour_test.php b/admin/tool/usertours/tests/tour_test.php
index 536723375cd..f7955dd94e4 100644
--- a/admin/tool/usertours/tests/tour_test.php
+++ b/admin/tool/usertours/tests/tour_test.php
@@ -14,21 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for tour.
- *
- * @package tool_usertours
- * @copyright 2016 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace tool_usertours;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/formslib.php');
-use tool_usertours\tour;
-
/**
* Tests for tour.
*
@@ -36,7 +28,7 @@ use tool_usertours\tour;
* @copyright 2016 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tour_testcase extends advanced_testcase {
+class tour_test extends \advanced_testcase {
/**
* @var moodle_database
diff --git a/auth/db/tests/db_test.php b/auth/db/tests/db_test.php
index 606dc51945b..0e98f086714 100644
--- a/auth/db/tests/db_test.php
+++ b/auth/db/tests/db_test.php
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace auth_db;
+
/**
* External database auth sync tests, this also tests adodb drivers
* that are matching our four supported Moodle database drivers.
@@ -23,11 +25,7 @@
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-
-class auth_db_testcase extends advanced_testcase {
+class db_test extends \advanced_testcase {
/** @var string Original error log */
protected $oldlog;
@@ -123,7 +121,7 @@ class auth_db_testcase extends advanced_testcase {
throw new exception('Unknown database family ' . $DB->get_dbfamily());
}
- $table = new xmldb_table('auth_db_users');
+ $table = new \xmldb_table('auth_db_users');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null);
$table->add_field('pass', XMLDB_TYPE_CHAR, '255', null, null, null);
@@ -168,7 +166,7 @@ class auth_db_testcase extends advanced_testcase {
global $DB;
$dbman = $DB->get_manager();
- $table = new xmldb_table('auth_db_users');
+ $table = new \xmldb_table('auth_db_users');
$dbman->drop_table($table);
ini_set('error_log', $this->oldlog);
@@ -222,7 +220,7 @@ class auth_db_testcase extends advanced_testcase {
$this->assertCount(2, $DB->get_records('user'));
- $trace = new null_progress_trace();
+ $trace = new \null_progress_trace();
// Sync users and make sure that two events user_created werer triggered.
$sink = $this->redirectEvents();
@@ -483,7 +481,7 @@ class auth_db_testcase extends advanced_testcase {
$extdbuser3 = (object)array('name'=>'u3', 'pass'=>'heslo', 'email'=>'u3@example.com',
'lastname' => 'userxss');
$extdbuser3->id = $DB->insert_record('auth_db_users', $extdbuser3);
- $trace = new null_progress_trace();
+ $trace = new \null_progress_trace();
// Let's test user sync make sure still works as expected..
$auth->sync_users($trace, true);
@@ -529,7 +527,7 @@ class auth_db_testcase extends advanced_testcase {
}
// Sync to moodle.
- $trace = new null_progress_trace();
+ $trace = new \null_progress_trace();
$auth->sync_users($trace, true);
// Check user is there.
diff --git a/auth/manual/tests/manual_test.php b/auth/manual/tests/manual_test.php
index 7857e34b17b..77503b18e87 100644
--- a/auth/manual/tests/manual_test.php
+++ b/auth/manual/tests/manual_test.php
@@ -14,14 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Manual authentication tests.
- *
- * @package auth_manual
- * @category test
- * @copyright 2014 Gilles-Philippe Leblanc
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace auth_manual;
+
+use auth_plugin_manual;
defined('MOODLE_INTERNAL') || die();
@@ -36,7 +31,7 @@ require_once($CFG->dirroot.'/auth/manual/auth.php');
* @copyright 2014 Gilles-Philippe Leblanc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class auth_manual_testcase extends advanced_testcase {
+class manual_test extends \advanced_testcase {
/** @var auth_plugin_manual Keeps the authentication plugin. */
protected $authplugin;
diff --git a/auth/oauth2/tests/auth_test.php b/auth/oauth2/tests/auth_test.php
index 4582d7081ee..eab37fb21a6 100644
--- a/auth/oauth2/tests/auth_test.php
+++ b/auth/oauth2/tests/auth_test.php
@@ -14,26 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace auth_oauth2;
+
/**
* Auth oauth2 auth functions tests.
*
* @package auth_oauth2
* @category test
- * @copyright 2019 Shamim Rezaie
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-/**
- * Tests for the \auth_oauth2\auth class.
- *
* @copyright 2019 Shamim Rezaie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class auth_oauth2_auth_testcase extends advanced_testcase {
+class auth_test extends \advanced_testcase {
public function test_get_password_change_info() {
$this->resetAfterTest();
diff --git a/auth/tests/digital_consent_test.php b/auth/tests/digital_consent_test.php
index c9b2b90e10a..8ad2d411b15 100644
--- a/auth/tests/digital_consent_test.php
+++ b/auth/tests/digital_consent_test.php
@@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for core_auth\digital_consent.
- *
- * @package core_auth
- * @copyright 2018 Mihail Geshoski
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_auth;
/**
* Digital consent helper testcase.
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2018 Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_auth_digital_consent_testcase extends advanced_testcase {
+class digital_consent_test extends \advanced_testcase {
public function test_is_age_digital_consent_verification_enabled() {
global $CFG;
diff --git a/availability/tests/capability_checker_test.php b/availability/tests/capability_checker_test.php
index 7cfd2a9956b..b228a2f55f4 100644
--- a/availability/tests/capability_checker_test.php
+++ b/availability/tests/capability_checker_test.php
@@ -14,17 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for the capability checker class.
- *
- * @package core_availability
- * @copyright 2014 The Open University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-use core_availability\capability_checker;
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_availability;
/**
* Unit tests for the capability checker class.
@@ -33,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_availability_capability_checker_testcase extends advanced_testcase {
+class capability_checker_test extends \advanced_testcase {
/**
* Tests loading a class from /availability/classes.
*/
@@ -51,7 +41,7 @@ class core_availability_capability_checker_testcase extends advanced_testcase {
$generator->enrol_user($student->id, $course->id, $roleids['student']);
// Check a capability which they both have.
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$checker = new capability_checker($context);
$result = array_keys($checker->get_users_by_capability('mod/forum:replypost'));
sort($result);
diff --git a/availability/tests/component_test.php b/availability/tests/component_test.php
index de05104eebc..993c778361e 100644
--- a/availability/tests/component_test.php
+++ b/availability/tests/component_test.php
@@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for the component and plugin definitions for availability system.
- *
- * @package core_availability
- * @copyright 2014 The Open University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_availability;
/**
* Unit tests for the component and plugin definitions for availability system.
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_availability_component_testcase extends advanced_testcase {
+class component_test extends \advanced_testcase {
/**
* Tests loading a class from /availability/classes.
*/
@@ -47,7 +39,7 @@ class core_availability_component_testcase extends advanced_testcase {
// This code will throw debugging information if the plugininfo class
// is missing. Unfortunately it doesn't actually cause the test to
// fail, but it's obvious when running test at least.
- $pluginmanager = core_plugin_manager::instance();
+ $pluginmanager = \core_plugin_manager::instance();
$list = $pluginmanager->get_enabled_plugins('availability');
$this->assertArrayHasKey('completion', $list);
$this->assertArrayHasKey('date', $list);
diff --git a/availability/tests/info_test.php b/availability/tests/info_test.php
index 4108d604923..e47b72d9433 100644
--- a/availability/tests/info_test.php
+++ b/availability/tests/info_test.php
@@ -14,19 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for info and subclasses.
- *
- * @package core_availability
- * @copyright 2014 The Open University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-use core_availability\info;
-use core_availability\info_module;
-use core_availability\info_section;
+namespace core_availability;
/**
* Unit tests for info and subclasses.
@@ -35,7 +23,7 @@ use core_availability\info_section;
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class info_testcase extends advanced_testcase {
+class info_test extends \advanced_testcase {
public function setUp(): void {
// Load the mock condition so that it can be used.
require_once(__DIR__ . '/fixtures/mock_condition.php');
@@ -491,7 +479,7 @@ class info_testcase extends advanced_testcase {
// If the students have viewhiddenactivities, they get past the module
// restriction.
- role_change_permission($studentroleid, context_module::instance($page2->cmid),
+ role_change_permission($studentroleid, \context_module::instance($page2->cmid),
'moodle/course:ignoreavailabilityrestrictions', CAP_ALLOW);
$expected = array($u1->id, $u2->id);
$this->assertEquals($expected, array_keys($info->filter_user_list($allusers)));
@@ -502,7 +490,7 @@ class info_testcase extends advanced_testcase {
// If they have viewhiddensections, they also get past the section
// restriction.
- role_change_permission($studentroleid, context_course::instance($course->id),
+ role_change_permission($studentroleid, \context_course::instance($course->id),
'moodle/course:ignoreavailabilityrestrictions', CAP_ALLOW);
$expected = array($u1->id, $u2->id, $u3->id);
$this->assertEquals($expected, array_keys($info->filter_user_list($allusers)));
diff --git a/availability/tests/tree_test.php b/availability/tests/tree_test.php
index 445c8d44094..68247d74d35 100644
--- a/availability/tests/tree_test.php
+++ b/availability/tests/tree_test.php
@@ -14,18 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for the condition tree class and related logic.
- *
- * @package core_availability
- * @copyright 2014 The Open University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-use core_availability\capability_checker;
-use \core_availability\tree;
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_availability;
/**
* Unit tests for the condition tree class and related logic.
@@ -34,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tree_testcase extends \advanced_testcase {
+class tree_test extends \advanced_testcase {
public function setUp(): void {
// Load the mock classes so they can be used.
require_once(__DIR__ . '/fixtures/mock_condition.php');
@@ -48,83 +37,83 @@ class tree_testcase extends \advanced_testcase {
try {
new tree('frog');
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('not object', $e->getMessage());
}
try {
new tree((object)array());
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('missing ->op', $e->getMessage());
}
try {
new tree((object)array('op' => '*'));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('unknown ->op', $e->getMessage());
}
try {
new tree((object)array('op' => '|'));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('missing ->show', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => 0));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('->show not bool', $e->getMessage());
}
try {
new tree((object)array('op' => '&'));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('missing ->showc', $e->getMessage());
}
try {
new tree((object)array('op' => '&', 'showc' => 0));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('->showc not array', $e->getMessage());
}
try {
new tree((object)array('op' => '&', 'showc' => array(0)));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('->showc value not bool', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => true));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('missing ->c', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => true,
'c' => 'side'));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('->c not array', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => true,
'c' => array(3)));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('child not object', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => true,
'c' => array((object)array('type' => 'doesnotexist'))));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('Unknown condition type: doesnotexist', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => true,
'c' => array((object)array())));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('missing ->op', $e->getMessage());
}
try {
@@ -133,7 +122,7 @@ class tree_testcase extends \advanced_testcase {
'showc' => array(true, true)
));
$this->fail();
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertStringContainsString('->c, ->showc mismatch', $e->getMessage());
}
}
@@ -336,7 +325,7 @@ class tree_testcase extends \advanced_testcase {
/**
* Shortcut function to check availability and also get information.
*
- * @param stdClass $structure Tree structure
+ * @param \stdClass $structure Tree structure
* @param \core_availability\info $info Location info
* @param int $userid User id
*/
diff --git a/backup/controller/tests/controller_test.php b/backup/controller/tests/controller_test.php
index 5c93fb60e21..cf289501a15 100644
--- a/backup/controller/tests/controller_test.php
+++ b/backup/controller/tests/controller_test.php
@@ -16,22 +16,33 @@
/**
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use backup;
+use backup_controller;
+use restore_controller;
+
defined('MOODLE_INTERNAL') || die();
-// Include all the needed stuff
+// Include all the needed stuff.
global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
-/*
- * controller tests (all)
+/**
+ * Tests for the backup and restore controller classes.
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_controller_testcase extends advanced_testcase {
+class controller_test extends \advanced_testcase {
protected $moduleid; // course_modules id used for testing
protected $sectionid; // course_sections id used for testing
diff --git a/backup/converter/moodle1/tests/moodle1_converter_test.php b/backup/converter/moodle1/tests/moodle1_converter_test.php
index d8ece4bcbac..b11f5058d11 100644
--- a/backup/converter/moodle1/tests/moodle1_converter_test.php
+++ b/backup/converter/moodle1/tests/moodle1_converter_test.php
@@ -14,23 +14,33 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for the moodle1 converter
- *
- * @package core_backup
- * @subpackage backup-convert
- * @category phpunit
- * @copyright 2011 Mark Nielsen
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup;
+use convert_path;
+use convert_path_exception;
+use convert_factory;
+use convert_helper;
+use moodle1_converter;
+use moodle1_convert_empty_storage_exception;
+use moodle1_convert_exception;
+use moodle1_convert_storage_exception;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/backup/converter/moodle1/lib.php');
-
-class core_backup_moodle1_converter_testcase extends advanced_testcase {
+/**
+ * Unit tests for the moodle1 converter
+ *
+ * @package core_backup
+ * @subpackage backup-convert
+ * @category test
+ * @copyright 2011 Mark Nielsen
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class moodle1_converter_test extends \advanced_testcase {
/** @var string the name of the directory containing the unpacked Moodle 1.9 backup */
protected $tempdir;
@@ -68,7 +78,7 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$this->tempdirpath/moddata/unittest/4/icon.gif"
);
- $this->iconhash = file_storage::hash_from_path($this->tempdirpath.'/moddata/unittest/4/icon.gif');
+ $this->iconhash = \file_storage::hash_from_path($this->tempdirpath.'/moddata/unittest/4/icon.gif');
copy(
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$this->tempdirpath/moddata/unittest/4/7/icon.gif"
@@ -351,8 +361,8 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
$this->assertEquals('array', gettype($files['/file1.gif']));
$this->assertEquals('array', gettype($files['/sub1/.']));
$this->assertEquals('array', gettype($files['/sub1/file2.gif']));
- $this->assertEquals(file_storage::hash_from_string(''), $files['/.']['contenthash']);
- $this->assertEquals(file_storage::hash_from_string(''), $files['/sub1/.']['contenthash']);
+ $this->assertEquals(\file_storage::hash_from_string(''), $files['/.']['contenthash']);
+ $this->assertEquals(\file_storage::hash_from_string(''), $files['/sub1/.']['contenthash']);
$this->assertEquals($this->iconhash, $files['/file1.gif']['contenthash']);
$this->assertEquals($this->iconhash, $files['/sub1/file2.gif']['contenthash']);
diff --git a/backup/moodle2/tests/backup_encrypted_content_test.php b/backup/moodle2/tests/backup_encrypted_content_test.php
index d8397e06a35..5323b93cecf 100644
--- a/backup/moodle2/tests/backup_encrypted_content_test.php
+++ b/backup/moodle2/tests/backup_encrypted_content_test.php
@@ -14,13 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for the handling of encrypted contents in backup and restore.
- *
- * @package core_backup
- * @copyright 2016 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup;
+use base_element_struct_exception;
+use encrypted_final_element;
defined('MOODLE_INTERNAL') || die();
@@ -29,7 +27,14 @@ require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_custom_fields.php');
-class core_backup_encrypted_content_testscase extends advanced_testcase {
+/**
+ * Tests for the handling of encrypted contents in backup and restore.
+ *
+ * @package core_backup
+ * @copyright 2016 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class backup_encrypted_content_test extends \advanced_testcase {
public function setUp(): void {
if (!function_exists('openssl_encrypt')) {
@@ -64,7 +69,7 @@ class core_backup_encrypted_content_testscase extends advanced_testcase {
set_config('backup_encryptkey', base64_encode($key), 'backup');
$efe->set_value('tiny_secret');
$this->fail('Expecting base_element_struct_exception exception, none happened');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertInstanceOf('base_element_struct_exception', $e);
$this->assertEquals('encrypted_final_element incorrect key length', $e->errorcode);
diff --git a/backup/moodle2/tests/backup_xml_transformer_test.php b/backup/moodle2/tests/backup_xml_transformer_test.php
index 658f6c1bd4d..9f061029f25 100644
--- a/backup/moodle2/tests/backup_xml_transformer_test.php
+++ b/backup/moodle2/tests/backup_xml_transformer_test.php
@@ -14,15 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for backup_xml_transformer class.
- *
- * @package core_backup
- * @subpackage moodle2
- * @category backup
- * @copyright 2017 Dmitrii Metelkin (dmitriim@catalyst-au.net)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup_xml_transformer;
defined('MOODLE_INTERNAL') || die();
@@ -34,10 +28,12 @@ require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php');
* Tests for backup_xml_transformer.
*
* @package core_backup
+ * @subpackage moodle2
+ * @category test
* @copyright 2017 Dmitrii Metelkin (dmitriim@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_xml_transformer_testcase extends advanced_testcase {
+class backup_xml_transformer_test extends \advanced_testcase {
/**
* Initial set up.
diff --git a/backup/moodle2/tests/fixtures/format_test_cs_options.php b/backup/moodle2/tests/fixtures/format_test_cs_options.php
new file mode 100644
index 00000000000..41e5ee25c3a
--- /dev/null
+++ b/backup/moodle2/tests/fixtures/format_test_cs_options.php
@@ -0,0 +1,82 @@
+.
+
+/**
+ * Various fixture course formats for backup unit tests
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
+ * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+require_once($CFG->dirroot . '/course/format/topics/lib.php');
+
+/**
+ * Fixture course format with one option.
+ */
+class format_test_cs_options extends format_topics {
+ /**
+ * Override method format_topics::get_default_section_name to prevent PHPUnit errors related to the nonexistent
+ * format_test_cs_options lang file.
+ *
+ * @param \stdClass $section The section in question.
+ * @return string The section's name for display.
+ */
+ public function get_default_section_name($section) {
+ if ($section->section == 0) {
+ return parent::get_default_section_name($section);
+ } else {
+ return get_string('sectionname', 'format_topics') . ' ' . $section->section;
+ }
+ }
+
+ public function section_format_options($foreditform = false) {
+ return array(
+ 'numdaystocomplete' => array(
+ 'type' => PARAM_INT,
+ 'label' => 'Test days',
+ 'element_type' => 'text',
+ 'default' => 0,
+ ),
+ );
+ }
+}
+
+/**
+ * Fixture course format with 2 options, 1 inherited.
+ */
+class format_test_cs2_options extends format_test_cs_options {
+ public function section_format_options($foreditform = false) {
+ return array(
+ 'numdaystocomplete' => array(
+ 'type' => PARAM_INT,
+ 'label' => 'Test days',
+ 'element_type' => 'text',
+ 'default' => 0,
+ ),
+ 'secondparameter' => array(
+ 'type' => PARAM_INT,
+ 'label' => 'Test Parmater',
+ 'element_type' => 'text',
+ 'default' => 0,
+ ),
+ ) + parent::section_format_options($foreditform);
+ }
+}
diff --git a/backup/moodle2/tests/moodle2_course_format_test.php b/backup/moodle2/tests/moodle2_course_format_test.php
index bac585934bf..2b72225beb7 100644
--- a/backup/moodle2/tests/moodle2_course_format_test.php
+++ b/backup/moodle2/tests/moodle2_course_format_test.php
@@ -14,13 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for Moodle 2 format backup operation.
- *
- * @package core_backup
- * @copyright 2014 Russell Smith
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup;
+use backup_controller;
+use restore_dbops;
+use restore_controller;
defined('MOODLE_INTERNAL') || die();
@@ -29,6 +28,7 @@ require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
require_once($CFG->dirroot . '/course/format/topics/lib.php');
require_once($CFG->libdir . '/completionlib.php');
+require_once($CFG->dirroot . '/backup/moodle2/tests/fixtures/format_test_cs_options.php');
/**
* Tests for Moodle 2 course format section_options backup operation.
@@ -37,7 +37,7 @@ require_once($CFG->libdir . '/completionlib.php');
* @copyright 2014 Russell Smith
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_moodle2_course_format_testcase extends advanced_testcase {
+class moodle2_course_format_test extends \advanced_testcase {
/**
* Tests a backup and restore adds the required section option data
@@ -58,7 +58,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
'enablecompletion' => COMPLETION_ENABLED),
array('createsections' => true));
- $courseobject = format_base::instance($course->id);
+ $courseobject = \format_base::instance($course->id);
$section = $DB->get_record('course_sections',
array('course' => $course->id, 'section' => 1), '*', MUST_EXIST);
$data = array('id' => $section->id,
@@ -91,7 +91,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
'enablecompletion' => COMPLETION_ENABLED),
array('createsections' => true));
- $courseobject = format_base::instance($course->id);
+ $courseobject = \format_base::instance($course->id);
$section = $DB->get_record('course_sections',
array('course' => $course->id, 'section' => 1), '*', MUST_EXIST);
$data = array('id' => $section->id,
@@ -134,7 +134,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
array('createsections' => true));
// Set section 2 to have both options, and a name.
- $courseobject = format_base::instance($course->id);
+ $courseobject = \format_base::instance($course->id);
$section = $DB->get_record('course_sections',
array('course' => $course->id, 'section' => 2), '*', MUST_EXIST);
$data = array('id' => $section->id,
@@ -151,7 +151,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
// Check that the section contains the options suitable for the new
// format and that even the one with the same name as from the old format
// has NOT been set.
- $newcourseobject = format_base::instance($newcourse->id);
+ $newcourseobject = \format_base::instance($newcourse->id);
$sectionoptions = $newcourseobject->get_format_options(2);
$this->assertArrayHasKey('numdaystocomplete', $sectionoptions);
$this->assertArrayNotHasKey('secondparameter', $sectionoptions);
@@ -167,8 +167,8 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
/**
* Backs a course up and restores it.
*
- * @param stdClass $srccourse Course object to backup
- * @param stdClass $dstcourse Course object to restore into
+ * @param \stdClass $srccourse Course object to backup
+ * @param \stdClass $dstcourse Course object to restore into
* @param int $target Target course mode (backup::TARGET_xx)
* @return int ID of newly restored course
*/
@@ -206,60 +206,3 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
return $newcourseid;
}
}
-
-/**
- * Class format_test_cs_options
- *
- * Test course format that has 1 option.
- */
-class format_test_cs_options extends format_topics {
- /**
- * Override method format_topics::get_default_section_name to prevent PHPUnit errors related to the nonexistent
- * format_test_cs_options lang file.
- *
- * @param stdClass $section The section in question.
- * @return string The section's name for display.
- */
- public function get_default_section_name($section) {
- if ($section->section == 0) {
- return parent::get_default_section_name($section);
- } else {
- return get_string('sectionname', 'format_topics') . ' ' . $section->section;
- }
- }
-
- public function section_format_options($foreditform = false) {
- return array(
- 'numdaystocomplete' => array(
- 'type' => PARAM_INT,
- 'label' => 'Test days',
- 'element_type' => 'text',
- 'default' => 0,
- ),
- );
- }
-}
-
-/**
- * Class format_test_cs2_options
- *
- * Test course format that has 2 options, 1 inherited.
- */
-class format_test_cs2_options extends format_test_cs_options {
- public function section_format_options($foreditform = false) {
- return array(
- 'numdaystocomplete' => array(
- 'type' => PARAM_INT,
- 'label' => 'Test days',
- 'element_type' => 'text',
- 'default' => 0,
- ),
- 'secondparameter' => array(
- 'type' => PARAM_INT,
- 'label' => 'Test Parmater',
- 'element_type' => 'text',
- 'default' => 0,
- ),
- ) + parent::section_format_options($foreditform);
- }
-}
diff --git a/backup/moodle2/tests/moodle2_test.php b/backup/moodle2/tests/moodle2_test.php
index b4fed991b69..778ef6156a7 100644
--- a/backup/moodle2/tests/moodle2_test.php
+++ b/backup/moodle2/tests/moodle2_test.php
@@ -14,13 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for Moodle 2 format backup operation.
- *
- * @package core_backup
- * @copyright 2014 The Open University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup;
+use backup_controller;
+use restore_controller;
+use restore_dbops;
defined('MOODLE_INTERNAL') || die();
@@ -36,7 +35,7 @@ require_once($CFG->libdir . '/completionlib.php');
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_moodle2_testcase extends advanced_testcase {
+class moodle2_test extends \advanced_testcase {
/**
* Tests the availability field on modules and sections is correctly
@@ -64,7 +63,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
// We need a grade, easiest is to add an assignment.
$assignrow = $generator->create_module('assign', array(
'course' => $course->id));
- $assign = new assign(context_module::instance($assignrow->cmid), false, false);
+ $assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
$item = $assign->get_grade_item();
// Make a test grouping as well.
@@ -88,7 +87,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
$modinfo = get_fast_modinfo($newcourseid);
$forums = array_values($modinfo->get_instances_of('forum'));
$assigns = array_values($modinfo->get_instances_of('assign'));
- $newassign = new assign(context_module::instance($assigns[0]->id), false, false);
+ $newassign = new \assign(\context_module::instance($assigns[0]->id), false, false);
$newitem = $newassign->get_grade_item();
$newgroupingid = $DB->get_field('groupings', 'id', array('courseid' => $newcourseid));
@@ -181,7 +180,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
// Grade >= 75%.
$grades = array_values(grade_get_grade_items_for_activity($quizzes[0], true));
$gradeid = $grades[0]->id;
- $coursegrade = grade_item::fetch_course_item($newcourseid);
+ $coursegrade = \grade_item::fetch_course_item($newcourseid);
$this->assertEquals(
'{"op":"&","showc":[true],"c":[{"type":"grade","id":' . $gradeid . ',"min":75}]}',
$pages[4]->availability);
@@ -282,7 +281,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
// We need a grade, easiest is to add an assignment.
$assignrow = $generator->create_module('assign', array(
'course' => $course->id));
- $assign = new assign(context_module::instance($assignrow->cmid), false, false);
+ $assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
$item = $assign->get_grade_item();
// Make a test group and grouping as well.
@@ -461,7 +460,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
/**
* Backs a course up and restores it.
*
- * @param stdClass $course Course object to backup
+ * @param \stdClass $course Course object to backup
* @param int $newdate If non-zero, specifies custom date for new course
* @param callable|null $inbetween If specified, function that is called before restore
* @return int ID of newly restored course
@@ -507,7 +506,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
* This is based on the code from course/modduplicate.php, but reduced for
* simplicity.
*
- * @param stdClass $course Course object
+ * @param \stdClass $course Course object
* @param int $cmid Activity to duplicate
* @return int ID of new activity
*/
@@ -529,7 +528,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
// Find cmid.
$tasks = $rc->get_plan()->get_tasks();
- $cmcontext = context_module::instance($cmid);
+ $cmcontext = \context_module::instance($cmid);
$newcmid = 0;
foreach ($tasks as $task) {
if (is_subclass_of($task, 'restore_activity_task')) {
@@ -541,7 +540,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
}
$rc->destroy();
if (!$newcmid) {
- throw new coding_exception('Unexpected: failure to find restored cmid');
+ throw new \coding_exception('Unexpected: failure to find restored cmid');
}
return $newcmid;
}
@@ -578,7 +577,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
$selfplugin->enrol_user($selfinstance, $user->id, $studentrole->id);
// Give current user capabilities to do backup and restore and assign student role.
- $categorycontext = context_course::instance($course->id)->get_parent_context();
+ $categorycontext = \context_course::instance($course->id)->get_parent_context();
$caps = array_merge([
'moodle/course:view',
@@ -819,8 +818,8 @@ class core_backup_moodle2_testcase extends advanced_testcase {
// Create course and add HTML block.
$course = $generator->create_course();
- $context = context_course::instance($course->id);
- $page = new moodle_page();
+ $context = \context_course::instance($course->id);
+ $page = new \moodle_page();
$page->set_context($context);
$page->set_course($course);
$page->set_pagelayout('standard');
@@ -840,7 +839,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
$newcourseid = $this->backup_and_restore($course);
// Confirm that values were transferred correctly into HTML block on new course.
- $newcontext = context_course::instance($newcourseid);
+ $newcontext = \context_course::instance($newcourseid);
$blockdata = $DB->get_record('block_instances',
['blockname' => 'html', 'parentcontextid' => $newcontext->id]);
$this->assertEquals(12345, $blockdata->timecreated);
@@ -860,7 +859,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
$after = time();
// The fields not specified should default to current time.
- $newcontext = context_course::instance($newcourseid);
+ $newcontext = \context_course::instance($newcourseid);
$blockdata = $DB->get_record('block_instances',
['blockname' => 'html', 'parentcontextid' => $newcontext->id]);
$this->assertTrue($before <= $blockdata->timecreated && $after >= $blockdata->timecreated);
@@ -886,8 +885,8 @@ class core_backup_moodle2_testcase extends advanced_testcase {
$forum = $generator->create_module('forum', ['course' => $course->id]);
// Add a block.
- $context = context_course::instance($course->id);
- $page = new moodle_page();
+ $context = \context_course::instance($course->id);
+ $page = new \moodle_page();
$page->set_context($context);
$page->set_course($course);
$page->set_pagelayout('standard');
@@ -902,7 +901,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
$newcourseid = $this->backup_and_restore($course);
// Now the course should be requested for index (all search areas).
- $newcontext = context_course::instance($newcourseid);
+ $newcontext = \context_course::instance($newcourseid);
$requests = array_values($DB->get_records('search_index_requests'));
$this->assertCount(1, $requests);
$this->assertEquals($newcontext->id, $requests[0]->contextid);
@@ -1077,7 +1076,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
// Create course and add content bank content.
$course = $generator->create_course();
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$filepath = $CFG->dirroot . '/h5p/tests/fixtures/filltheblanks.h5p';
$contents = $cbgenerator->generate_contentbank_data('contenttype_h5p', 2, $USER->id, $context, true, $filepath);
$this->assertEquals(2, $DB->count_records('contentbank_content'));
@@ -1086,7 +1085,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
$newcourseid = $this->backup_and_restore($course);
// Confirm that values were transferred correctly into content bank on new course.
- $newcontext = context_course::instance($newcourseid);
+ $newcontext = \context_course::instance($newcourseid);
$this->assertEquals(4, $DB->count_records('contentbank_content'));
$this->assertEquals(2, $DB->count_records('contentbank_content', ['contextid' => $newcontext->id]));
diff --git a/backup/moodle2/tests/restore_gradebook_structure_step_test.php b/backup/moodle2/tests/restore_gradebook_structure_step_test.php
index 5fdec30d36a..2b47e14c80f 100644
--- a/backup/moodle2/tests/restore_gradebook_structure_step_test.php
+++ b/backup/moodle2/tests/restore_gradebook_structure_step_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Test for restore_stepslib.
- *
- * @package core_backup
- * @copyright 2016 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
defined('MOODLE_INTERNAL') || die();
@@ -36,7 +30,7 @@ require_once($CFG->libdir . '/completionlib.php');
* @copyright 2016 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_restore_gradebook_structure_step_testcase extends advanced_testcase {
+class restore_gradebook_structure_step_test extends \advanced_testcase {
/**
* Provide tests for rewrite_step_backup_file_for_legacy_freeze based upon fixtures.
diff --git a/backup/moodle2/tests/restore_stepslib_date_test.php b/backup/moodle2/tests/restore_stepslib_date_test.php
index e5cc3f43975..cdbc491abf1 100644
--- a/backup/moodle2/tests/restore_stepslib_date_test.php
+++ b/backup/moodle2/tests/restore_stepslib_date_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Restore date tests.
- *
- * @package core_backup
- * @copyright 2017 Adrian Greeve
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
defined('MOODLE_INTERNAL') || die();
@@ -36,7 +30,7 @@ require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
* @copyright 2017 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class restore_stepslib_date_testcase extends restore_date_testcase {
+class restore_stepslib_date_test extends \restore_date_testcase {
/**
* Restoring a manual grade item does not result in the timecreated or
@@ -46,17 +40,17 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
$course = $this->getDataGenerator()->create_course(['startdate' => time()]);
- $params = new stdClass();
+ $params = new \stdClass();
$params->courseid = $course->id;
$params->fullname = 'unittestgradecalccategory';
$params->aggregation = GRADE_AGGREGATE_MEAN;
$params->aggregateonlygraded = 0;
- $gradecategory = new grade_category($params, false);
+ $gradecategory = new \grade_category($params, false);
$gradecategory->insert();
$gradecategory->load_grade_item();
- $gradeitems = new grade_item();
+ $gradeitems = new \grade_item();
$gradeitems->courseid = $course->id;
$gradeitems->categoryid = $gradecategory->id;
$gradeitems->itemname = 'manual grade_item';
@@ -80,7 +74,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
'courseid' => $course->id,
];
- $gradeitem = grade_item::fetch($gradeitemparams);
+ $gradeitem = \grade_item::fetch($gradeitemparams);
// Do backup and restore.
@@ -92,7 +86,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
'courseid' => $course->id,
];
- $newgradeitem = grade_item::fetch($newgradeitemparams);
+ $newgradeitem = \grade_item::fetch($newgradeitemparams);
$this->assertEquals($gradeitem->timecreated, $newgradeitem->timecreated);
$this->assertEquals($gradeitem->timemodified, $newgradeitem->timemodified);
}
@@ -125,7 +119,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
// Create a course.
$course = $this->getDataGenerator()->create_course(['startdate' => time()]);
// Create a badge.
- $fordb = new stdClass();
+ $fordb = new \stdClass();
$fordb->id = null;
$fordb->name = "Test badge";
$fordb->description = "Testing badges";
@@ -187,7 +181,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
'timeduration' => 86400,
'visible' => 1
];
- $calendarevent = calendar_event::create($event, false);
+ $calendarevent = \calendar_event::create($event, false);
// Backup and restore.
$newcourseid = $this->backup_and_restore($course);
@@ -214,7 +208,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
$studentrole = $DB->get_record('role', ['shortname' => 'student']);
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
// Complete the course with a user.
- $ccompletion = new completion_completion(['course' => $course->id,
+ $ccompletion = new \completion_completion(['course' => $course->id,
'userid' => $user->id,
'timeenrolled' => time(),
'timestarted' => time()
@@ -227,7 +221,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
$newcourseid = $this->backup_and_restore($course);
$newcourse = get_course($newcourseid);
- $newcompletion = completion_completion::fetch(['course' => $newcourseid, 'userid' => $user->id]);
+ $newcompletion = \completion_completion::fetch(['course' => $newcourseid, 'userid' => $user->id]);
// Compare dates.
$this->assertEquals($ccompletion->timeenrolled, $newcompletion->timeenrolled);
@@ -244,7 +238,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
// Testing the restore of an overridden grade.
list($course, $assign) = $this->create_course_and_module('assign', []);
$cm = $DB->get_record('course_modules', ['course' => $course->id, 'instance' => $assign->id]);
- $assignobj = new mod_assign_testable_assign(context_module::instance($cm->id), $cm, $course);
+ $assignobj = new \mod_assign_testable_assign(\context_module::instance($cm->id), $cm, $course);
$submission = $assignobj->get_user_submission($USER->id, true);
$grade = $assignobj->get_user_grade($USER->id, true);
$grade->grade = 75;
@@ -257,10 +251,10 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
'itemmodule' => 'assign',
'courseid' => $course->id,
];
- $gradeitem = grade_item::fetch($gradeitemparams);
+ $gradeitem = \grade_item::fetch($gradeitemparams);
// Next the grade grade.
- $gradegrade = grade_grade::fetch(['itemid' => $gradeitem->id, 'userid' => $USER->id]);
+ $gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->id, 'userid' => $USER->id]);
$gradegrade->set_overridden(true);
// Back up and restore.
@@ -277,9 +271,9 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
'courseid' => $newcourse->id,
];
- $newgradeitem = grade_item::fetch($newgradeitemparams);
+ $newgradeitem = \grade_item::fetch($newgradeitemparams);
// Find grade grade.
- $newgradegrade = grade_grade::fetch(['itemid' => $newgradeitem->id, 'userid' => $USER->id]);
+ $newgradegrade = \grade_grade::fetch(['itemid' => $newgradeitem->id, 'userid' => $USER->id]);
// Compare dates.
$this->assertEquals($gradegrade->timecreated, $newgradegrade->timecreated);
$this->assertEquals($gradegrade->timemodified, $newgradegrade->timemodified);
@@ -300,7 +294,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
'completionusegrade' => 1 // Student must receive a grade to complete this activity.
]);
$cm = $DB->get_record('course_modules', ['course' => $course->id, 'instance' => $assign->id]);
- $assignobj = new mod_assign_testable_assign(context_module::instance($cm->id), $cm, $course);
+ $assignobj = new \mod_assign_testable_assign(\context_module::instance($cm->id), $cm, $course);
$submission = $assignobj->get_user_submission($USER->id, true);
$grade = $assignobj->get_user_grade($USER->id, true);
$grade->grade = 75;
@@ -350,10 +344,10 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
// Make a user to do the quiz.
$user1 = $this->getDataGenerator()->create_user();
- $quizobj = quiz::create($quiz->id, $user1->id);
+ $quizobj = \quiz::create($quiz->id, $user1->id);
// Start the attempt.
- $quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
+ $quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$timenow = time();
@@ -364,7 +358,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
quiz_attempt_save_started($quizobj, $quba, $attempt);
// Process some responses from the student.
- $attemptobj = quiz_attempt::create($attempt->id);
+ $attemptobj = \quiz_attempt::create($attempt->id);
$prefix1 = $quba->get_field_prefix(1);
$prefix2 = $quba->get_field_prefix(2);
@@ -375,7 +369,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
$attemptobj->process_submitted_actions($timenow, false, $tosubmit);
// Finish the attempt.
- $attemptobj = quiz_attempt::create($attempt->id);
+ $attemptobj = \quiz_attempt::create($attempt->id);
$attemptobj->process_finish($timenow, false);
$questionattemptstepdates = [];
@@ -390,14 +384,14 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
// Get the quiz for this new restored course.
$quizdata = $DB->get_record('quiz', ['course' => $newcourseid]);
- $quizobj = quiz::create($quizdata->id, $user1->id);
+ $quizobj = \quiz::create($quizdata->id, $user1->id);
$questionusage = $DB->get_record('question_usages', [
'component' => 'mod_quiz',
'contextid' => $quizobj->get_context()->id
]);
- $newquba = question_engine::load_questions_usage_by_activity($questionusage->id);
+ $newquba = \question_engine::load_questions_usage_by_activity($questionusage->id);
$restorediterator = $newquba->get_attempt_iterator();
$i = 0;
diff --git a/backup/tests/async_backup_test.php b/backup/tests/async_backup_test.php
index 2984abd77e0..8e19151c085 100644
--- a/backup/tests/async_backup_test.php
+++ b/backup/tests/async_backup_test.php
@@ -14,13 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Asyncronhous backup tests.
- *
- * @package core_backup
- * @copyright 2018 Matt Porritt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup;
+use backup_controller;
defined('MOODLE_INTERNAL') || die();
@@ -32,10 +29,11 @@ require_once($CFG->libdir . '/completionlib.php');
/**
* Asyncronhous backup tests.
*
+ * @package core_backup
* @copyright 2018 Matt Porritt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_async_backup_testcase extends \core_privacy\tests\provider_testcase {
+class async_backup_test extends \advanced_testcase {
/**
* Tests the asynchronous backup.
@@ -66,7 +64,7 @@ class core_backup_async_backup_testcase extends \core_privacy\tests\provider_tes
// We need a grade, easiest is to add an assignment.
$assignrow = $generator->create_module('assign', array(
'course' => $course->id));
- $assign = new assign(context_module::instance($assignrow->cmid), false, false);
+ $assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
$item = $assign->get_grade_item();
// Make a test grouping as well.
@@ -161,7 +159,7 @@ class core_backup_async_backup_testcase extends \core_privacy\tests\provider_tes
// We need a grade, easiest is to add an assignment.
$assignrow = $generator->create_module('assign', array(
'course' => $course->id));
- $assign = new assign(context_module::instance($assignrow->cmid), false, false);
+ $assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
$item = $assign->get_grade_item();
// Make a test grouping as well.
diff --git a/backup/tests/async_restore_test.php b/backup/tests/async_restore_test.php
index 0b747904cf6..01faf9a1731 100644
--- a/backup/tests/async_restore_test.php
+++ b/backup/tests/async_restore_test.php
@@ -14,13 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Asyncronhous restore tests.
- *
- * @package core_backup
- * @copyright 2018 Matt Porritt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup;
+use backup_controller;
+use restore_controller;
+use restore_dbops;
defined('MOODLE_INTERNAL') || die();
@@ -32,10 +31,11 @@ require_once($CFG->libdir . '/completionlib.php');
/**
* Asyncronhous restore tests.
*
+ * @package core_backup
* @copyright 2018 Matt Porritt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_async_restore_testcase extends \core_privacy\tests\provider_testcase {
+class async_restore_test extends \advanced_testcase {
/**
* Tests the asynchronous backup.
@@ -62,7 +62,7 @@ class core_backup_async_restore_testcase extends \core_privacy\tests\provider_te
// We need a grade, easiest is to add an assignment.
$assignrow = $generator->create_module('assign', array(
'course' => $course->id));
- $assign = new assign(context_module::instance($assignrow->cmid), false, false);
+ $assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
$item = $assign->get_grade_item();
// Make a test grouping as well.
@@ -88,7 +88,7 @@ class core_backup_async_restore_testcase extends \core_privacy\tests\provider_te
$bc->destroy();
// Get the backup file.
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
$fs = get_file_storage();
$files = $fs->get_area_files($coursecontext->id, 'backup', 'course', false, 'id ASC');
$backupfile = reset($files);
@@ -164,7 +164,7 @@ class core_backup_async_restore_testcase extends \core_privacy\tests\provider_te
// We need a grade, easiest is to add an assignment.
$assignrow = $generator->create_module('assign', array(
'course' => $course->id));
- $assign = new assign(context_module::instance($assignrow->cmid), false, false);
+ $assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
$item = $assign->get_grade_item();
// Make a test grouping as well.
@@ -189,7 +189,7 @@ class core_backup_async_restore_testcase extends \core_privacy\tests\provider_te
$bc->destroy();
// Get the backup file.
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
$fs = get_file_storage();
$files = $fs->get_area_files($coursecontext->id, 'backup', 'course', false, 'id ASC');
$backupfile = reset($files);
diff --git a/backup/tests/automated_backup_test.php b/backup/tests/automated_backup_test.php
index c2fb61e4ad8..4dec8ddc691 100644
--- a/backup/tests/automated_backup_test.php
+++ b/backup/tests/automated_backup_test.php
@@ -22,6 +22,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use backup_cron_automated_helper;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -32,17 +36,18 @@ require_once($CFG->libdir . '/completionlib.php');
/**
* Automated backup tests.
*
+ * @package core_backup
* @copyright 2019 John Yao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_automated_backup_testcase extends advanced_testcase {
+class automated_backup_test extends \advanced_testcase {
/**
* @var \backup_cron_automated_helper
*/
protected $backupcronautomatedhelper;
/**
- * @var stdClass $course
+ * @var \stdClass $course
*/
protected $course;
@@ -70,7 +75,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
// We need a grade, easiest is to add an assignment.
$assignrow = $generator->create_module('assign', array(
'course' => $this->course->id));
- $assign = new assign(context_module::instance($assignrow->cmid), false, false);
+ $assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
$item = $assign->get_grade_item();
// Make a test grouping as well.
@@ -111,11 +116,11 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
$classobject = $this->backupcronautomatedhelper->return_this();
- $method = new ReflectionMethod('\backup_cron_automated_helper', 'get_courses');
+ $method = new \ReflectionMethod('\backup_cron_automated_helper', 'get_courses');
$method->setAccessible(true); // Allow accessing of private method.
$courses = $method->invoke($classobject);
- $method = new ReflectionMethod('\backup_cron_automated_helper', 'check_and_push_automated_backups');
+ $method = new \ReflectionMethod('\backup_cron_automated_helper', 'check_and_push_automated_backups');
$method->setAccessible(true); // Allow accessing of private method.
$emailpending = $method->invokeArgs($classobject, [$courses, $admin]);
@@ -141,12 +146,12 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
$classobject = $this->backupcronautomatedhelper->return_this();
- $method = new ReflectionMethod('\backup_cron_automated_helper', 'get_courses');
+ $method = new \ReflectionMethod('\backup_cron_automated_helper', 'get_courses');
$method->setAccessible(true); // Allow accessing of private method.
$courses = $method->invoke($classobject);
// Create this backup course.
- $backupcourse = new stdClass;
+ $backupcourse = new \stdClass;
$backupcourse->courseid = $this->course->id;
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_NOTYETRUN;
$DB->insert_record('backup_courses', $backupcourse);
@@ -157,7 +162,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
$backupcourse->nextstarttime = time() - 10;
$DB->update_record('backup_courses', $backupcourse);
- $method = new ReflectionMethod('\backup_cron_automated_helper', 'check_and_push_automated_backups');
+ $method = new \ReflectionMethod('\backup_cron_automated_helper', 'check_and_push_automated_backups');
$method->setAccessible(true); // Allow accessing of private method.
$emailpending = $method->invokeArgs($classobject, [$courses, $admin]);
$this->assertTrue($emailpending);
@@ -188,7 +193,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
set_config('backup_auto_skip_hidden', true, 'backup');
set_config('backup_auto_weekdays', '1111111', 'backup');
// Create this backup course.
- $backupcourse = new stdClass;
+ $backupcourse = new \stdClass;
$backupcourse->courseid = $this->course->id;
// This is the status we believe last run was OK.
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
@@ -201,7 +206,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
$classobject = $this->backupcronautomatedhelper->return_this();
$nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup(null, time());
- $method = new ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
+ $method = new \ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
$method->setAccessible(true); // Allow accessing of private method.
$skipped = $method->invokeArgs($classobject, [$backupcourse, $course, $nextstarttime]);
@@ -221,7 +226,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
set_config('backup_auto_weekdays', '1111111', 'backup');
// Create this backup course.
- $backupcourse = new stdClass;
+ $backupcourse = new \stdClass;
$backupcourse->courseid = $this->course->id;
// This is the status we believe last run was OK.
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
@@ -236,7 +241,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
$classobject = $this->backupcronautomatedhelper->return_this();
$nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup(null, time());
- $method = new ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
+ $method = new \ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
$method->setAccessible(true); // Allow accessing of private method.
$skipped = $method->invokeArgs($classobject, [$backupcourse, $course, $nextstarttime]);
@@ -256,7 +261,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
set_config('backup_auto_weekdays', '1111111', 'backup');
// Create this backup course.
- $backupcourse = new stdClass;
+ $backupcourse = new \stdClass;
$backupcourse->courseid = $this->course->id;
// This is the status we believe last run was OK.
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
@@ -271,7 +276,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
$classobject = $this->backupcronautomatedhelper->return_this();
$nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup(null, time());
- $method = new ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
+ $method = new \ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
$method->setAccessible(true); // Allow accessing of private method.
$skipped = $method->invokeArgs($classobject, [$backupcourse, $course, $nextstarttime]);
@@ -288,28 +293,28 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
$classobject = $this->backupcronautomatedhelper->return_this();
// Create this backup course.
- $backupcourse = new stdClass;
+ $backupcourse = new \stdClass;
$backupcourse->courseid = $this->course->id;
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_NOTYETRUN;
$DB->insert_record('backup_courses', $backupcourse);
$backupcourse = $DB->get_record('backup_courses', ['courseid' => $this->course->id]);
// Create a backup task.
- $method = new ReflectionMethod('\backup_cron_automated_helper', 'push_course_backup_adhoc_task');
+ $method = new \ReflectionMethod('\backup_cron_automated_helper', 'push_course_backup_adhoc_task');
$method->setAccessible(true); // Allow accessing of private method.
$method->invokeArgs($classobject, [$backupcourse, $admin]);
// Delete course for this test.
delete_course($this->course->id, false);
- $task = core\task\manager::get_next_adhoc_task(time());
+ $task = \core\task\manager::get_next_adhoc_task(time());
ob_start();
$task->execute();
$output = ob_get_clean();
$this->assertStringContainsString('Invalid course id: ' . $this->course->id . ', task aborted.', $output);
- core\task\manager::adhoc_task_complete($task);
+ \core\task\manager::adhoc_task_complete($task);
}
/**
@@ -321,21 +326,21 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
$classobject = $this->backupcronautomatedhelper->return_this();
// Create this backup course.
- $backupcourse = new stdClass;
+ $backupcourse = new \stdClass;
$backupcourse->courseid = $this->course->id;
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_NOTYETRUN;
$DB->insert_record('backup_courses', $backupcourse);
$backupcourse = $DB->get_record('backup_courses', ['courseid' => $this->course->id]);
// Create a backup task.
- $method = new ReflectionMethod('\backup_cron_automated_helper', 'push_course_backup_adhoc_task');
+ $method = new \ReflectionMethod('\backup_cron_automated_helper', 'push_course_backup_adhoc_task');
$method->setAccessible(true); // Allow accessing of private method.
$method->invokeArgs($classobject, [$backupcourse, $admin]);
// Delete backup course for this test.
$DB->delete_records('backup_courses', ['courseid' => $this->course->id]);
- $task = core\task\manager::get_next_adhoc_task(time());
+ $task = \core\task\manager::get_next_adhoc_task(time());
ob_start();
$task->execute();
@@ -343,7 +348,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
$this->assertStringContainsString('Automated backup for course: ' . $this->course->fullname . ' encounters an error.',
$output);
- core\task\manager::adhoc_task_complete($task);
+ \core\task\manager::adhoc_task_complete($task);
}
}
diff --git a/backup/tests/backup_cleanup_task_test.php b/backup/tests/backup_cleanup_task_test.php
index 98fdbb314fd..0a10bd65ccd 100644
--- a/backup/tests/backup_cleanup_task_test.php
+++ b/backup/tests/backup_cleanup_task_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for the \core\task\backup_cleanup_task scheduled task.
- *
- * @package core_backup
- * @copyright 2021 Mikhail Golenkov
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
defined('MOODLE_INTERNAL') || die();
@@ -30,10 +24,11 @@ require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
/**
* Tests for the \core\task\backup_cleanup_task scheduled task.
*
+ * @package core_backup
* @copyright 2021 Mikhail Golenkov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_cleanup_task_testcase extends advanced_testcase {
+class backup_cleanup_task_test extends \advanced_testcase {
/**
* Set up tasks for all tests.
diff --git a/backup/tests/backup_restore_permission_test.php b/backup/tests/backup_restore_permission_test.php
index 42929a426b0..4d15cbe8c27 100644
--- a/backup/tests/backup_restore_permission_test.php
+++ b/backup/tests/backup_restore_permission_test.php
@@ -14,13 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Backup restore permission tests.
- *
- * @package core_backup
- * @copyright Tomo Tsuyuki
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use core_backup_backup_restore_base_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -30,9 +26,13 @@ require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
/**
- * Testcase class for permission backup / restore functionality.
+ * Backup restore permission tests.
+ *
+ * @package core_backup
+ * @copyright Tomo Tsuyuki
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_backup_restore_permission_testcase extends core_backup_backup_restore_base_testcase {
+class backup_restore_permission_test extends core_backup_backup_restore_base_testcase {
/** @var stdClass A test course which is restored/imported from. */
protected $course1;
@@ -62,9 +62,9 @@ class core_backup_backup_restore_permission_testcase extends core_backup_backup_
// Create a course with some availability data set.
$generator = $this->getDataGenerator();
$this->course1 = $generator->create_course();
- $this->course1context = context_course::instance($this->course1->id);
+ $this->course1context = \context_course::instance($this->course1->id);
$this->course2 = $generator->create_course();
- $this->course2context = context_course::instance($this->course2->id);
+ $this->course2context = \context_course::instance($this->course2->id);
$this->capabilityname = 'enrol/manual:enrol';
$this->user = $generator->create_user();
diff --git a/backup/tests/course_copy_test.php b/backup/tests/course_copy_test.php
index 40f216853e9..59e8efa2fa4 100644
--- a/backup/tests/course_copy_test.php
+++ b/backup/tests/course_copy_test.php
@@ -14,14 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Course copy tests.
- *
- * @package core_backup
- * @copyright 2020 onward The Moodle Users Association
- * @author Matt Porritt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -37,7 +33,7 @@ require_once($CFG->libdir . '/completionlib.php');
* @author Matt Porritt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_course_copy_testcase extends advanced_testcase {
+class course_copy_test extends \advanced_testcase {
/**
*
@@ -88,7 +84,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
// We need a grade, easiest is to add an assignment.
$assignrow = $generator->create_module('assign', array(
'course' => $course->id));
- $assign = new assign(context_module::instance($assignrow->cmid), false, false);
+ $assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
$item = $assign->get_grade_item();
// Make a test grouping as well.
@@ -384,7 +380,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
$this->assertEquals(1.0, $postrestorerec->progress);
// Check the restored course itself.
- $coursecontext = context_course::instance($postrestorerec->itemid);
+ $coursecontext = \context_course::instance($postrestorerec->itemid);
$users = get_enrolled_users($coursecontext);
$modinfo = get_fast_modinfo($postrestorerec->itemid);
@@ -452,7 +448,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
$postrestorerec = $DB->get_record('backup_controllers', array('backupid' => $copyids['restoreid']));
// Check the restored course itself.
- $coursecontext = context_course::instance($postrestorerec->itemid);
+ $coursecontext = \context_course::instance($postrestorerec->itemid);
$users = get_enrolled_users($coursecontext);
$modinfo = get_fast_modinfo($postrestorerec->itemid);
@@ -521,7 +517,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
$postrestorerec = $DB->get_record('backup_controllers', array('backupid' => $copyids['restoreid']));
// Check the restored course itself.
- $coursecontext = context_course::instance($postrestorerec->itemid);
+ $coursecontext = \context_course::instance($postrestorerec->itemid);
$users = get_enrolled_users($coursecontext);
$modinfo = get_fast_modinfo($postrestorerec->itemid);
@@ -590,7 +586,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
$postrestorerec = $DB->get_record('backup_controllers', array('backupid' => $copyids['restoreid']));
// Check the restored course itself.
- $coursecontext = context_course::instance($postrestorerec->itemid);
+ $coursecontext = \context_course::instance($postrestorerec->itemid);
$users = get_enrolled_users($coursecontext);
get_fast_modinfo($postrestorerec->itemid, 0, true);
diff --git a/backup/tests/quiz_restore_decode_links_test.php b/backup/tests/quiz_restore_decode_links_test.php
index 46a643619f5..cbf0506e310 100644
--- a/backup/tests/quiz_restore_decode_links_test.php
+++ b/backup/tests/quiz_restore_decode_links_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Decode links quiz restore tests.
- *
- * @package core_backup
- * @copyright 2020 Ilya Tregubov
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
defined('MOODLE_INTERNAL') || die();
@@ -31,9 +25,13 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
/**
- * restore_decode tests (both rule and content)
+ * Decode links quiz restore tests.
+ *
+ * @package core_backup
+ * @copyright 2020 Ilya Tregubov
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class restore_quiz_decode_testcase extends \core_privacy\tests\provider_testcase {
+class quiz_restore_decode_links_test extends \advanced_testcase {
/**
* Test restore_decode_rule class
@@ -55,14 +53,14 @@ class restore_quiz_decode_testcase extends \core_privacy\tests\provider_testcase
// Create questions.
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$cat = $questiongenerator->create_question_category(array('contextid' => $context->id));
$question = $questiongenerator->create_question('multichoice', null, array('category' => $cat->id));
// Add to the quiz.
quiz_add_quiz_question($question->id, $quiz);
- $questiondata = question_bank::load_question_data($question->id);
+ $questiondata = \question_bank::load_question_data($question->id);
$firstanswer = array_shift($questiondata->options->answers);
$DB->set_field('question_answers', 'answer', $CFG->wwwroot . '/course/view.php?id=' . $course->id,
diff --git a/backup/util/checks/tests/checks_test.php b/backup/util/checks/tests/checks_test.php
index 3b8904358a1..d94f7eff417 100644
--- a/backup/util/checks/tests/checks_test.php
+++ b/backup/util/checks/tests/checks_test.php
@@ -15,12 +15,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * @package core_backup
- * @category phpunit
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup;
+use backup_check;
+use backup_controller;
+use backup_controller_exception;
defined('MOODLE_INTERNAL') || die();
@@ -28,11 +28,15 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
-
-/*
- * check tests (all)
+/**
+ * Check tests (all).
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_check_testcase extends advanced_testcase {
+class checks_test extends \advanced_testcase {
protected $moduleid; // course_modules id used for testing
protected $sectionid; // course_sections id used for testing
@@ -77,21 +81,21 @@ class backup_check_testcase extends advanced_testcase {
try {
backup_check::check_id(backup::TYPE_1ACTIVITY, 0);
$this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof backup_controller_exception);
$this->assertEquals($e->errorcode, 'backup_check_module_not_exists');
}
try {
backup_check::check_id(backup::TYPE_1SECTION, 0);
$this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
+ } catch (\exception $e) {
$this->assertTrue($e instanceof backup_controller_exception);
$this->assertEquals($e->errorcode, 'backup_check_section_not_exists');
}
try {
backup_check::check_id(backup::TYPE_1COURSE, 0);
$this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof backup_controller_exception);
$this->assertEquals($e->errorcode, 'backup_check_course_not_exists');
}
@@ -100,7 +104,7 @@ class backup_check_testcase extends advanced_testcase {
try {
backup_check::check_id(12345678,0);
$this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof backup_controller_exception);
$this->assertEquals($e->errorcode, 'backup_check_incorrect_type');
}
@@ -110,7 +114,7 @@ class backup_check_testcase extends advanced_testcase {
try {
backup_check::check_user($userid);
$this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof backup_controller_exception);
$this->assertEquals($e->errorcode, 'backup_check_user_not_exists');
}
@@ -118,9 +122,9 @@ class backup_check_testcase extends advanced_testcase {
// Security check tests
// Try to pass wrong controller
try {
- backup_check::check_security(new stdclass(), true);
+ backup_check::check_security(new \stdClass(), true);
$this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof backup_controller_exception);
$this->assertEquals($e->errorcode, 'backup_check_security_requires_backup_controller');
}
diff --git a/backup/util/dbops/tests/backup_dbops_test.php b/backup/util/dbops/tests/backup_dbops_test.php
index 7a18eb0fae4..e644b42d88c 100644
--- a/backup/util/dbops/tests/backup_dbops_test.php
+++ b/backup/util/dbops/tests/backup_dbops_test.php
@@ -16,11 +16,19 @@
/**
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use backup;
+use backup_controller;
+use backup_controller_dbops;
+use backup_controller_exception;
+use backup_dbops_exception;
+
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff
@@ -28,9 +36,12 @@ global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
/**
- * Backup dbops tests (all).
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_dbops_testcase extends advanced_testcase {
+class backup_dbops_test extends \advanced_testcase {
protected $moduleid; // course_modules id used for testing
protected $sectionid; // course_sections id used for testing
@@ -98,17 +109,17 @@ class backup_dbops_testcase extends advanced_testcase {
try {
$recid = backup_controller_dbops::save_controller($bc, 'lalala');
$this->assertTrue(false, 'backup_dbops_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof backup_dbops_exception);
$this->assertEquals($e->errorcode, 'backup_controller_dbops_saving_checksum_mismatch');
}
// Try to save non backup_controller object
- $bc = new stdclass();
+ $bc = new \stdClass();
try {
$recid = backup_controller_dbops::save_controller($bc, 'lalala');
$this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof backup_controller_exception);
$this->assertEquals($e->errorcode, 'backup_controller_expected');
}
@@ -129,7 +140,7 @@ class backup_dbops_testcase extends advanced_testcase {
try {
$bc = backup_controller_dbops::load_controller('1234567890');
$this->assertTrue(false, 'backup_dbops_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof backup_dbops_exception);
$this->assertEquals($e->errorcode, 'backup_controller_dbops_nonexisting');
}
@@ -150,7 +161,7 @@ class backup_dbops_testcase extends advanced_testcase {
// Test encoding/decoding of backup_ids_temp,backup_files_temp encode/decode functions.
// We need to handle both objects and data elements.
- $object = new stdClass();
+ $object = new \stdClass();
$object->item1 = 10;
$object->item2 = 'a String';
$testarray = array($object, 10, null, 'string', array('a' => 'b', 1 => 1));
diff --git a/backup/util/dbops/tests/restore_dbops_test.php b/backup/util/dbops/tests/restore_dbops_test.php
index 78060ae1ea7..325c01a4adb 100644
--- a/backup/util/dbops/tests/restore_dbops_test.php
+++ b/backup/util/dbops/tests/restore_dbops_test.php
@@ -14,12 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * @package core_backup
- * @category phpunit
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use restore_controller_dbops;
+use restore_dbops;
defined('MOODLE_INTERNAL') || die();
@@ -28,9 +26,12 @@ global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
/**
- * Restore dbops tests (all).
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class restore_dbops_testcase extends advanced_testcase {
+class restore_dbops_test extends \advanced_testcase {
/**
* Verify the xxx_ids_cached (in-memory backup_ids cache) stuff works as expected.
@@ -47,7 +48,7 @@ class restore_dbops_testcase extends advanced_testcase {
// Some variables and objects for testing.
$restoreid = 'testrestoreid';
- $mapping = new stdClass();
+ $mapping = new \stdClass();
$mapping->itemname = 'user';
$mapping->itemid = 1;
$mapping->newitemid = 2;
@@ -68,8 +69,8 @@ class restore_dbops_testcase extends advanced_testcase {
$this->assertSame(null, $result->info);
// Drop the backup_xxx_temp temptables manually, so memory cache won't be invalidated.
- $dbman->drop_table(new xmldb_table('backup_ids_temp'));
- $dbman->drop_table(new xmldb_table('backup_files_temp'));
+ $dbman->drop_table(new \xmldb_table('backup_ids_temp'));
+ $dbman->drop_table(new \xmldb_table('backup_files_temp'));
// Verify the mapping continues returning the same info,
// now from cache (the table does not exist).
@@ -90,8 +91,8 @@ class restore_dbops_testcase extends advanced_testcase {
try {
$result = restore_dbops::get_backup_ids_record($restoreid, $mapping->itemname, $mapping->itemid);
$this->fail('Expecting an exception, none occurred');
- } catch (Exception $e) {
- $this->assertTrue($e instanceof dml_exception);
+ } catch (\Exception $e) {
+ $this->assertTrue($e instanceof \dml_exception);
$this->assertSame('Table "backup_ids_temp" does not exist', $e->getMessage());
}
@@ -114,8 +115,8 @@ class restore_dbops_testcase extends advanced_testcase {
try {
$result = restore_dbops::get_backup_ids_record($restoreid, $mapping->itemname, $mapping->itemid);
$this->fail('Expecting an exception, none occurred');
- } catch (Exception $e) {
- $this->assertTrue($e instanceof dml_exception);
+ } catch (\Exception $e) {
+ $this->assertTrue($e instanceof \dml_exception);
$this->assertSame('Table "backup_ids_temp" does not exist', $e->getMessage());
}
}
@@ -349,7 +350,7 @@ class restore_dbops_testcase extends advanced_testcase {
// Get the dbuser record, because we may have changed it above.
$dbuser = $DB->get_record('user', ['id' => $dbuser->id]);
- $method = (new ReflectionClass('restore_dbops'))->getMethod('precheck_user');
+ $method = (new \ReflectionClass('restore_dbops'))->getMethod('precheck_user');
$method->setAccessible(true);
$result = $method->invoke(null, $backupuser, $samesite, $siteid);
diff --git a/backup/util/destinations/tests/destinations_test.php b/backup/util/destinations/tests/destinations_test.php
index 42da3811153..ef0b4f346f7 100644
--- a/backup/util/destinations/tests/destinations_test.php
+++ b/backup/util/destinations/tests/destinations_test.php
@@ -14,23 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_backup;
+
/**
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-// Include all the needed stuff
-global $CFG;
-//require_once($CFG->dirroot . '/backup/util/helper/backup_helper.class.php');
-
-/**
- * dbops tests (all)
- */
-class backup_destinations_testcase extends basic_testcase {
+class destinations_test extends \basic_testcase {
/**
* test backup_destination class
diff --git a/backup/util/factories/tests/factories_test.php b/backup/util/factories/tests/factories_test.php
index 7cebfc56c56..d67f6defc02 100644
--- a/backup/util/factories/tests/factories_test.php
+++ b/backup/util/factories/tests/factories_test.php
@@ -14,12 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * @package core_backup
- * @category phpunit
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup;
+use backup_factory;
+use database_logger;
+use error_log_logger;
+use file_logger;
+use output_indented_logger;
defined('MOODLE_INTERNAL') || die();
@@ -34,11 +36,13 @@ require_once($CFG->dirroot . '/backup/util/loggers/database_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/file_logger.class.php');
require_once($CFG->dirroot . '/backup/util/factories/backup_factory.class.php');
-
/**
- * backup_factory tests (all)
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_factories_testcase extends advanced_testcase {
+class factories_test extends \advanced_testcase {
public function setUp(): void {
global $CFG;
diff --git a/backup/util/helper/tests/async_helper_test.php b/backup/util/helper/tests/async_helper_test.php
index d44bfb2cf17..da485ab8d9a 100644
--- a/backup/util/helper/tests/async_helper_test.php
+++ b/backup/util/helper/tests/async_helper_test.php
@@ -14,13 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Asyncronhous helper tests.
- *
- * @package core_backup
- * @copyright 2018 Matt Porritt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use async_helper;
+use backup;
+use backup_controller;
defined('MOODLE_INTERNAL') || die();
@@ -31,10 +29,11 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
/**
* Asyncronhous helper tests.
*
+ * @package core_backup
* @copyright 2018 Matt Porritt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_async_helper_testcase extends \core_privacy\tests\provider_testcase {
+class async_helper_test extends \advanced_testcase {
/**
* Tests sending message for asynchronous backup.
@@ -113,7 +112,7 @@ class core_backup_async_helper_testcase extends \core_privacy\tests\provider_tes
// We need a grade, easiest is to add an assignment.
$assignrow = $generator->create_module('assign', array(
'course' => $course->id));
- $assign = new assign(context_module::instance($assignrow->cmid), false, false);
+ $assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
$item = $assign->get_grade_item();
// Make a test grouping as well.
@@ -137,7 +136,7 @@ class core_backup_async_helper_testcase extends \core_privacy\tests\provider_tes
$bc->destroy();
unset($bc);
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
$renderer = $PAGE->get_renderer('core', 'backup');
$result = \async_helper::get_async_backups($renderer, $coursecontext->instanceid);
diff --git a/backup/util/helper/tests/backup_encode_content_test.php b/backup/util/helper/tests/backup_encode_content_test.php
index 54067125e24..c93df258173 100644
--- a/backup/util/helper/tests/backup_encode_content_test.php
+++ b/backup/util/helper/tests/backup_encode_content_test.php
@@ -14,30 +14,29 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * @package core_backup
- * @category phpunit
- * @copyright 2013 The Open University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use backup_course_task;
defined('MOODLE_INTERNAL') || die();
-
global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_course_task.class.php');
-
-
/**
* Tests for encoding content links in backup_course_task.
*
* The code that this tests is actually in backup/moodle2/backup_course_task.class.php,
* but there is no place for unit tests near there, and perhaps one day it will
* be refactored so it becomes more generic.
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2013 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_course_task_testcase extends basic_testcase {
+class backup_encode_content_test extends \basic_testcase {
/**
* Test the encode_content_links method for course.
diff --git a/backup/util/helper/tests/converterhelper_test.php b/backup/util/helper/tests/converterhelper_test.php
index 7824ab26d31..6086c10f08a 100644
--- a/backup/util/helper/tests/converterhelper_test.php
+++ b/backup/util/helper/tests/converterhelper_test.php
@@ -15,34 +15,34 @@
// along with Moodle. If not, see .
/**
+ * Test the convert helper.
+ *
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use backup;
+use convert_helper;
+
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff
global $CFG;
require_once($CFG->dirroot . '/backup/util/helper/convert_helper.class.php');
-
/**
- * Provides access to the protected methods we need to test
+ * Test the convert helper.
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class testable_convert_helper extends convert_helper {
-
- public static function choose_conversion_path($format, array $descriptions) {
- return parent::choose_conversion_path($format, $descriptions);
- }
-}
-
-
-/**
- * Defines the test methods
- */
-class backup_convert_helper_testcase extends basic_testcase {
+class converterhelper_test extends \basic_testcase {
public function test_choose_conversion_path() {
@@ -143,3 +143,13 @@ class backup_convert_helper_testcase extends basic_testcase {
$this->assertEquals($path, array('cc1', 'cc3', 'cc4'));
}
}
+
+/**
+ * Provides access to the protected methods we need to test
+ */
+class testable_convert_helper extends convert_helper {
+
+ public static function choose_conversion_path($format, array $descriptions) {
+ return parent::choose_conversion_path($format, $descriptions);
+ }
+}
diff --git a/backup/util/helper/tests/cronhelper_test.php b/backup/util/helper/tests/cronhelper_test.php
index c580aa497d9..22833e74533 100644
--- a/backup/util/helper/tests/cronhelper_test.php
+++ b/backup/util/helper/tests/cronhelper_test.php
@@ -18,11 +18,16 @@
* Unit tests for backups cron helper.
*
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2012 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use backup;
+use backup_cron_automated_helper;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -31,9 +36,14 @@ require_once($CFG->dirroot . '/backup/util/interfaces/checksumable.class.php');
require_once("$CFG->dirroot/backup/backup.class.php");
/**
- * Unit tests for backup cron helper
+ * Unit tests for backups cron helper.
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2012 Frédéric Massart
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_cron_helper_testcase extends advanced_testcase {
+class cronhelper_test extends \advanced_testcase {
/**
* Test {@link backup_cron_automated_helper::calculate_next_automated_backup}.
*/
@@ -349,7 +359,7 @@ class backup_cron_helper_testcase extends advanced_testcase {
];
$event = \core\event\course_backup_created::create([
'objectid' => $course->id,
- 'context' => context_course::instance($course->id),
+ 'context' => \context_course::instance($course->id),
'other' => $otherarray
]);
$event->trigger();
@@ -380,13 +390,13 @@ class backup_cron_helper_testcase extends advanced_testcase {
$course4 = $this->getDataGenerator()->create_course(array('timecreated' => 1552179600));
// Create backup course records for the courses that need them.
- $backupcourse3 = new stdClass;
+ $backupcourse3 = new \stdClass;
$backupcourse3->courseid = $course3->id;
$backupcourse3->laststatus = testable_backup_cron_automated_helper::BACKUP_STATUS_OK;
$backupcourse3->nextstarttime = 1554858160;
$DB->insert_record('backup_courses', $backupcourse3);
- $backupcourse4 = new stdClass;
+ $backupcourse4 = new \stdClass;
$backupcourse4->courseid = $course4->id;
$backupcourse4->laststatus = testable_backup_cron_automated_helper::BACKUP_STATUS_OK;
$backupcourse4->nextstarttime = 1554858160;
diff --git a/backup/util/helper/tests/decode_test.php b/backup/util/helper/tests/decode_test.php
index b55178a5990..772c0ec2256 100644
--- a/backup/util/helper/tests/decode_test.php
+++ b/backup/util/helper/tests/decode_test.php
@@ -16,11 +16,16 @@
/**
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use restore_decode_rule;
+use restore_decode_rule_exception;
+
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff
@@ -29,9 +34,14 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
/**
- * restore_decode tests (both rule and content)
+ * Restore_decode tests (both rule and content)
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_restore_decode_testcase extends basic_testcase {
+class decode_test extends \basic_testcase {
/**
* test restore_decode_rule class
@@ -42,7 +52,7 @@ class backup_restore_decode_testcase extends basic_testcase {
try {
$dr = new restore_decode_rule('28 HJH', '/index.php', array());
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof restore_decode_rule_exception);
$this->assertEquals($e->errorcode, 'decode_rule_incorrect_name');
$this->assertEquals($e->a, '28 HJH');
@@ -51,7 +61,7 @@ class backup_restore_decode_testcase extends basic_testcase {
try {
$dr = new restore_decode_rule('HJHJhH', '/index.php', array());
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof restore_decode_rule_exception);
$this->assertEquals($e->errorcode, 'decode_rule_incorrect_name');
$this->assertEquals($e->a, 'HJHJhH');
@@ -60,7 +70,7 @@ class backup_restore_decode_testcase extends basic_testcase {
try {
$dr = new restore_decode_rule('', '/index.php', array());
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof restore_decode_rule_exception);
$this->assertEquals($e->errorcode, 'decode_rule_incorrect_name');
$this->assertEquals($e->a, '');
@@ -69,7 +79,7 @@ class backup_restore_decode_testcase extends basic_testcase {
try {
$dr = new restore_decode_rule('TESTRULE', 'index.php', array());
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof restore_decode_rule_exception);
$this->assertEquals($e->errorcode, 'decode_rule_incorrect_urltemplate');
$this->assertEquals($e->a, 'index.php');
@@ -78,7 +88,7 @@ class backup_restore_decode_testcase extends basic_testcase {
try {
$dr = new restore_decode_rule('TESTRULE', '', array());
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof restore_decode_rule_exception);
$this->assertEquals($e->errorcode, 'decode_rule_incorrect_urltemplate');
$this->assertEquals($e->a, '');
@@ -87,7 +97,7 @@ class backup_restore_decode_testcase extends basic_testcase {
try {
$dr = new restore_decode_rule('TESTRULE', '/course/view.php?id=$1&c=$2$3', array('test1', 'test2'));
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof restore_decode_rule_exception);
$this->assertEquals($e->errorcode, 'decode_rule_mappings_incorrect_count');
$this->assertEquals($e->a->placeholders, 3);
@@ -97,7 +107,7 @@ class backup_restore_decode_testcase extends basic_testcase {
try {
$dr = new restore_decode_rule('TESTRULE', '/course/view.php?id=$5&c=$4$1', array('test1', 'test2', 'test3'));
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof restore_decode_rule_exception);
$this->assertEquals($e->errorcode, 'decode_rule_nonconsecutive_placeholders');
$this->assertEquals($e->a, '1, 4, 5');
@@ -106,7 +116,7 @@ class backup_restore_decode_testcase extends basic_testcase {
try {
$dr = new restore_decode_rule('TESTRULE', '/course/view.php?id=$0&c=$3$2', array('test1', 'test2', 'test3'));
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof restore_decode_rule_exception);
$this->assertEquals($e->errorcode, 'decode_rule_nonconsecutive_placeholders');
$this->assertEquals($e->a, '0, 2, 3');
@@ -115,7 +125,7 @@ class backup_restore_decode_testcase extends basic_testcase {
try {
$dr = new restore_decode_rule('TESTRULE', '/course/view.php?id=$1&c=$3$3', array('test1', 'test2', 'test3'));
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof restore_decode_rule_exception);
$this->assertEquals($e->errorcode, 'decode_rule_duplicate_placeholders');
$this->assertEquals($e->a, '1, 3, 3');
diff --git a/backup/util/helper/tests/restore_log_rule_test.php b/backup/util/helper/tests/restore_log_rule_test.php
index 24d549bf134..58c0cfc6ffa 100644
--- a/backup/util/helper/tests/restore_log_rule_test.php
+++ b/backup/util/helper/tests/restore_log_rule_test.php
@@ -14,12 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * @package core_backup
- * @category test
- * @copyright 2015 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use restore_log_rule;
defined('MOODLE_INTERNAL') || die();
@@ -27,13 +24,20 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
-
-class backup_restore_log_rule_testcase extends basic_testcase {
+/**
+ * Test the backup and restore of logs using rules.
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2015 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class restore_log_rule_test extends \basic_testcase {
function test_process_keeps_log_unmodified() {
// Prepare a tiny log entry.
- $originallog = new stdClass();
+ $originallog = new \stdClass();
$originallog->url = 'original';
$originallog->info = 'original';
$log = clone($originallog);
@@ -55,7 +59,7 @@ class backup_restore_log_rule_testcase extends basic_testcase {
$expectation = '~Any \(string\) with (.*) like (.*) and (.*)\. (.*)\.~';
$lr = new restore_log_rule('this', 'doesnt', 'matter', 'here');
- $class = new ReflectionClass('restore_log_rule');
+ $class = new \ReflectionClass('restore_log_rule');
$method = $class->getMethod('extract_tokens');
$method->setAccessible(true);
diff --git a/backup/util/loggers/tests/logger_test.php b/backup/util/loggers/tests/logger_test.php
index f81d7a40dc8..bbcdc4fcedb 100644
--- a/backup/util/loggers/tests/logger_test.php
+++ b/backup/util/loggers/tests/logger_test.php
@@ -15,12 +15,24 @@
// along with Moodle. If not, see .
/**
+ * Logger tests (all).
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use backup;
+use base_logger;
+use base_logger_exception;
+use database_logger;
+use error_log_logger;
+use file_logger;
+use output_indented_logger;
+use output_text_logger;
+
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff
@@ -36,9 +48,14 @@ require_once($CFG->dirroot . '/backup/util/loggers/file_logger.class.php');
/**
- * logger tests (all)
+ * Logger tests (all).
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_logger_testcase extends basic_testcase {
+class logger_test extends \basic_testcase {
/**
* test base_logger class
@@ -65,10 +82,10 @@ class backup_logger_testcase extends basic_testcase {
try {
$lo1->set_next($lo1); //self
$this->assertTrue(false, 'base_logger_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_logger_exception);
$this->assertEquals($e->errorcode, 'logger_circular_reference');
- $this->assertTrue($e->a instanceof stdclass);
+ $this->assertTrue($e->a instanceof \stdClass);
$this->assertEquals($e->a->main, get_class($lo1));
$this->assertEquals($e->a->alreadyinchain, get_class($lo1));
}
@@ -81,10 +98,10 @@ class backup_logger_testcase extends basic_testcase {
try {
$lo3->set_next($lo1);
$this->assertTrue(false, 'base_logger_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_logger_exception);
$this->assertEquals($e->errorcode, 'logger_circular_reference');
- $this->assertTrue($e->a instanceof stdclass);
+ $this->assertTrue($e->a instanceof \stdClass);
$this->assertEquals($e->a->main, get_class($lo1));
$this->assertEquals($e->a->alreadyinchain, get_class($lo3));
}
@@ -241,7 +258,7 @@ class backup_logger_testcase extends basic_testcase {
@remove_dir(dirname($file));
// Recreate test dir
if (!check_dir_exists(dirname($file), true, true)) {
- throw new moodle_exception('error_creating_temp_dir', 'error', dirname($file));
+ throw new \moodle_exception('error_creating_temp_dir', 'error', dirname($file));
}
// Instantiate with date and level output, and also use the depth option
@@ -308,7 +325,7 @@ class backup_logger_testcase extends basic_testcase {
try {
$result = @$lo->process($message, backup::LOG_ERROR); // Try to write again
$this->assertTrue(false, 'base_logger_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_logger_exception);
$this->assertEquals($e->errorcode, 'error_writing_file');
}
@@ -317,7 +334,7 @@ class backup_logger_testcase extends basic_testcase {
try {
$lo = new file_logger(backup::LOG_WARNING, true, true, '');
$this->assertTrue(false, 'base_logger_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_logger_exception);
$this->assertEquals($e->errorcode, 'missing_fullpath_parameter');
}
@@ -327,7 +344,7 @@ class backup_logger_testcase extends basic_testcase {
try {
$lo = new file_logger(backup::LOG_WARNING, true, true, $file);
$this->assertTrue(false, 'base_logger_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_logger_exception);
$this->assertEquals($e->errorcode, 'file_not_writable');
$this->assertEquals($e->a, $file);
diff --git a/backup/util/settings/tests/settings_test.php b/backup/util/settings/tests/settings_test.php
index 1f512d563a9..92cda1134e5 100644
--- a/backup/util/settings/tests/settings_test.php
+++ b/backup/util/settings/tests/settings_test.php
@@ -15,12 +15,26 @@
// along with Moodle. If not, see .
/**
+ * Setting tests (all).
+ *
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use activity_backup_setting;
+use backup_setting;
+use backup_setting_exception;
+use base_setting;
+use base_setting_exception;
+use course_backup_setting;
+use section_backup_setting;
+use setting_dependency;
+use setting_dependency_disabledif_empty;
+
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff
@@ -36,11 +50,15 @@ require_once($CFG->dirroot . '/backup/util/settings/section/section_backup_setti
require_once($CFG->dirroot . '/backup/util/settings/course/course_backup_setting.class.php');
require_once($CFG->dirroot . '/backup/util/ui/backup_ui_setting.class.php');
-
/**
- * setting tests (all)
+ * Setting tests (all).
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backp_settings_testcase extends basic_testcase {
+class settings_test extends \basic_testcase {
/**
* test base_setting class
@@ -74,7 +92,7 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs = new mock_base_setting('test', 'one_wrong_type');
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_invalid_type');
}
@@ -83,7 +101,7 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs = new mock_base_setting('test', base_setting::IS_INTEGER, 99.99);
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_invalid_integer');
}
@@ -92,7 +110,7 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs = new mock_base_setting('test', base_setting::IS_FILENAME, '../../filename.txt');
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_invalid_filename');
}
@@ -101,7 +119,7 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs = new mock_base_setting('test', base_setting::IS_BOOLEAN, null, 'one_wrong_visibility');
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_invalid_visibility');
}
@@ -110,7 +128,7 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs = new mock_base_setting('test', base_setting::IS_BOOLEAN, null, null, 'one_wrong_status');
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_invalid_status');
}
@@ -119,14 +137,14 @@ class backp_settings_testcase extends basic_testcase {
// We need a custom error handler to catch the type hinting error
// that should return incorrect_object_passed
$bs = new mock_base_setting('test', base_setting::IS_BOOLEAN);
- set_error_handler('backup_setting_error_handler', E_RECOVERABLE_ERROR);
+ set_error_handler('\core_backup\backup_setting_error_handler', E_RECOVERABLE_ERROR);
try {
$bs->set_ui('one_wrong_ui_type', 'label', array(), array());
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'incorrect_object_passed');
- } catch (TypeError $e) {
+ } catch (\TypeError $e) {
// On PHP7+ we get a TypeError raised, lets check we've the right error.
$this->assertMatchesRegularExpression('/must be (of type|an instance of) backup_setting_ui/', $e->getMessage());
}
@@ -136,14 +154,14 @@ class backp_settings_testcase extends basic_testcase {
// We need a custom error handler to catch the type hinting error
// that should return incorrect_object_passed
$bs = new mock_base_setting('test', base_setting::IS_BOOLEAN);
- set_error_handler('backup_setting_error_handler', E_RECOVERABLE_ERROR);
+ set_error_handler('\core_backup\backup_setting_error_handler', E_RECOVERABLE_ERROR);
try {
$bs->set_ui(base_setting::UI_HTML_CHECKBOX, 'one/wrong/label', array(), array());
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'incorrect_object_passed');
- } catch (TypeError $e) {
+ } catch (\TypeError $e) {
// On PHP7+ we get a TypeError raised, lets check we've the right error.
$this->assertMatchesRegularExpression('/must be (of type|an instance of) backup_setting_ui/', $e->getMessage());
}
@@ -154,7 +172,7 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs->set_value(true);
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_locked_by_permission');
}
@@ -164,7 +182,7 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs->set_value(true);
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_locked_by_config');
}
@@ -176,7 +194,7 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs1->add_dependency($bs2);
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_already_added');
}
@@ -186,10 +204,10 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs1->add_dependency($bs1); // self
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_circular_reference');
- $this->assertTrue($e->a instanceof stdclass);
+ $this->assertTrue($e->a instanceof \stdClass);
$this->assertEquals($e->a->main, 'test1');
$this->assertEquals($e->a->alreadydependent, 'test1');
}
@@ -204,10 +222,10 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs4->add_dependency($bs1, null, array('value'=>0));
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_circular_reference');
- $this->assertTrue($e->a instanceof stdclass);
+ $this->assertTrue($e->a instanceof \stdClass);
$this->assertEquals($e->a->main, 'test1');
$this->assertEquals($e->a->alreadydependent, 'test4');
}
@@ -219,10 +237,10 @@ class backp_settings_testcase extends basic_testcase {
// $bs1 is already dependent on $bs2 so this should fail.
$bs2->register_dependency(new setting_dependency_disabledif_empty($bs2, $bs1));
$this->assertTrue(false, 'base_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_setting_exception);
$this->assertEquals($e->errorcode, 'setting_circular_reference');
- $this->assertTrue($e->a instanceof stdclass);
+ $this->assertTrue($e->a instanceof \stdClass);
$this->assertEquals($e->a->main, 'test1');
$this->assertEquals($e->a->alreadydependent, 'test2');
}
@@ -344,15 +362,15 @@ class backp_settings_testcase extends basic_testcase {
$this->assertEquals($bs->get_level(), 1);
// Instantiate backup setting class and try to add one non backup_setting dependency
- set_error_handler('backup_setting_error_handler', E_RECOVERABLE_ERROR);
+ set_error_handler('\core_backup\backup_setting_error_handler', E_RECOVERABLE_ERROR);
$bs = new mock_backup_setting('test', base_setting::IS_INTEGER, null);
try {
- $bs->add_dependency(new stdclass());
+ $bs->add_dependency(new \stdClass());
$this->assertTrue(false, 'backup_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof backup_setting_exception);
$this->assertEquals($e->errorcode, 'incorrect_object_passed');
- } catch (TypeError $e) {
+ } catch (\TypeError $e) {
// On PHP7+ we get a TypeError raised, lets check we've the right error.
$this->assertMatchesRegularExpression('/must be (an instance of|of type) base_setting/', $e->getMessage());
}
@@ -366,7 +384,7 @@ class backp_settings_testcase extends basic_testcase {
try {
$bs2->add_dependency($bs1);
$this->assertTrue(false, 'backup_setting_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof backup_setting_exception);
$this->assertEquals($e->errorcode, 'cannot_add_upper_level_dependency');
}
diff --git a/backup/util/structure/tests/baseatom_test.php b/backup/util/structure/tests/baseatom_test.php
index 0f829e8a64b..98070cd1b95 100644
--- a/backup/util/structure/tests/baseatom_test.php
+++ b/backup/util/structure/tests/baseatom_test.php
@@ -14,12 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * @package core_backup
- * @category phpunit
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use base_atom_content_exception;
+use base_atom_struct_exception;
+use mock_base_atom;
defined('MOODLE_INTERNAL') || die();
@@ -28,10 +27,16 @@ require_once(__DIR__.'/fixtures/structure_fixtures.php');
/**
- * Unit test case the base_atom class. Note: as it's abstract we are testing
- * mock_base_atom instantiable class instead
+ * Unit test case the base_atom class.
+ *
+ * Note: as it's abstract we are testing mock_base_atom instantiable class instead
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_base_atom_testcase extends basic_testcase {
+class baseatom_test extends \basic_testcase {
/**
* Correct base_atom_tests
@@ -80,7 +85,7 @@ class backup_base_atom_testcase extends basic_testcase {
try {
$instance = new mock_base_atom('');
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_atom_struct_exception);
}
@@ -88,7 +93,7 @@ class backup_base_atom_testcase extends basic_testcase {
try {
$instance = new mock_base_atom('TESTING ATOM');
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_atom_struct_exception);
}
@@ -96,13 +101,13 @@ class backup_base_atom_testcase extends basic_testcase {
try {
$instance = new mock_base_atom('TESTING-ATOM');
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_atom_struct_exception);
}
try {
$instance = new mock_base_atom('TESTING_ATOM_Á');
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_atom_struct_exception);
}
@@ -112,7 +117,7 @@ class backup_base_atom_testcase extends basic_testcase {
try {
$instance->set_value('test');
$this->fail("Expecting base_atom_content_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_atom_content_exception);
}
}
diff --git a/backup/util/structure/tests/baseattribute_test.php b/backup/util/structure/tests/baseattribute_test.php
index e32d7ab9812..e8248c0311e 100644
--- a/backup/util/structure/tests/baseattribute_test.php
+++ b/backup/util/structure/tests/baseattribute_test.php
@@ -14,12 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * @package core_backup
- * @category phpunit
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use mock_base_attribute;
defined('MOODLE_INTERNAL') || die();
@@ -28,10 +25,17 @@ require_once(__DIR__.'/fixtures/structure_fixtures.php');
/**
- * Unit test case the base_attribute class. Note: No really much to test here as attribute is 100%
+ * Unit test case the base_attribute class.
+ *
+ * Note: No really much to test here as attribute is 100%
* atom extension without new functionality (name/value)
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_base_attribute_testcase extends basic_testcase {
+class baseattribute_test extends \basic_testcase {
/**
* Correct base_attribute tests
diff --git a/backup/util/structure/tests/basefinalelement_test.php b/backup/util/structure/tests/basefinalelement_test.php
index f4156db7fd1..93ce518bce6 100644
--- a/backup/util/structure/tests/basefinalelement_test.php
+++ b/backup/util/structure/tests/basefinalelement_test.php
@@ -14,12 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * @package core_backup
- * @category phpunit
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use base_atom_struct_exception;
+use base_attribute;
+use base_element_attribute_exception;
+use mock_base_attribute;
+use mock_base_final_element;
defined('MOODLE_INTERNAL') || die();
@@ -28,9 +29,16 @@ require_once(__DIR__.'/fixtures/structure_fixtures.php');
/**
- * Unit test case the base_final_element class. Note: highly imbricated with base_nested_element class
+ * Unit test case the base_final_element class.
+ *
+ * Note: highly imbricated with base_nested_element class
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_base_final_element_testcase extends basic_testcase {
+class basefinalelement_test extends \basic_testcase {
/**
* Correct base_final_element tests
@@ -128,27 +136,27 @@ class backup_base_final_element_testcase extends basic_testcase {
try {
$instance = new mock_base_final_element('');
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_atom_struct_exception);
}
// Create instance with incorrect (object) attribute
try {
- $obj = new stdClass;
+ $obj = new \stdClass;
$obj->name = 'test_attr';
$instance = new mock_base_final_element('TEST', $obj);
$this->fail("Expecting base_element_attribute_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_attribute_exception);
}
// Create instance with array containing incorrect (object) attribute
try {
- $obj = new stdClass;
+ $obj = new \stdClass;
$obj->name = 'test_attr';
$instance = new mock_base_final_element('TEST', array($obj));
$this->fail("Expecting base_element_attribute_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_attribute_exception);
}
@@ -156,7 +164,7 @@ class backup_base_final_element_testcase extends basic_testcase {
try {
$instance = new mock_base_final_element('TEST', array('ATTR1', 'ATTR2', 'ATTR1'));
$this->fail("Expecting base_element_attribute_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_attribute_exception);
}
}
diff --git a/backup/util/structure/tests/basenestedelement_test.php b/backup/util/structure/tests/basenestedelement_test.php
index cdafd83e95d..50ce8b8003e 100644
--- a/backup/util/structure/tests/basenestedelement_test.php
+++ b/backup/util/structure/tests/basenestedelement_test.php
@@ -14,12 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * @package core_backup
- * @category phpunit
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use base_atom_struct_exception;
+use base_element_parent_exception;
+use base_element_struct_exception;
+use mock_base_attribute;
+use mock_base_final_element;
+use mock_base_nested_element;
defined('MOODLE_INTERNAL') || die();
@@ -28,9 +30,16 @@ require_once(__DIR__.'/fixtures/structure_fixtures.php');
/**
- * Unit test case the base_nested_element class. Note: highly imbricated with base_final_element class
+ * Unit test case the base_nested_element class.
+ *
+ * Note: highly imbricated with base_final_element class
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_base_nested_element_testcase extends basic_testcase {
+class basenestedelement_test extends \basic_testcase {
/**
* Correct creation tests (attributes and final elements)
@@ -179,27 +188,27 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$instance = new mock_base_nested_element('');
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_atom_struct_exception);
}
// Create instance with incorrect (object) final element
try {
- $obj = new stdClass;
+ $obj = new \stdClass;
$obj->name = 'test_attr';
$instance = new mock_base_nested_element('TEST', null, $obj);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
// Create instance with array containing incorrect (object) final element
try {
- $obj = new stdClass;
+ $obj = new \stdClass;
$obj->name = 'test_attr';
$instance = new mock_base_nested_element('TEST', null, array($obj));
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -207,7 +216,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$instance = new mock_base_nested_element('TEST', null, array('VAL1', 'VAL2', 'VAL1'));
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -216,7 +225,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$instance->get_value();
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -225,7 +234,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$instance->set_value('some_value');
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -234,7 +243,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$instance->clean_value('some_value');
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
}
@@ -304,17 +313,17 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$parent->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
// Add non base_element object child
$parent = new mock_base_nested_element('PARENT');
- $child = new stdClass();
+ $child = new \stdClass();
try {
$parent->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -324,7 +333,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$parent->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -336,7 +345,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$parent->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -348,7 +357,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$grandparent->add_child($parent);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -364,7 +373,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$grandparent->add_child($parent2);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -376,7 +385,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$parent2->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_parent_exception);
}
@@ -386,7 +395,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$nested->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
$this->assertEquals($e->errorcode, 'baseelementchildnameconflict');
$this->assertEquals($e->a, 'FINAL2');
diff --git a/backup/util/structure/tests/baseoptiogroup_test.php b/backup/util/structure/tests/baseoptigroup_test.php
similarity index 88%
rename from backup/util/structure/tests/baseoptiogroup_test.php
rename to backup/util/structure/tests/baseoptigroup_test.php
index 773a1563960..baa782ddb0b 100644
--- a/backup/util/structure/tests/baseoptiogroup_test.php
+++ b/backup/util/structure/tests/baseoptigroup_test.php
@@ -14,23 +14,31 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * @package core_backup
- * @category phpunit
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use base_atom_struct_exception;
+use base_element_struct_exception;
+use mock_base_attribute;
+use mock_base_final_element;
+use mock_base_nested_element;
+use mock_base_optigroup;
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff
require_once(__DIR__.'/fixtures/structure_fixtures.php');
-
/**
- * Unit test case the base_optigroup class. Note: highly imbricated with nested/final base elements
+ * Unit test case the base_optigroup class.
+ *
+ * Note: highly imbricated with nested/final base elements
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_base_optigroup_testcase extends basic_testcase {
+class baseoptigroup_test extends \basic_testcase {
/**
* Correct creation tests (s)
@@ -75,27 +83,27 @@ class backup_base_optigroup_testcase extends basic_testcase {
try {
$instance = new mock_base_nested_element('');
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_atom_struct_exception);
}
// Create instance with incorrect (object) final element
try {
- $obj = new stdClass;
+ $obj = new \stdClass;
$obj->name = 'test_attr';
$instance = new mock_base_nested_element('TEST', null, $obj);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
// Create instance with array containing incorrect (object) final element
try {
- $obj = new stdClass;
+ $obj = new \stdClass;
$obj->name = 'test_attr';
$instance = new mock_base_nested_element('TEST', null, array($obj));
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -103,7 +111,7 @@ class backup_base_optigroup_testcase extends basic_testcase {
try {
$instance = new mock_base_nested_element('TEST', null, array('VAL1', 'VAL2', 'VAL1'));
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -112,7 +120,7 @@ class backup_base_optigroup_testcase extends basic_testcase {
try {
$instance->get_value();
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -121,7 +129,7 @@ class backup_base_optigroup_testcase extends basic_testcase {
try {
$instance->set_value('some_value');
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -130,7 +138,7 @@ class backup_base_optigroup_testcase extends basic_testcase {
try {
$instance->clean_value('some_value');
$this->fail("Expecting base_element_struct_exception exception, none occurred");
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
}
diff --git a/backup/util/ui/tests/base_setting_ui_test.php b/backup/util/ui/tests/base_setting_ui_test.php
index 61960023ca1..801bd7c0f0c 100644
--- a/backup/util/ui/tests/base_setting_ui_test.php
+++ b/backup/util/ui/tests/base_setting_ui_test.php
@@ -14,13 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for base_setting_ui class.
- *
- * @package core_backup
- * @copyright 2021 Université Rennes 2 {@link https://www.univ-rennes2.fr}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_backup;
+
+use base_setting;
+use base_setting_ui;
defined('MOODLE_INTERNAL') || die();
@@ -31,10 +28,11 @@ require_once($CFG->dirroot.'/backup/util/settings/tests/settings_test.php');
/**
* Tests for base_setting_ui class.
*
+ * @package core_backup
* @copyright 2021 Université Rennes 2 {@link https://www.univ-rennes2.fr}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class base_setting_ui_test extends advanced_testcase {
+class base_setting_ui_test extends \advanced_testcase {
/**
* Tests set_label().
*
@@ -71,7 +69,7 @@ class base_setting_ui_test extends advanced_testcase {
$this->assertSame('label', $bsui->get_label());
// Should raise an exception when cleaning ends with 100% empty.
- $this->expectException(base_setting_ui_exception::class);
+ $this->expectException(\Exception::class);
$this->expectExceptionMessage('error/setting_invalid_ui_label');
$bsui->set_label('');
}
diff --git a/backup/util/ui/tests/ui_test.php b/backup/util/ui/tests/ui_test.php
index e33c7488564..7494909e903 100644
--- a/backup/util/ui/tests/ui_test.php
+++ b/backup/util/ui/tests/ui_test.php
@@ -14,19 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Contains user interface tests.
- *
- * @package core_backup
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-// Include all the needed stuff.
-global $CFG;
-//require_once($CFG->dirroot . '/backup/util/checks/backup_check.class.php');
+namespace core_backup;
/**
* ui tests (all)
@@ -35,7 +23,7 @@ global $CFG;
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class backup_ui_testcase extends basic_testcase {
+class ui_test extends \basic_testcase {
/**
* Test backup_ui class
diff --git a/backup/util/xml/output/tests/output_test.php b/backup/util/xml/output/tests/output_test.php
index 21c7cd85b06..9deba27581a 100644
--- a/backup/util/xml/output/tests/output_test.php
+++ b/backup/util/xml/output/tests/output_test.php
@@ -15,12 +15,21 @@
// along with Moodle. If not, see .
/**
+ * xml_output tests (base, memory and file).
+ *
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use file_xml_output;
+use memory_xml_output;
+use xml_output;
+use xml_output_exception;
+
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff
@@ -29,10 +38,15 @@ require_once($CFG->dirroot . '/backup/util/xml/output/xml_output.class.php');
require_once($CFG->dirroot . '/backup/util/xml/output/memory_xml_output.class.php');
require_once($CFG->dirroot . '/backup/util/xml/output/file_xml_output.class.php');
-/*
+/**
* xml_output tests (base, memory and file)
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class xml_output_test extends advanced_testcase {
+class output_test extends \advanced_testcase {
/*
* test memory_xml_output
@@ -47,7 +61,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->write('test');
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'xml_output_not_started');
}
@@ -57,7 +71,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->set_buffersize(8192);
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'xml_output_buffer_nosupport');
}
@@ -68,7 +82,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->set_buffersize(8192);
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'xml_output_already_started');
}
@@ -78,7 +92,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->stop();
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'xml_output_not_started');
}
@@ -88,7 +102,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->debug_info();
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'xml_output_not_stopped');
}
@@ -99,7 +113,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->start();
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'xml_output_already_started');
}
@@ -110,7 +124,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->debug_info();
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'xml_output_not_stopped');
}
@@ -122,7 +136,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->stop();
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'xml_output_not_started');
}
@@ -134,7 +148,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->start();
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'xml_output_already_stopped');
}
@@ -145,7 +159,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->get_allcontents();
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'xml_output_not_stopped');
}
@@ -220,7 +234,7 @@ class xml_output_test extends advanced_testcase {
@remove_dir(dirname($file));
// Recreate test dir
if (!check_dir_exists(dirname($file), true, true)) {
- throw new moodle_exception('error_creating_temp_dir', 'error', dirname($file));
+ throw new \moodle_exception('error_creating_temp_dir', 'error', dirname($file));
}
// Instantiate xml_output
@@ -233,7 +247,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->start();
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'directory_not_exists');
}
@@ -245,7 +259,7 @@ class xml_output_test extends advanced_testcase {
try {
$xo->start();
$this->assertTrue(false, 'xml_output_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_output_exception);
$this->assertEquals($e->errorcode, 'file_already_exists');
}
diff --git a/backup/util/xml/parser/tests/parser_test.php b/backup/util/xml/parser/tests/parser_test.php
index 7f9ea28b874..06acf90c5f8 100644
--- a/backup/util/xml/parser/tests/parser_test.php
+++ b/backup/util/xml/parser/tests/parser_test.php
@@ -15,12 +15,22 @@
// along with Moodle. If not, see .
/**
+ * Test progressive_parser and progressive_parser_processor tests.
+ *
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use grouped_parser_processor;
+use progressive_parser;
+use progressive_parser_exception;
+use progressive_parser_processor;
+use simplified_parser_processor;
+
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff
@@ -30,10 +40,15 @@ require_once($CFG->dirroot . '/backup/util/xml/parser/processors/progressive_par
require_once($CFG->dirroot . '/backup/util/xml/parser/processors/simplified_parser_processor.class.php');
require_once($CFG->dirroot . '/backup/util/xml/parser/processors/grouped_parser_processor.class.php');
-/*
- * progressive_parser and progressive_parser_processor tests
+/**
+ * Test progressive_parser and progressive_parser_processor tests.
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class progressive_parser_test extends advanced_testcase {
+class parser_test extends \advanced_testcase {
/*
* test progressive_parser public methods
@@ -50,7 +65,7 @@ class progressive_parser_test extends advanced_testcase {
try {
$pp->process();
$this->assertTrue(false);
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof progressive_parser_exception);
$this->assertEquals($e->errorcode, 'undefined_parser_processor');
}
@@ -62,16 +77,16 @@ class progressive_parser_test extends advanced_testcase {
try {
$pp->process();
$this->assertTrue(false);
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof progressive_parser_exception);
$this->assertEquals($e->errorcode, 'undefined_xml_to_parse');
}
// Assign *invalid* processor to parser
try {
- $pp->set_processor(new stdClass());
+ $pp->set_processor(new \stdClass());
$this->assertTrue(false);
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof progressive_parser_exception);
$this->assertEquals($e->errorcode, 'invalid_parser_processor');
}
@@ -87,7 +102,7 @@ class progressive_parser_test extends advanced_testcase {
try {
$pp->set_file($CFG->dirroot . '/backup/util/xml/parser/tests/fixtures/test0.xml');
$this->assertTrue(false);
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof progressive_parser_exception);
$this->assertEquals($e->errorcode, 'invalid_file_to_parse');
}
@@ -103,7 +118,7 @@ class progressive_parser_test extends advanced_testcase {
try {
$pp->set_contents('');
$this->assertTrue(false);
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof progressive_parser_exception);
$this->assertEquals($e->errorcode, 'invalid_contents_to_parse');
}
@@ -129,7 +144,7 @@ class progressive_parser_test extends advanced_testcase {
$pp->set_file($CFG->dirroot . '/backup/util/xml/parser/tests/fixtures/test2.xml');
try {
$pp->process();
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof progressive_parser_exception);
$this->assertEquals($e->errorcode, 'xml_parsing_error');
}
@@ -143,7 +158,7 @@ class progressive_parser_test extends advanced_testcase {
try { // Second process, will throw exception
$pp->process();
$this->assertTrue(false);
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof progressive_parser_exception);
$this->assertEquals($e->errorcode, 'progressive_parser_already_used');
}
diff --git a/backup/util/xml/tests/writer_test.php b/backup/util/xml/tests/writer_test.php
index bb65a5a0c71..2e5c4543551 100644
--- a/backup/util/xml/tests/writer_test.php
+++ b/backup/util/xml/tests/writer_test.php
@@ -15,12 +15,22 @@
// along with Moodle. If not, see .
/**
+ * Test xml_writer tests.
+ *
* @package core_backup
- * @category phpunit
+ * @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_backup;
+
+use memory_xml_output;
+use xml_contenttransformer;
+use xml_output;
+use xml_writer;
+use xml_writer_exception;
+
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff
@@ -31,9 +41,14 @@ require_once($CFG->dirroot . '/backup/util/xml/output/memory_xml_output.class.ph
require_once($CFG->dirroot . '/backup/util/xml/contenttransformer/xml_contenttransformer.class.php');
/**
- * xml_writer tests
+ * Test xml_writer tests.
+ *
+ * @package core_backup
+ * @category test
+ * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class xml_writer_testcase extends basic_testcase {
+class writer_test extends \basic_testcase {
/**
* test xml_writer public methods
@@ -48,25 +63,25 @@ class xml_writer_testcase extends basic_testcase {
try {
$xw = new mock_xml_writer(null);
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'invalid_xml_output');
}
// Instantiate xml_writer with wrong xml_output object
try {
- $xw = new mock_xml_writer(new stdclass());
+ $xw = new mock_xml_writer(new \stdClass());
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'invalid_xml_output');
}
// Instantiate xml_writer with wrong xml_contenttransformer object
try {
- $xw = new mock_xml_writer($xo, new stdclass());
+ $xw = new mock_xml_writer($xo, new \stdClass());
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'invalid_xml_contenttransformer');
}
@@ -77,7 +92,7 @@ class xml_writer_testcase extends basic_testcase {
try {
$xw->start();
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'xml_writer_already_started');
}
@@ -90,7 +105,7 @@ class xml_writer_testcase extends basic_testcase {
try {
$xw->stop();
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'xml_writer_already_stopped');
}
@@ -101,7 +116,7 @@ class xml_writer_testcase extends basic_testcase {
try {
$xw->stop();
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'xml_writer_not_started');
}
@@ -114,7 +129,7 @@ class xml_writer_testcase extends basic_testcase {
try {
$xw->start();
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'xml_writer_already_stopped');
}
@@ -126,14 +141,14 @@ class xml_writer_testcase extends basic_testcase {
try {
$xw->set_nonamespace_schema('http://moodle.org');
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'xml_writer_already_started');
}
try {
$xw->set_prologue('sweet prologue');
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'xml_writer_already_started');
}
@@ -172,7 +187,7 @@ class xml_writer_testcase extends basic_testcase {
try {
$xw->end_tag('first');
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'xml_writer_end_tag_no_match');
}
@@ -184,7 +199,7 @@ class xml_writer_testcase extends basic_testcase {
try {
$xw->end_tag('first');
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'xml_writer_end_tag_no_match');
}
@@ -249,7 +264,7 @@ class xml_writer_testcase extends basic_testcase {
try {
$xw->stop();
$this->assertTrue(false, 'xml_writer_exception expected');
- } catch (exception $e) {
+ } catch (\Exception $e) {
$this->assertTrue($e instanceof xml_writer_exception);
$this->assertEquals($e->errorcode, 'xml_writer_open_tags_remaining');
}
diff --git a/blocks/myoverview/tests/myoverview_test.php b/blocks/myoverview/tests/myoverview_test.php
index eba4b29bc4a..506e28fa0b5 100644
--- a/blocks/myoverview/tests/myoverview_test.php
+++ b/blocks/myoverview/tests/myoverview_test.php
@@ -14,16 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Online users tests
- *
- * @package block_myoverview
- * @category test
- * @copyright 2019 Juan Leyva
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace block_myoverview;
/**
* Online users testcase
@@ -33,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2019 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class block_myoverview_testcase extends advanced_testcase {
+class myoverview_test extends \advanced_testcase {
/**
* Test getting block configuration
@@ -64,10 +55,10 @@ class block_myoverview_testcase extends advanced_testcase {
set_config('customfiltergrouping', $field->get('shortname'), 'block_myoverview');
$this->setUser($user);
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
if (!$currentpage = my_get_page($user->id, MY_PAGE_PRIVATE)) {
- throw new moodle_exception('mymoodlesetup');
+ throw new \moodle_exception('mymoodlesetup');
}
$PAGE->set_url('/my/index.php'); // Need this because some internal API calls require the $PAGE url to be set.
diff --git a/blocks/online_users/tests/online_users_test.php b/blocks/online_users/tests/online_users_test.php
index 9f56f5fc81d..2f653ca62a5 100644
--- a/blocks/online_users/tests/online_users_test.php
+++ b/blocks/online_users/tests/online_users_test.php
@@ -14,19 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Online users tests
- *
- * @package block_online_users
- * @category test
- * @copyright 2015 University of Nottingham
- * @author Barry Oosthuizen
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-use block_online_users\fetcher;
-
-defined('MOODLE_INTERNAL') || die();
+namespace block_online_users;
/**
* Online users testcase
@@ -37,7 +25,7 @@ defined('MOODLE_INTERNAL') || die();
* @author Barry Oosthuizen
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class block_online_users_testcase extends advanced_testcase {
+class online_users_test extends \advanced_testcase {
protected $data;
@@ -70,7 +58,7 @@ class block_online_users_testcase extends advanced_testcase {
$groupid = $this->data['group1']->id;
$now = time();
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
- $context = context_course::instance($this->data['course1']->id);
+ $context = \context_course::instance($this->data['course1']->id);
$courseid = $this->data['course1']->id;
$onlineusers = new fetcher($groupid, $now, $timetoshowusers, $context, false, $courseid);
@@ -110,7 +98,7 @@ class block_online_users_testcase extends advanced_testcase {
$currentgroup = null;
$now = time();
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
- $context = context_course::instance($this->data['course1']->id);
+ $context = \context_course::instance($this->data['course1']->id);
$courseid = $this->data['course1']->id;
$onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $context, false, $courseid);
@@ -140,7 +128,7 @@ class block_online_users_testcase extends advanced_testcase {
$currentgroup = null;
$now = time();
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
- $context = context_system::instance();
+ $context = \context_system::instance();
$onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $context, true);
$usercount = $onlineusers->count_users();
@@ -160,7 +148,7 @@ class block_online_users_testcase extends advanced_testcase {
$groupid = $this->data['group1']->id;
$now = time();
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
- $context = context_course::instance($this->data['course1']->id);
+ $context = \context_course::instance($this->data['course1']->id);
$courseid = $this->data['course1']->id;
$user1 = $this->data['user1'];
$user2 = $this->data['user2'];
@@ -215,7 +203,7 @@ class block_online_users_testcase extends advanced_testcase {
$currentgroup = null;
$now = time();
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
- $context = context_course::instance($this->data['course1']->id);
+ $context = \context_course::instance($this->data['course1']->id);
$courseid = $this->data['course1']->id;
$user1 = $this->data['user1'];
$user2 = $this->data['user2'];
@@ -271,7 +259,7 @@ class block_online_users_testcase extends advanced_testcase {
$currentgroup = null;
$now = time();
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
- $context = context_system::instance();
+ $context = \context_system::instance();
$user1 = $this->data['user1'];
$user2 = $this->data['user2'];
// Set user2 as logged user.
diff --git a/blocks/rss_client/tests/cron_test.php b/blocks/rss_client/tests/cron_test.php
index fdead2892c9..9bcf0894bba 100644
--- a/blocks/rss_client/tests/cron_test.php
+++ b/blocks/rss_client/tests/cron_test.php
@@ -14,27 +14,21 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * PHPunit tests for rss client cron.
- *
- * @package block_rss_client
- * @copyright 2015 University of Nottingham
- * @author Neill Magill
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace block_rss_client;
+
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/../../moodleblock.class.php');
require_once(__DIR__ . '/../block_rss_client.php');
/**
- * Class for the PHPunit tests for rss client cron.
+ * PHPunit tests for rss client cron.
*
* @package block_rss_client
* @copyright 2015 Universit of Nottingham
* @author Neill Magill
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class block_rss_client_cron_testcase extends advanced_testcase {
+class cron_test extends \advanced_testcase {
/**
* Test that when a record has a skipuntil time that is greater
* than the current time the attempt is skipped.
diff --git a/blocks/tag_youtube/tests/block_tag_youtube_test.php b/blocks/tag_youtube/tests/block_tag_youtube_test.php
index 6434c445e4a..deae56cfbdc 100644
--- a/blocks/tag_youtube/tests/block_tag_youtube_test.php
+++ b/blocks/tag_youtube/tests/block_tag_youtube_test.php
@@ -14,16 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Block Tag Youtube tests
- *
- * @package block_tag_youtube
- * @category test
- * @copyright 2015 Jun Pataleta
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace block_tag_youtube;
/**
* Block Tag Youtube test class.
@@ -33,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2015 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_block_tag_youtube_testcase extends advanced_testcase {
+class block_tag_youtube_test extends \advanced_testcase {
/**
* Testing the tag youtube block's initial state after a new installation.
diff --git a/cache/tests/administration_helper_test.php b/cache/tests/administration_helper_test.php
index 39418717000..22c446b4035 100644
--- a/cache/tests/administration_helper_test.php
+++ b/cache/tests/administration_helper_test.php
@@ -14,17 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * PHPunit tests for the cache API and in particular things in locallib.php
- *
- * This file is part of Moodle's cache API, affectionately called MUC.
- * It contains the components that are requried in order to use caching.
- *
- * @package core
- * @category cache
- * @copyright 2012 Sam Hemelryk
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_cache;
+
+use cache_config_testing;
+use cache_config_writer;
+use cache_factory;
+use cache_helper;
+use cache_store;
defined('MOODLE_INTERNAL') || die();
@@ -37,10 +33,12 @@ require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php');
/**
* PHPunit tests for the cache API and in particular the core_cache\administration_helper
*
+ * @package core_cache
+ * @category test
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_cache_administration_helper_testcase extends advanced_testcase {
+class administration_helper_test extends \advanced_testcase {
/**
* Set things back to the default before each test.
@@ -73,7 +71,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
cache_store::MODE_REQUEST => array('default_request'),
)));
- $storesummaries = core_cache\administration_helper::get_store_instance_summaries();
+ $storesummaries = administration_helper::get_store_instance_summaries();
$this->assertIsArray($storesummaries);
$this->assertArrayHasKey('summariesstore', $storesummaries);
$summary = $storesummaries['summariesstore'];
@@ -99,7 +97,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
}));
$this->assertEquals($mappingcount, $summary['mappings']);
- $definitionsummaries = core_cache\administration_helper::get_definition_summaries();
+ $definitionsummaries = administration_helper::get_definition_summaries();
$this->assertIsArray($definitionsummaries);
$this->assertArrayHasKey('core/eventinvalidation', $definitionsummaries);
$summary = $definitionsummaries['core/eventinvalidation'];
@@ -119,7 +117,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
$this->assertIsArray($summary['mappings']);
$this->assertContains('summariesstore', $summary['mappings']);
- $pluginsummaries = core_cache\administration_helper::get_store_plugin_summaries();
+ $pluginsummaries = administration_helper::get_store_plugin_summaries();
$this->assertIsArray($pluginsummaries);
$this->assertArrayHasKey('file', $pluginsummaries);
$summary = $pluginsummaries['file'];
@@ -131,18 +129,18 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
$this->assertArrayHasKey('supports', $summary);
$this->assertArrayHasKey('canaddinstance', $summary);
- $locksummaries = core_cache\administration_helper::get_lock_summaries();
+ $locksummaries = administration_helper::get_lock_summaries();
$this->assertIsArray($locksummaries);
$this->assertTrue(count($locksummaries) > 0);
- $mappings = core_cache\administration_helper::get_default_mode_stores();
+ $mappings = administration_helper::get_default_mode_stores();
$this->assertIsArray($mappings);
$this->assertCount(3, $mappings);
$this->assertArrayHasKey(cache_store::MODE_APPLICATION, $mappings);
$this->assertIsArray($mappings[cache_store::MODE_APPLICATION]);
$this->assertContains('summariesstore', $mappings[cache_store::MODE_APPLICATION]);
- $potentials = core_cache\administration_helper::get_definition_store_options('core', 'eventinvalidation');
+ $potentials = administration_helper::get_definition_store_options('core', 'eventinvalidation');
$this->assertIsArray($potentials); // Currently used, suitable, default
$this->assertCount(3, $potentials);
$this->assertArrayHasKey('summariesstore', $potentials[0]);
@@ -160,7 +158,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
try {
$form = cache_factory::get_administration_display_helper()->get_add_store_form('somethingstupid');
$this->fail('You should not be able to create an add form for a store plugin that does not exist.');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertInstanceOf('coding_exception', $e, 'Needs to be: ' .get_class($e)." ::: ".$e->getMessage());
}
}
@@ -170,7 +168,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
*/
public function test_get_edit_store_form() {
// Always instantiate a new core display helper here.
- $administrationhelper = new core_cache\local\administration_display_helper;
+ $administrationhelper = new local\administration_display_helper;
$config = cache_config_writer::instance();
$this->assertTrue($config->add_store_instance('test_get_edit_store_form', 'file'));
@@ -180,14 +178,14 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
try {
$form = $administrationhelper->get_edit_store_form('somethingstupid', 'moron');
$this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
try {
$form = $administrationhelper->get_edit_store_form('file', 'blisters');
$this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
}
@@ -216,7 +214,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
try {
cache_helper::hash_key('test/test', $definition);
$this->fail('Invalid key was allowed, you should see this.');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('test/test', $e->debuginfo);
}
diff --git a/cache/tests/config_writer_test.php b/cache/tests/config_writer_test.php
index a88aa10b7c3..e0f28649eb8 100644
--- a/cache/tests/config_writer_test.php
+++ b/cache/tests/config_writer_test.php
@@ -14,17 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * PHPunit tests for the cache API and in particular things in locallib.php
- *
- * This file is part of Moodle's cache API, affectionately called MUC.
- * It contains the components that are requried in order to use caching.
- *
- * @package core
- * @category cache
- * @copyright 2012 Sam Hemelryk
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_cache;
+
+use cache_config_testing;
+use cache_config_writer;
+use cache_factory;
+use cache_store;
defined('MOODLE_INTERNAL') || die();
@@ -36,10 +31,12 @@ require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php');
/**
* PHPunit tests for the cache API and in particular the cache config writer.
*
+ * @package core_cache
+ * @category test
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_cache_config_writer_testcase extends advanced_testcase {
+class config_writer_test extends \advanced_testcase {
/**
* Set things back to the default before each test.
@@ -216,14 +213,14 @@ class core_cache_config_writer_testcase extends advanced_testcase {
try {
$config->delete_store_instance('default_application');
$this->fail('Default store deleted. This should not be possible!');
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertInstanceOf('cache_exception', $e);
}
try {
$config->delete_store_instance('some_crazy_store');
$this->fail('You should not be able to delete a store that does not exist.');
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertInstanceOf('cache_exception', $e);
}
@@ -231,7 +228,7 @@ class core_cache_config_writer_testcase extends advanced_testcase {
// Try with a plugin that does not exist.
$config->add_store_instance('storeconfigtest', 'shallowfail', array('test' => 'a', 'one' => 'two'));
$this->fail('You should not be able to add an instance of a store that does not exist.');
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertInstanceOf('cache_exception', $e);
}
}
@@ -276,14 +273,14 @@ class core_cache_config_writer_testcase extends advanced_testcase {
try {
$config->set_definition_mappings('phpunit/testdefinition', array('something that does not exist'));
$this->fail('You should not be able to set a mapping for a store that does not exist.');
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
try {
$config->set_definition_mappings('something/crazy', array('setdefinitiontest'));
$this->fail('You should not be able to set a mapping for a definition that does not exist.');
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
}
diff --git a/calendar/tests/action_event_test.php b/calendar/tests/action_event_test.php
index 27aa5a26e73..c17a524375f 100644
--- a/calendar/tests/action_event_test.php
+++ b/calendar/tests/action_event_test.php
@@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
+namespace core_calendar;
use core_calendar\local\event\entities\action_event;
use core_calendar\local\event\value_objects\action;
@@ -31,13 +31,17 @@ use core_calendar\local\event\value_objects\event_times;
use core_calendar\local\event\entities\event_collection_interface;
use core_calendar\local\event\entities\event_interface;
+defined('MOODLE_INTERNAL') || die;
+
/**
* Action event testcase.
*
+ * @package core_calendar
+ * @category test
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_action_event_testcase extends advanced_testcase {
+class action_event_test extends \advanced_testcase {
/**
* Test event class getters.
*
@@ -67,7 +71,7 @@ class core_calendar_action_event_testcase extends advanced_testcase {
'event' => new core_calendar_action_event_test_event(),
'action' => new action(
'action 1',
- new moodle_url('http://example.com'),
+ new \moodle_url('http://example.com'),
2,
true
)
@@ -78,7 +82,7 @@ class core_calendar_action_event_testcase extends advanced_testcase {
'event' => new core_calendar_action_event_test_event(),
'action' => new action(
'action 2',
- new moodle_url('http://example.com'),
+ new \moodle_url('http://example.com'),
5,
false
)
diff --git a/calendar/tests/action_factory_test.php b/calendar/tests/action_factory_test.php
index d58a4775b94..e6e1507673d 100644
--- a/calendar/tests/action_factory_test.php
+++ b/calendar/tests/action_factory_test.php
@@ -14,26 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Action factory test.
- *
- * @package core_calendar
- * @copyright 2017 Cameron Ball
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_calendar;
-defined('MOODLE_INTERNAL') || die();
-
-use core_calendar\action_factory;
use core_calendar\local\event\entities\action_interface;
/**
* Action factory testcase.
*
+ * @package core_calendar
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_action_factory_test extends advanced_testcase {
+class action_factory_test extends \advanced_testcase {
/**
* Test action factory.
*/
diff --git a/calendar/tests/action_test.php b/calendar/tests/action_test.php
index cc4dd6a3ccd..efad0b55721 100644
--- a/calendar/tests/action_test.php
+++ b/calendar/tests/action_test.php
@@ -14,25 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Action tests.
- *
- * @package core_calendar
- * @copyright 2017 Cameron Ball
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_calendar;
use core_calendar\local\event\value_objects\action;
/**
* Action testcase.
*
+ * @package core_calendar
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_action_testcase extends advanced_testcase {
+class action_test extends \advanced_testcase {
/**
* Test action class getters.
*
@@ -64,7 +57,7 @@ class core_calendar_action_testcase extends advanced_testcase {
'Dataset 1' => [
'constructorparams' => [
'name' => 'Hello',
- 'url' => new moodle_url('http://example.com'),
+ 'url' => new \moodle_url('http://example.com'),
'item_count' => 1,
'actionable' => true
]
@@ -72,7 +65,7 @@ class core_calendar_action_testcase extends advanced_testcase {
'Dataset 2' => [
'constructorparams' => [
'name' => 'Goodbye',
- 'url' => new moodle_url('http://example.com'),
+ 'url' => new \moodle_url('http://example.com'),
'item_count' => 2,
'actionable' => false
]
diff --git a/calendar/tests/calendar_event_exporter_test.php b/calendar/tests/calendar_event_exporter_test.php
index e974ae8024d..05530921646 100644
--- a/calendar/tests/calendar_event_exporter_test.php
+++ b/calendar/tests/calendar_event_exporter_test.php
@@ -14,29 +14,22 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Calendar event exporter tests tests.
- *
- * @package core_calendar
- * @copyright 2017 Ryan Wyllie
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_calendar;
use core_calendar\external\calendar_event_exporter;
use core_calendar\local\event\container;
-use core_calendar\type_factory;
+defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/helpers.php');
/**
* Calendar event exporter testcase.
*
+ * @package core_calendar
* @copyright 2017 Ryan Wyllie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_event_exporter_testcase extends advanced_testcase {
+class calendar_event_exporter_test extends \advanced_testcase {
/**
* Data provider for the timestamp min limit test case to confirm
* that the minimum time limit is set correctly on the boundary cases.
@@ -46,7 +39,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
$todaymidnight = usergetmidnight($now);
$tomorrowmidnight = $todaymidnight + DAYSECS;
$eightam = $todaymidnight + (60 * 60 * 8);
- $starttime = (new DateTime())->setTimestamp($eightam);
+ $starttime = (new \DateTime())->setTimestamp($eightam);
return [
'before min' => [
@@ -80,12 +73,12 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
* @dataProvider get_timestamp_min_limit_test_cases()
*/
public function test_get_timestamp_min_limit($starttime, $min, $expected) {
- $class = \core_calendar\external\calendar_event_exporter::class;
+ $class = calendar_event_exporter::class;
$mock = $this->getMockBuilder($class)
->disableOriginalConstructor()
->onlyMethods([])
->getMock();
- $reflector = new ReflectionClass($class);
+ $reflector = new \ReflectionClass($class);
$method = $reflector->getMethod('get_timestamp_min_limit');
$method->setAccessible(true);
@@ -103,7 +96,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
$todaymidnight = usergetmidnight($now);
$yesterdaymidnight = $todaymidnight - DAYSECS;
$eightam = $todaymidnight + (60 * 60 * 8);
- $starttime = (new DateTime())->setTimestamp($eightam);
+ $starttime = (new \DateTime())->setTimestamp($eightam);
return [
'before max' => [
@@ -137,12 +130,12 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
* @dataProvider get_timestamp_max_limit_test_cases()
*/
public function test_get_timestamp_max_limit($starttime, $max, $expected) {
- $class = \core_calendar\external\calendar_event_exporter::class;
+ $class = calendar_event_exporter::class;
$mock = $this->getMockBuilder($class)
->disableOriginalConstructor()
->onlyMethods([])
->getMock();
- $reflector = new ReflectionClass($class);
+ $reflector = new \ReflectionClass($class);
$method = $reflector->getMethod('get_timestamp_max_limit');
$method->setAccessible(true);
@@ -163,7 +156,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$course = $generator->create_course();
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$now = time();
$mapper = container::get_event_mapper();
$legacyevent = create_event([
@@ -177,7 +170,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
'context' => $context,
'course' => $course,
'moduleinstance' => null,
- 'daylink' => new moodle_url(''),
+ 'daylink' => new \moodle_url(''),
'type' => type_factory::get_calendar_instance(),
'today' => $now
]);
@@ -202,7 +195,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
$this->setAdminUser();
$generator = $this->getDataGenerator();
$user = $generator->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$now = time();
$mapper = container::get_event_mapper();
$legacyevent = create_event([
@@ -216,7 +209,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
'context' => $context,
'course' => null,
'moduleinstance' => null,
- 'daylink' => new moodle_url(''),
+ 'daylink' => new \moodle_url(''),
'type' => type_factory::get_calendar_instance(),
'today' => $now
]);
@@ -243,7 +236,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
$rawshortname = 'Shortname link';
$nolinkshortname = strip_links($rawshortname);
$course = $generator->create_course(['shortname' => $rawshortname]);
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
$now = time();
$mapper = container::get_event_mapper();
$renderer = $PAGE->get_renderer('core_calendar');
@@ -258,7 +251,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
'context' => $coursecontext,
'course' => $course,
'moduleinstance' => null,
- 'daylink' => new moodle_url(''),
+ 'daylink' => new \moodle_url(''),
'type' => type_factory::get_calendar_instance(),
'today' => $now
]);
@@ -281,7 +274,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
$rawshortname = 'Shortname link';
$nolinkshortname = strip_links($rawshortname);
$course = $generator->create_course(['shortname' => $rawshortname]);
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
$now = time();
$mapper = container::get_event_mapper();
$renderer = $PAGE->get_renderer('core_calendar');
@@ -296,7 +289,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
'context' => $coursecontext,
'course' => $course,
'moduleinstance' => null,
- 'daylink' => new moodle_url(''),
+ 'daylink' => new \moodle_url(''),
'type' => type_factory::get_calendar_instance(),
'today' => $now
]);
diff --git a/calendar/tests/calendar_information_test.php b/calendar/tests/calendar_information_test.php
index dccdda48798..ac8761d9b8d 100644
--- a/calendar/tests/calendar_information_test.php
+++ b/calendar/tests/calendar_information_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for calendar_information.
- *
- * @package core_calendar
- * @copyright 2017 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_calendar;
defined('MOODLE_INTERNAL') || die();
@@ -33,7 +27,7 @@ require_once(__DIR__ . '/helpers.php');
* @copyright 2017 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class calendar_information_testcase extends advanced_testcase {
+class calendar_information_test extends \advanced_testcase {
/**
* Helper to mock a course and category structure.
diff --git a/calendar/tests/calendartype_test.php b/calendar/tests/calendartype_test.php
index 4e6e5dfc08c..57d5038a2f8 100644
--- a/calendar/tests/calendartype_test.php
+++ b/calendar/tests/calendartype_test.php
@@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_calendar;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -45,7 +47,7 @@ require_once($CFG->dirroot . '/user/profile/definelib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.6
*/
-class core_calendar_type_testcase extends advanced_testcase {
+class calendartype_test extends \advanced_testcase {
/** @var MoodleQuickForm Keeps reference of dummy form object */
private $mform;
@@ -284,7 +286,7 @@ class core_calendar_type_testcase extends advanced_testcase {
$submissiondata = $form->get_data();
// On the user profile field page after get_data, the function define_save is called
// in the field base class, which then calls the field's function define_save_preprocess.
- $field = new profile_define_datetime();
+ $field = new \profile_define_datetime();
$submissiondata = $field->define_save_preprocess($submissiondata);
// Create an array we want to compare with the date passed.
@@ -309,7 +311,7 @@ class core_calendar_type_testcase extends advanced_testcase {
/**
* Form object to be used in test case.
*/
-class temp_form_calendartype extends moodleform {
+class temp_form_calendartype extends \moodleform {
/**
* Form definition.
*/
diff --git a/calendar/tests/cm_info_proxy_test.php b/calendar/tests/cm_info_proxy_test.php
index 95aba86cb79..fcab933fae7 100644
--- a/calendar/tests/cm_info_proxy_test.php
+++ b/calendar/tests/cm_info_proxy_test.php
@@ -14,25 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * cm_info_proxy tests.
- *
- * @package core_calendar
- * @copyright 2017 Cameron Ball
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_calendar;
use core_calendar\local\event\proxies\cm_info_proxy;
/**
* cm_info_proxy testcase.
*
+ * @package core_calendar
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_cm_info_proxy_testcase extends advanced_testcase {
+class cm_info_proxy_test extends \advanced_testcase {
/**
* Test creating cm_info_std_proxy, using getter and setter.
diff --git a/calendar/tests/container_test.php b/calendar/tests/container_test.php
index 7e00429f270..72b31d6e29c 100644
--- a/calendar/tests/container_test.php
+++ b/calendar/tests/container_test.php
@@ -14,19 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Event container tests.
- *
- * @package core_calendar
- * @copyright 2017 Cameron Ball
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-require_once($CFG->dirroot . '/calendar/lib.php');
+namespace core_calendar;
use core_calendar\local\event\entities\action_event;
use core_calendar\local\event\entities\event;
@@ -36,13 +24,20 @@ use core_calendar\local\event\factories\event_factory_interface;
use core_calendar\local\event\mappers\event_mapper;
use core_calendar\local\event\mappers\event_mapper_interface;
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+
+require_once($CFG->dirroot . '/calendar/lib.php');
+
/**
- * Core container testcase.
+ * Event container test..
*
+ * @package core_calendar
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_container_testcase extends advanced_testcase {
+class container_test extends \advanced_testcase {
/**
* Test setup.
@@ -435,10 +430,10 @@ class core_calendar_container_testcase extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$group = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
- foreach (core_component::get_plugin_list('mod') as $modname => $unused) {
+ foreach (\core_component::get_plugin_list('mod') as $modname => $unused) {
try {
$generator = $this->getDataGenerator()->get_plugin_generator('mod_'.$modname);
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
// Module generator is not implemented.
continue;
}
@@ -544,7 +539,7 @@ class core_calendar_container_testcase extends advanced_testcase {
$record->$name = $value;
}
- $event = new calendar_event($record);
+ $event = new \calendar_event($record);
return $event->create($record, false);
}
diff --git a/calendar/tests/coursecat_proxy_test.php b/calendar/tests/coursecat_proxy_test.php
index 346662970c9..669105cae29 100644
--- a/calendar/tests/coursecat_proxy_test.php
+++ b/calendar/tests/coursecat_proxy_test.php
@@ -14,25 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * coursecat_proxy tests.
- *
- * @package core_calendar
- * @copyright 2017 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_calendar;
use core_calendar\local\event\proxies\coursecat_proxy;
/**
* coursecat_proxy testcase.
*
+ * @package core_calendar
* @copyright 2017 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_coursecat_proxy_testcase extends advanced_testcase {
+class coursecat_proxy_test extends \advanced_testcase {
public function test_valid_coursecat() {
global $DB;
@@ -43,7 +36,7 @@ class core_calendar_coursecat_proxy_testcase extends advanced_testcase {
$category = $generator->create_category([
'name' => $name,
]);
- cache_helper::purge_by_event('changesincoursecat');
+ \cache_helper::purge_by_event('changesincoursecat');
// Fetch the proxy.
$startreads = $DB->perf_get_reads();
diff --git a/calendar/tests/event_description_test.php b/calendar/tests/event_description_test.php
index b7c0e40ea4a..fd5fdf1179c 100644
--- a/calendar/tests/event_description_test.php
+++ b/calendar/tests/event_description_test.php
@@ -14,25 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Event description tests.
- *
- * @package core_calendar
- * @copyright 2017 Cameron Ball
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_calendar;
use core_calendar\local\event\value_objects\event_description;
/**
* Action testcase.
*
+ * @package core_calendar
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_event_description_testcase extends advanced_testcase {
+class event_description_test extends \advanced_testcase {
/**
* Test event description class getters.
*
diff --git a/calendar/tests/event_factory_test.php b/calendar/tests/event_factory_test.php
index f1c8b44b974..044341ec99a 100644
--- a/calendar/tests/event_factory_test.php
+++ b/calendar/tests/event_factory_test.php
@@ -14,29 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Event factory test.
- *
- * @package core_calendar
- * @copyright 2017 Cameron Ball
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_calendar;
+
+use core_calendar\local\event\factories\event_factory;
+use core_calendar\local\event\entities\event_interface;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/calendar/lib.php');
-use core_calendar\local\event\factories\event_factory;
-use core_calendar\local\event\entities\event_interface;
-
/**
- * Event factory testcase.
+ * Event factory test.
*
+ * @package core_calendar
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_event_factory_testcase extends advanced_testcase {
+class event_factory_test extends \advanced_testcase {
/**
* Test event class getters.
*
@@ -479,7 +474,7 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
$record->$name = $value;
}
- $event = new calendar_event($record);
+ $event = new \calendar_event($record);
return $event->create($record, false);
}
}
diff --git a/calendar/tests/event_mapper_test.php b/calendar/tests/event_mapper_test.php
index e69456338b9..0428de004a4 100644
--- a/calendar/tests/event_mapper_test.php
+++ b/calendar/tests/event_mapper_test.php
@@ -22,10 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->dirroot . '/calendar/lib.php');
+namespace core_calendar;
use core_calendar\local\event\mappers\event_mapper;
use core_calendar\local\event\value_objects\action;
@@ -38,13 +35,19 @@ use core_calendar\local\event\entities\event_interface;
use core_calendar\local\event\entities\action_event_interface;
use core_calendar\local\event\proxies\proxy_interface;
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+require_once($CFG->dirroot . '/calendar/lib.php');
+
/**
- * Event mapper testcase.
+ * Event mapper test.
*
+ * @package core_calendar
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_event_mapper_testcase extends advanced_testcase {
+class event_mapper_test extends \advanced_testcase {
/**
* Test legacy event -> event.
*/
@@ -71,7 +74,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
new event_mapper_test_event_factory()
);
$legacyevent = $mapper->from_event_to_legacy_event($event);
- $this->assertInstanceOf(calendar_event::class, $legacyevent);
+ $this->assertInstanceOf(\calendar_event::class, $legacyevent);
}
/**
@@ -85,7 +88,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
$mapper = new event_mapper(
new event_mapper_test_event_factory()
);
- $obj = $mapper->from_event_to_stdclass($event);
+ $obj = $mapper->from_event_to_stdClass($event);
$this->assertInstanceOf(\stdClass::class, $obj);
$this->assertEquals($obj->name, $event->get_name());
$this->assertEquals($obj->eventtype, $event->get_type());
@@ -125,7 +128,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
);
$legacyevent = $mapper->from_event_to_legacy_event($event);
- $this->assertInstanceOf(calendar_event::class, $legacyevent);
+ $this->assertInstanceOf(\calendar_event::class, $legacyevent);
$this->assertEquals($legacyevent->actionname, 'test action');
$this->assertInstanceOf(\moodle_url::class, $legacyevent->actionurl);
$this->assertEquals($legacyevent->actionnum, 1729);
@@ -153,7 +156,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
$record->$name = $value;
}
- $event = new calendar_event($record);
+ $event = new \calendar_event($record);
return $event->create($record, false);
}
}
diff --git a/calendar/tests/event_times_test.php b/calendar/tests/event_times_test.php
index ee7e5e1e8d1..70fd9e22039 100644
--- a/calendar/tests/event_times_test.php
+++ b/calendar/tests/event_times_test.php
@@ -14,25 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Event times tests.
- *
- * @package core_calendar
- * @copyright 2017 Cameron Ball
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_calendar;
use core_calendar\local\event\value_objects\event_times;
/**
- * Event times testcase.
+ * Event times tests.
*
+ * @package core_calendar
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_event_times_testcase extends advanced_testcase {
+class event_times_test extends \advanced_testcase {
/**
* Test event times class getters.
*
diff --git a/calendar/tests/event_vault_test.php b/calendar/tests/event_vault_test.php
index 5d90f93b3d8..579e6461f3a 100644
--- a/calendar/tests/event_vault_test.php
+++ b/calendar/tests/event_vault_test.php
@@ -14,22 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This file contains the class that handles testing of the calendar event vault.
- *
- * @package core_calendar
- * @copyright 2017 Ryan Wyllie
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_calendar;
+
+use action_event_test_factory;
+use core_calendar\local\event\data_access\event_vault;
+use core_calendar\local\event\strategies\raw_event_retrieval_strategy;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/calendar/tests/helpers.php');
-use core_calendar\local\event\data_access\event_vault;
-use core_calendar\local\event\strategies\raw_event_retrieval_strategy;
-
/**
* This file contains the class that handles testing of the calendar event vault.
*
@@ -37,7 +32,7 @@ use core_calendar\local\event\strategies\raw_event_retrieval_strategy;
* @copyright 2017 Ryan Wyllie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_event_vault_testcase extends advanced_testcase {
+class event_vault_test extends \advanced_testcase {
/**
* Test that get_action_events_by_timesort returns events after the
@@ -517,7 +512,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
];
foreach ($events as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
$factory = new action_event_test_factory();
@@ -1174,7 +1169,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
];
foreach ($events as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
$factory = new action_event_test_factory();
diff --git a/calendar/tests/events_related_objects_cache_test.php b/calendar/tests/events_related_objects_cache_test.php
index 0238db8047e..91ed2a3ff48 100644
--- a/calendar/tests/events_related_objects_cache_test.php
+++ b/calendar/tests/events_related_objects_cache_test.php
@@ -14,21 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for the events_related_objects_cache.
- *
- * @package core_calendar
- * @copyright 2017 Ryan Wyllie
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_calendar;
+
+use core_calendar\external\events_related_objects_cache;
+use core_calendar\local\event\container;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/helpers.php');
-use \core_calendar\external\events_related_objects_cache;
-use \core_calendar\local\event\container;
-
/**
* Tests for the events_related_objects_cache.
*
@@ -36,7 +30,7 @@ use \core_calendar\local\event\container;
* @copyright 2017 Ryan Wyllie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_events_related_objects_cache_testcase extends advanced_testcase {
+class events_related_objects_cache_test extends \advanced_testcase {
/**
* Tests set up
diff --git a/calendar/tests/local_api_test.php b/calendar/tests/local_api_test.php
index 987de7b3915..ec840ee898a 100644
--- a/calendar/tests/local_api_test.php
+++ b/calendar/tests/local_api_test.php
@@ -14,20 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Contains the class containing unit tests for the calendar local API.
- *
- * @package core_calendar
- * @copyright 2017 Mark Nelson
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_calendar;
+
+use core_calendar\local\event\container;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/helpers.php');
-use \core_calendar\local\event\container;
-
/**
* Class contaning unit tests for the calendar local API.
*
@@ -35,7 +29,7 @@ use \core_calendar\local\event\container;
* @copyright 2017 Mark Nelson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_local_api_testcase extends advanced_testcase {
+class local_api_test extends \advanced_testcase {
/**
* Tests set up
@@ -694,7 +688,7 @@ class core_calendar_local_api_testcase extends advanced_testcase {
]
];
foreach ($events as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
$timestart = time() - 60;
$timeend = time() + 60;
@@ -820,7 +814,7 @@ class core_calendar_local_api_testcase extends advanced_testcase {
];
foreach ($events as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
$timestart = $now - 100;
@@ -896,7 +890,7 @@ class core_calendar_local_api_testcase extends advanced_testcase {
];
foreach ($repeatingevents as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
// Make sure repeating events are not filtered out.
@@ -913,9 +907,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$user = $generator->create_user();
$roleid = $generator->create_role();
$context = \context_system::instance();
- $originalstarttime = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
- $expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
+ $originalstarttime = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
+ $expected = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
$mapper = container::get_event_mapper();
$generator->role_assign($roleid, $user->id, $context->id);
@@ -948,9 +942,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$user = $generator->create_user();
$roleid = $generator->create_role();
$context = \context_system::instance();
- $originalstarttime = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
- $expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
+ $originalstarttime = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
+ $expected = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
$mapper = container::get_event_mapper();
$generator->role_assign($roleid, $user->id, $context->id);
@@ -985,9 +979,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
- $timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
- $expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
+ $timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
+ $expected = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
list($feedback, $event) = $this->create_feedback_activity_and_event(
[
'timeopen' => $timeopen->getTimestamp(),
@@ -1020,10 +1014,10 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
- $timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
- $timeclose = new DateTimeImmutable('2019-01-1T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
- $expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
+ $timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $timeclose = new \DateTimeImmutable('2019-01-1T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
+ $expected = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
list($feedback, $event) = $this->create_feedback_activity_and_event(
[
'timeopen' => $timeopen->getTimestamp(),
@@ -1057,9 +1051,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
- $timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
- $timeclose = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
+ $timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $timeclose = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
list($feedback, $event) = $this->create_feedback_activity_and_event(
[
'timeopen' => $timeopen->getTimestamp(),
@@ -1093,9 +1087,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
- $timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
- $timeclose = new DateTimeImmutable('2017-02-2T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
+ $timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $timeclose = new \DateTimeImmutable('2017-02-2T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
list($feedback, $event) = $this->create_feedback_activity_and_event(
[
'timeopen' => $timeopen->getTimestamp(),
@@ -1124,9 +1118,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
- $timeclose = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2016-02-2T10:00:00+08:00');
- $expected = new DateTimeImmutable('2016-02-2T15:00:00+08:00');
+ $timeclose = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2016-02-2T10:00:00+08:00');
+ $expected = new \DateTimeImmutable('2016-02-2T15:00:00+08:00');
list($feedback, $event) = $this->create_feedback_activity_and_event(
[
'timeopen' => 0,
@@ -1160,10 +1154,10 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
- $timeopen = new DateTimeImmutable('2016-01-1T15:00:00+08:00');
- $timeclose = new DateTimeImmutable('2019-01-1T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
- $expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
+ $timeopen = new \DateTimeImmutable('2016-01-1T15:00:00+08:00');
+ $timeclose = new \DateTimeImmutable('2019-01-1T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
+ $expected = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
list($feedback, $event) = $this->create_feedback_activity_and_event(
[
'timeopen' => $timeopen->getTimestamp(),
@@ -1197,10 +1191,10 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
- $timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
- $timeclose = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2017-01-1T10:00:00+08:00');
- $expected = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $timeclose = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2017-01-1T10:00:00+08:00');
+ $expected = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
list($feedback, $event) = $this->create_feedback_activity_and_event(
[
'timeopen' => $timeopen->getTimestamp(),
@@ -1234,9 +1228,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
- $timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
- $timeclose = new DateTimeImmutable('2017-02-2T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2016-02-2T10:00:00+08:00');
+ $timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $timeclose = new \DateTimeImmutable('2017-02-2T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2016-02-2T10:00:00+08:00');
list($feedback, $event) = $this->create_feedback_activity_and_event(
[
'timeopen' => $timeopen->getTimestamp(),
@@ -1268,8 +1262,8 @@ class core_calendar_local_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
$mapper = container::get_event_mapper();
- $timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
- $newstartdate = new DateTimeImmutable('2016-02-2T10:00:00+08:00');
+ $timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
+ $newstartdate = new \DateTimeImmutable('2016-02-2T10:00:00+08:00');
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$course = $generator->create_course();
diff --git a/calendar/tests/raw_event_retrieval_strategy_test.php b/calendar/tests/raw_event_retrieval_strategy_test.php
index 5bedcb15e74..235d68fe7f2 100644
--- a/calendar/tests/raw_event_retrieval_strategy_test.php
+++ b/calendar/tests/raw_event_retrieval_strategy_test.php
@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_calendar;
+
+use core_calendar\local\event\strategies\raw_event_retrieval_strategy;
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+require_once($CFG->dirroot . '/calendar/tests/helpers.php');
+
/**
* Raw event retrieval strategy tests.
*
@@ -21,21 +30,7 @@
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->dirroot . '/calendar/tests/helpers.php');
-
-use core_calendar\local\event\strategies\raw_event_retrieval_strategy;
-
-/**
- * Raw event retrieval strategy testcase.
- *
- * @copyright 2017 Cameron Ball
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testcase {
+class raw_event_retrieval_strategy_test extends \advanced_testcase {
/**
* Test retrieval strategy when module is disabled.
*/
@@ -82,7 +77,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
];
foreach ($events as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
// Get all events.
@@ -220,7 +215,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
];
foreach ($events as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
$groups = [$group1->id, $group2->id];
@@ -292,7 +287,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
];
foreach ($repeatingevents as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
// Make sure repeating events are not filtered out.
@@ -333,7 +328,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
];
foreach ($events as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
// Get all events.
@@ -394,7 +389,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
]
];
foreach ($events as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
$retrievalstrategy = new raw_event_retrieval_strategy();
@@ -433,7 +428,7 @@ class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testc
]
];
foreach ($events as $event) {
- calendar_event::create($event, false);
+ \calendar_event::create($event, false);
}
$retrievalstrategy = new raw_event_retrieval_strategy;
diff --git a/calendar/tests/repeat_event_collection_test.php b/calendar/tests/repeat_event_collection_test.php
index 0b50958267b..935eb2bf159 100644
--- a/calendar/tests/repeat_event_collection_test.php
+++ b/calendar/tests/repeat_event_collection_test.php
@@ -22,11 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-require_once($CFG->dirroot . '/calendar/lib.php');
+namespace core_calendar;
use core_calendar\local\event\entities\event;
use core_calendar\local\event\entities\repeat_event_collection;
@@ -36,13 +32,20 @@ use core_calendar\local\event\value_objects\event_description;
use core_calendar\local\event\value_objects\event_times;
use core_calendar\local\event\factories\event_factory_interface;
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+
+require_once($CFG->dirroot . '/calendar/lib.php');
+
/**
* Repeat event collection tests.
*
+ * @package core_calendar
* @copyright 2017 Ryan Wyllie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_repeat_event_collection_testcase extends advanced_testcase {
+class repeat_event_collection_test extends \advanced_testcase {
/**
* Test that the collection id is set to the parent id if the repeat id
* is falsey.
@@ -169,7 +172,7 @@ class core_calendar_repeat_event_collection_testcase extends advanced_testcase {
$record->$name = $value;
}
- $event = new calendar_event($record);
+ $event = new \calendar_event($record);
return $event->create($record, false);
}
}
diff --git a/calendar/tests/rrule_manager_test.php b/calendar/tests/rrule_manager_test.php
index 449a9fcbbb5..ed9a3c11994 100644
--- a/calendar/tests/rrule_manager_test.php
+++ b/calendar/tests/rrule_manager_test.php
@@ -14,22 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Defines test class to test manage rrule during ical imports.
- *
- * @package core_calendar
- * @category test
- * @copyright 2014 onwards Ankit Agarwal
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_calendar;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/calendar/lib.php');
-use core_calendar\rrule_manager;
-
/**
* Defines test class to test manage rrule during ical imports.
*
@@ -38,7 +29,7 @@ use core_calendar\rrule_manager;
* @copyright 2014 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_rrule_manager_testcase extends advanced_testcase {
+class rrule_manager_test extends \advanced_testcase {
/** @var calendar_event a dummy event */
protected $event;
@@ -53,13 +44,13 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Set our timezone based on the timezone in the RFC's samples (US/Eastern).
$tz = 'US/Eastern';
$this->setTimezone($tz);
- $timezone = new DateTimeZone($tz);
+ $timezone = new \DateTimeZone($tz);
// Create our event's DTSTART date based on RFC's samples (most commonly used in RFC is 1997-09-02 09:00:00 EDT).
- $time = DateTime::createFromFormat('Ymd\THis', '19970902T090000', $timezone);
+ $time = \DateTime::createFromFormat('Ymd\THis', '19970902T090000', $timezone);
$timestart = $time->getTimestamp();
$user = $this->getDataGenerator()->create_user();
- $sub = new stdClass();
+ $sub = new \stdClass();
$sub->url = '';
$sub->courseid = 0;
$sub->groupid = 0;
@@ -67,7 +58,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$sub->pollinterval = 0;
$subid = $DB->insert_record('event_subscriptions', $sub, true);
- $event = new stdClass();
+ $event = new \stdClass();
$event->name = 'Event name';
$event->description = '';
$event->timestart = $timestart;
@@ -78,7 +69,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$event->groupid = 0;
$event->courseid = 0;
$event->eventtype = 'user';
- $eventobj = calendar_event::create($event, false);
+ $eventobj = \calendar_event::create($event, false);
$DB->set_field('event', 'repeatid', $eventobj->id, array('id' => $eventobj->id));
$eventobj->repeatid = $eventobj->id;
$this->event = $eventobj;
@@ -130,7 +121,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
'bymonth' => [3, 4],
];
- $reflectionclass = new ReflectionClass($mang);
+ $reflectionclass = new \ReflectionClass($mang);
foreach ($props as $prop => $expectedval) {
$rcprop = $reflectionclass->getProperty($prop);
$rcprop->setAccessible(true);
@@ -454,11 +445,11 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Change the start date for forever events to 9am of the current date.
$this->change_event_startdate(date('Ymd\T090000'));
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $interval = new DateInterval('P300D');
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P10Y'));
+ $interval = new \DateInterval('P300D');
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P10Y'));
$until = $untildate->getTimestamp();
// Forever event. This should generate events for time() + 10 year period, every 300 days.
@@ -525,11 +516,11 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertTrue($result);
}
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
- $interval = new DateInterval('P3W');
+ $interval = new \DateInterval('P3W');
// Every 3 weeks on Monday, Wednesday for 2 times.
$rrule = 'FREQ=WEEKLY;INTERVAL=3;BYDAY=MO,WE;COUNT=2';
@@ -565,7 +556,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
global $DB;
// Set the next Monday as the starting date of this event.
- $startdate = new DateTime('next Monday');
+ $startdate = new \DateTime('next Monday');
// Change the start date of the parent event.
$startdate = $this->change_event_startdate($startdate->format('Ymd\T090000'));
@@ -576,13 +567,13 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$mang->parse_rrule();
$mang->create_events($this->event);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P10Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P10Y'));
$until = $untildate->getTimestamp();
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
- $interval = new DateInterval('P50W');
+ $interval = new \DateInterval('P50W');
// First instance of this set of recurring events.
$expecteddate = clone($startdate);
@@ -604,8 +595,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_monthly_events_with_count_bymonthday() {
global $DB;
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $interval = new DateInterval('P1M');
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $interval = new \DateInterval('P1M');
$rrule = "FREQ=MONTHLY;COUNT=3;BYMONTHDAY=2"; // This should generate 3 events in total.
$mang = new rrule_manager($rrule);
@@ -650,12 +641,12 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_monthly_events_with_until_bymonthday_multi() {
global $DB;
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
- $interval = new DateInterval('P2M');
+ $interval = new \DateInterval('P2M');
$untildate = clone($startdatetime);
- $untildate->add(new DateInterval('P10M10D'));
+ $untildate->add(new \DateInterval('P10M10D'));
$until = $untildate->format('Ymd\This\Z');
// This should generate 11 child event + 1 parent, since by then until bound would be hit.
@@ -675,7 +666,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
if (date('j', $record->timestart) == 2) {
// Go to the fifth day of this month.
- $expecteddate->add(new DateInterval('P3D'));
+ $expecteddate->add(new \DateInterval('P3D'));
} else {
// Reset date to the first day of the month.
$expecteddate->modify('first day of this month');
@@ -695,18 +686,18 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Change the start date for forever events to 9am of the 2nd day of the current month and year.
$this->change_event_startdate(date('Ym02\T090000'));
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
- $interval = new DateInterval('P12M');
+ $interval = new \DateInterval('P12M');
// Forever event. This should generate events over a 10-year period, on 2nd day of the month, every 12 months.
$rrule = "FREQ=MONTHLY;INTERVAL=12;BYMONTHDAY=2";
$mang = new rrule_manager($rrule);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$until = $untildate->getTimestamp();
$mang->parse_rrule();
@@ -736,11 +727,11 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_monthly_events_with_count_byday() {
global $DB;
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
- $interval = new DateInterval('P1M');
+ $interval = new \DateInterval('P1M');
$rrule = 'FREQ=MONTHLY;COUNT=3;BYDAY=1MO'; // This should generate 3 events in total, first monday of the month.
$mang = new rrule_manager($rrule);
@@ -770,12 +761,12 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
global $DB;
// This much seconds after the start of the day.
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
$untildate = clone($startdatetime);
- $untildate->add(new DateInterval('P10M1D'));
+ $untildate->add(new \DateInterval('P10M1D'));
$until = $untildate->format('Ymd\This\Z');
// This rule should generate 9 events in total from first Monday of October 1997 to first Monday of June 1998.
@@ -807,14 +798,14 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_monthly_events_with_until_byday_multi() {
global $DB;
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
- $interval = new DateInterval('P2M');
+ $interval = new \DateInterval('P2M');
$untildate = clone($startdatetime);
- $untildate->add(new DateInterval('P10M20D'));
+ $untildate->add(new \DateInterval('P10M20D'));
$until = $untildate->format('Ymd\This\Z');
// This should generate 11 events from 17 Sep 1997 to 15 Jul 1998.
@@ -852,25 +843,25 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Change the start date for forever events to 9am of the 2nd day of the current month and year.
$this->change_event_startdate(date('Ym02\T090000'));
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
- $interval = new DateInterval('P12M');
+ $interval = new \DateInterval('P12M');
// Forever event. This should generate events over a 10 year period, on 1st Monday of the month every 12 months.
$rrule = "FREQ=MONTHLY;INTERVAL=12;BYDAY=1MO";
$mang = new rrule_manager($rrule);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$until = $untildate->getTimestamp();
$mang->parse_rrule();
$mang->create_events($this->event);
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
- $expecteddate = new DateTime('first Monday of this month');
+ $expecteddate = new \DateTime('first Monday of this month');
// Move to the next interval's first Monday if the calculated start date is after this month's first Monday.
if ($expecteddate->getTimestamp() < $startdate->getTimestamp()) {
$expecteddate->add($interval);
@@ -895,11 +886,11 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_yearly_events() {
global $DB;
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
- $interval = new DateInterval('P1Y');
+ $interval = new \DateInterval('P1Y');
$rrule = "FREQ=YEARLY;COUNT=3;BYMONTH=9"; // This should generate 3 events in total.
$mang = new rrule_manager($rrule);
@@ -970,7 +961,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Create a yearly event on the specified month, until the time limit is hit.
$untildate = clone($startdatetime);
- $untildate->add(new DateInterval('P10Y20D'));
+ $untildate->add(new \DateInterval('P10Y20D'));
$until = $untildate->format('Ymd\THis\Z');
$rrule = "FREQ=YEARLY;BYMONTH=9;UNTIL=$until;BYDAY=1MO";
@@ -1003,7 +994,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$mang->create_events($this->event);
// 5 bi-yearly records every first Monday of September 1998 to first Monday of September 2007.
- $interval = new DateInterval('P2Y');
+ $interval = new \DateInterval('P2Y');
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
$this->assertCount(5, $records);
@@ -1033,16 +1024,16 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$rrule = "FREQ=YEARLY;BYMONTH=9;INTERVAL=2"; // Forever event.
$mang = new rrule_manager($rrule);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
$mang->parse_rrule();
$mang->create_events($this->event);
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
- $interval = new DateInterval('P2Y');
- $expecteddate = new DateTime(date('Y0902\T090000'));
+ $interval = new \DateInterval('P2Y');
+ $expecteddate = new \DateTime(date('Y0902\T090000'));
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -1069,15 +1060,15 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
- $interval = new DateInterval('P2Y');
+ $interval = new \DateInterval('P2Y');
// First occurrence of this set of events is on the first Monday of September.
$expecteddate = clone($startdatetime);
@@ -1104,9 +1095,9 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Change the start date for forever events to 9am of the current date.
$this->change_event_startdate(date('Ymd\T090000'));
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $interval = new DateInterval('P2Y');
+ $interval = new \DateInterval('P2Y');
$rrule = 'FREQ=YEARLY;INTERVAL=2'; // Forever event.
$mang = new rrule_manager($rrule);
@@ -1115,8 +1106,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
$expecteddate = clone($startdatetime);
@@ -1143,8 +1134,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_daily_count() {
global $DB;
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $interval = new DateInterval('P1D');
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $interval = new \DateInterval('P1D');
$rrule = 'FREQ=DAILY;COUNT=10';
$mang = new rrule_manager($rrule);
@@ -1154,7 +1145,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
$this->assertCount(10, $records);
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
foreach ($records as $record) {
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -1174,10 +1165,10 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_daily_until() {
global $DB;
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $interval = new DateInterval('P1D');
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $interval = new \DateInterval('P1D');
- $untildate = new DateTime('19971224T000000Z');
+ $untildate = new \DateTime('19971224T000000Z');
$untiltimestamp = $untildate->getTimestamp();
$rrule = 'FREQ=DAILY;UNTIL=19971224T000000Z';
@@ -1189,7 +1180,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// 113 daily events from 02-09-1997 to 23-12-1997.
$this->assertCount(113, $records);
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -1214,8 +1205,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Change the start date for forever events to 9am of the current date in US/Eastern time.
$this->change_event_startdate(date('Ymd\T090000'), 'US/Eastern');
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $interval = new DateInterval('P2D');
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $interval = new \DateInterval('P2D');
$rrule = 'FREQ=DAILY;INTERVAL=2';
$mang = new rrule_manager($rrule);
@@ -1225,11 +1216,11 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Get the first 100 samples. This should be enough to verify that we have generated the recurring events correctly.
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart', 0, 100);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
@@ -1249,8 +1240,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_every_10_days_5_count() {
global $DB;
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $interval = new DateInterval('P10D');
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $interval = new \DateInterval('P10D');
$rrule = 'FREQ=DAILY;INTERVAL=10;COUNT=5';
$mang = new rrule_manager($rrule);
@@ -1260,7 +1251,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
$this->assertCount(5, $records);
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
foreach ($records as $record) {
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
// Go to next period.
@@ -1292,7 +1283,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// 92 events from 01-01-1998 to 03-01-2000.
$this->assertCount(92, $records);
- $untildate = new DateTime('20000131T090000Z');
+ $untildate = new \DateTime('20000131T090000Z');
$untiltimestamp = $untildate->getTimestamp();
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
@@ -1326,7 +1317,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// 92 events from 01-01-1998 to 03-01-2000.
$this->assertCount(92, $records);
- $untildate = new DateTime('20000131T090000Z');
+ $untildate = new \DateTime('20000131T090000Z');
$untiltimestamp = $untildate->getTimestamp();
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
@@ -1347,7 +1338,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_weekly_10_count() {
global $DB;
- $interval = new DateInterval('P1W');
+ $interval = new \DateInterval('P1W');
$rrule = 'FREQ=WEEKLY;COUNT=10';
$mang = new rrule_manager($rrule);
@@ -1357,7 +1348,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
$this->assertCount(10, $records);
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
foreach ($records as $record) {
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
// Go to next period.
@@ -1376,7 +1367,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_weekly_until_24_dec_1997() {
global $DB;
- $interval = new DateInterval('P1W');
+ $interval = new \DateInterval('P1W');
$rrule = 'FREQ=WEEKLY;UNTIL=19971224T000000Z';
$mang = new rrule_manager($rrule);
@@ -1387,9 +1378,9 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// 17 iterations from 02-09-1997 13:00 UTC to 23-12-1997 13:00 UTC.
$this->assertCount(17, $records);
- $untildate = new DateTime('19971224T000000Z');
+ $untildate = new \DateTime('19971224T000000Z');
$untiltimestamp = $untildate->getTimestamp();
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -1416,7 +1407,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Change the start date for forever events to 9am of the current date in US/Eastern time.
$this->change_event_startdate(date('Ymd\T090000'), 'US/Eastern');
- $interval = new DateInterval('P2W');
+ $interval = new \DateInterval('P2W');
$rrule = 'FREQ=WEEKLY;INTERVAL=2;WKST=SU';
$mang = new rrule_manager($rrule);
@@ -1426,11 +1417,11 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Get the first 100 samples. This should be enough to verify that we have generated the recurring events correctly.
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart', 0, 100);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
@@ -1459,10 +1450,10 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// 17 iterations from 02-09-1997 13:00 UTC to 23-12-1997 13:00 UTC.
$this->assertCount(10, $records);
- $untildate = new DateTime('19971007T000000Z');
+ $untildate = new \DateTime('19971007T000000Z');
$untiltimestamp = $untildate->getTimestamp();
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime($expecteddate->format('Y-m-d'));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime($expecteddate->format('Y-m-d'));
$offset = $expecteddate->diff($startdate, true);
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
@@ -1497,8 +1488,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// 17 iterations from 02-09-1997 13:00 UTC to 23-12-1997 13:00 UTC.
$this->assertCount(10, $records);
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime($expecteddate->format('Y-m-d'));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime($expecteddate->format('Y-m-d'));
$offset = $expecteddate->diff($startdate, true);
foreach ($records as $record) {
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -1532,11 +1523,11 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// 24 iterations every M-W-F from 03-09-1997 13:00 UTC to 22-12-1997 13:00 UTC.
$this->assertCount(24, $records);
- $untildate = new DateTime('19971224T000000Z');
+ $untildate = new \DateTime('19971224T000000Z');
$untiltimestamp = $untildate->getTimestamp();
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
@@ -1559,7 +1550,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
default:
$expecteddate->modify('next Monday');
// Increment expected date by 1 week if the next day is Monday.
- $expecteddate->add(new DateInterval('P1W'));
+ $expecteddate->add(new \DateInterval('P1W'));
break;
}
$expecteddate->add($offsetinterval);
@@ -1585,8 +1576,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Should correspond to COUNT rule.
$this->assertCount(8, $records);
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
@@ -1603,7 +1594,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
default:
$expecteddate->modify('next Tuesday');
// Increment expected date by 1 week if the next day is Tuesday.
- $expecteddate->add(new DateInterval('P1W'));
+ $expecteddate->add(new \DateInterval('P1W'));
break;
}
$expecteddate->add($offsetinterval);
@@ -1625,7 +1616,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Change our event's date to 05-09-1997, based on the example from the RFC.
$startdatetime = $this->change_event_startdate('19970905T090000', 'US/Eastern');
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
$rrule = 'FREQ=MONTHLY;COUNT=10;BYDAY=1FR';
@@ -1640,7 +1631,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
foreach ($records as $record) {
// Get the first Friday of the record's month.
$recordmonthyear = date('F Y', $record->timestart);
- $expecteddate = new DateTime('first Friday of ' . $recordmonthyear);
+ $expecteddate = new \DateTime('first Friday of ' . $recordmonthyear);
// Add the time of the event.
$expecteddate->add($offsetinterval);
@@ -1661,7 +1652,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Change our event's date to 05-09-1997, based on the example from the RFC.
$startdatetime = $this->change_event_startdate('19970905T090000', 'US/Eastern');
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
$rrule = 'FREQ=MONTHLY;UNTIL=19971224T000000Z;BYDAY=1FR';
@@ -1676,7 +1667,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
foreach ($records as $record) {
// Get the first Friday of the record's month.
$recordmonthyear = date('F Y', $record->timestart);
- $expecteddate = new DateTime('first Friday of ' . $recordmonthyear);
+ $expecteddate = new \DateTime('first Friday of ' . $recordmonthyear);
// Add the time of the event.
$expecteddate->add($offsetinterval);
@@ -1699,7 +1690,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Change our event's date to 05-09-1997, based on the example from the RFC.
$startdatetime = $this->change_event_startdate('19970907T090000', 'US/Eastern');
- $startdate = new DateTime(date('Y-m-d', $this->event->timestart));
+ $startdate = new \DateTime(date('Y-m-d', $this->event->timestart));
$offsetinterval = $startdatetime->diff($startdate, true);
$rrule = 'FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU';
@@ -1716,7 +1707,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
foreach ($records as $record) {
// Get date of the month's first/last Sunday.
$recordmonthyear = date('F Y', $record->timestart);
- $expecteddate = new DateTime($ordinal . ' Sunday of ' . $recordmonthyear);
+ $expecteddate = new \DateTime($ordinal . ' Sunday of ' . $recordmonthyear);
$expecteddate->add($offsetinterval);
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -1742,7 +1733,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Change our event's date to 05-09-1997, based on the example from the RFC.
$startdatetime = $this->change_event_startdate('19970922T090000', 'US/Eastern');
- $startdate = new DateTime($startdatetime->format('Y-m-d'));
+ $startdate = new \DateTime($startdatetime->format('Y-m-d'));
$offsetinterval = $startdatetime->diff($startdate, true);
$rrule = 'FREQ=MONTHLY;COUNT=6;BYDAY=-2MO';
@@ -1757,7 +1748,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
foreach ($records as $record) {
// Get date of the month's last Monday.
$recordmonthyear = date('F Y', $record->timestart);
- $expecteddate = new DateTime('last Monday of ' . $recordmonthyear);
+ $expecteddate = new \DateTime('last Monday of ' . $recordmonthyear);
// Modify to get the second to the last Monday.
$expecteddate->modify('last Monday');
// Add offset.
@@ -1793,17 +1784,17 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Get the first 100 samples. This should be enough to verify that we have generated the recurring events correctly.
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart', 0, 100);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
- $subinterval = new DateInterval('P2D');
+ $subinterval = new \DateInterval('P2D');
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
// Get date of the third to the last day of the month.
$recordmonthyear = date('F Y', $record->timestart);
- $expecteddate = new DateTime('last day of ' . $recordmonthyear);
+ $expecteddate = new \DateTime('last day of ' . $recordmonthyear);
// Set time to 9am.
$expecteddate->setTime(9, 0);
// Modify to get the third to the last day of the month.
@@ -1825,8 +1816,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
public function test_every_2nd_and_15th_of_the_month_10_count() {
global $DB;
- $startdatetime = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $startdate = new DateTime($startdatetime->format('Y-m-d'));
+ $startdatetime = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $startdate = new \DateTime($startdatetime->format('Y-m-d'));
$offsetinterval = $startdatetime->diff($startdate, true);
$rrule = 'FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15';
@@ -1844,7 +1835,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$recordmonthyear = date('Y-m', $record->timestart);
// Get date of the month's last Monday.
- $expecteddate = new DateTime("$recordmonthyear-$day");
+ $expecteddate = new \DateTime("$recordmonthyear-$day");
// Add offset.
$expecteddate->add($offsetinterval);
if ($day === '02') {
@@ -1870,7 +1861,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
global $DB;
$startdatetime = $this->change_event_startdate('19970930T090000', 'US/Eastern');
- $startdate = new DateTime($startdatetime->format('Y-m-d'));
+ $startdate = new \DateTime($startdatetime->format('Y-m-d'));
$offsetinterval = $startdatetime->diff($startdate, true);
$rrule = 'FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1';
@@ -1889,7 +1880,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$recordmonthyear = date('F Y', $record->timestart);
// Get date of the month's last Monday.
- $expecteddate = new DateTime("$day day of $recordmonthyear");
+ $expecteddate = new \DateTime("$day day of $recordmonthyear");
// Add offset.
$expecteddate->add($offsetinterval);
@@ -1927,19 +1918,19 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// First occurrence is 10-Sep-1997.
$expecteddate = clone($startdatetime);
- $expecteddate->setTimezone(new DateTimeZone(get_user_timezone()));
+ $expecteddate->setTimezone(new \DateTimeZone(get_user_timezone()));
foreach ($records as $record) {
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
// Get next expected date.
if ($expecteddate->format('d') == 15) {
// If 15th, increment by 18 months.
- $expecteddate->add(new DateInterval('P18M'));
+ $expecteddate->add(new \DateInterval('P18M'));
// Then go back to the 10th.
- $expecteddate->sub(new DateInterval('P5D'));
+ $expecteddate->sub(new \DateInterval('P5D'));
} else {
// Otherwise, increment by 1 day.
- $expecteddate->add(new DateInterval('P1D'));
+ $expecteddate->add(new \DateInterval('P1D'));
}
}
}
@@ -1960,7 +1951,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
global $DB;
// Change the start date for forever events to 9am of the Tuesday on or before of the current date in US/Eastern time.
- $nexttuesday = new DateTime('next Tuesday');
+ $nexttuesday = new \DateTime('next Tuesday');
$this->change_event_startdate($nexttuesday->format('Ymd\T090000'), 'US/Eastern');
$rrule = 'FREQ=MONTHLY;INTERVAL=2;BYDAY=TU';
@@ -1971,12 +1962,12 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Get the first 100 samples. This should be enough to verify that we have generated the recurring events correctly.
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart', 0, 100);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $this->event->timestart));
- $nextmonth = new DateTime($expecteddate->format('Y-m-d'));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $this->event->timestart));
+ $nextmonth = new \DateTime($expecteddate->format('Y-m-d'));
$offset = $expecteddate->diff($nextmonth, true);
$nextmonth->modify('first day of next month');
foreach ($records as $record) {
@@ -1993,7 +1984,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$expecteddate->modify('next Tuesday');
// Increment next month by 2 months.
- $nextmonth->add(new DateInterval('P2M'));
+ $nextmonth->add(new \DateInterval('P2M'));
}
$expecteddate->add($offset);
}
@@ -2026,9 +2017,9 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount(10, $records);
$expecteddate = $startdatetime;
- $expecteddate->setTimezone(new DateTimeZone(get_user_timezone()));
- $monthinterval = new DateInterval('P1M');
- $yearinterval = new DateInterval('P1Y');
+ $expecteddate->setTimezone(new \DateTimeZone(get_user_timezone()));
+ $monthinterval = new \DateInterval('P1M');
+ $yearinterval = new \DateInterval('P1Y');
foreach ($records as $record) {
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -2069,9 +2060,9 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount(10, $records);
$expecteddate = $startdatetime;
- $expecteddate->setTimezone(new DateTimeZone(get_user_timezone()));
- $monthinterval = new DateInterval('P1M');
- $yearinterval = new DateInterval('P2Y');
+ $expecteddate->setTimezone(new \DateTimeZone(get_user_timezone()));
+ $monthinterval = new \DateInterval('P1M');
+ $yearinterval = new \DateInterval('P2Y');
foreach ($records as $record) {
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -2116,10 +2107,10 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount(10, $records);
$expecteddate = $startdatetime;
- $expecteddate->setTimezone(new DateTimeZone(get_user_timezone()));
- $hundredthdayinterval = new DateInterval('P99D');
- $twohundredthdayinterval = new DateInterval('P100D');
- $yearinterval = new DateInterval('P3Y');
+ $expecteddate->setTimezone(new \DateTimeZone(get_user_timezone()));
+ $hundredthdayinterval = new \DateInterval('P99D');
+ $twohundredthdayinterval = new \DateInterval('P100D');
+ $yearinterval = new \DateInterval('P3Y');
foreach ($records as $record) {
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -2152,11 +2143,11 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
global $DB;
// Change our event's date to the 20th Monday of the current year.
- $twentiethmonday = new DateTime(date('Y-01-01'));
+ $twentiethmonday = new \DateTime(date('Y-01-01'));
$twentiethmonday->modify('+20 Monday');
$startdatetime = $this->change_event_startdate($twentiethmonday->format('Ymd\T000000'), 'US/Eastern');
- $interval = new DateInterval('P1Y');
+ $interval = new \DateInterval('P1Y');
$rrule = 'FREQ=YEARLY;BYDAY=20MO';
$mang = new rrule_manager($rrule);
@@ -2165,12 +2156,12 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
$expecteddate = $startdatetime;
- $expecteddate->setTimezone(new DateTimeZone(get_user_timezone()));
+ $expecteddate->setTimezone(new \DateTimeZone(get_user_timezone()));
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -2198,7 +2189,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
global $DB;
// Change our event's date to the start of the 20th week of the current year.
- $twentiethweek = new DateTime(date('Y-01-01'));
+ $twentiethweek = new \DateTime(date('Y-01-01'));
$twentiethweek->setISODate($twentiethweek->format('Y'), 20);
$startdatetime = $this->change_event_startdate($twentiethweek->format('Ymd\T090000'), 'US/Eastern');
@@ -2207,7 +2198,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$offset = $startdatetime->diff($startdate, true);
- $interval = new DateInterval('P1Y');
+ $interval = new \DateInterval('P1Y');
$rrule = 'FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO';
$mang = new rrule_manager($rrule);
@@ -2216,11 +2207,11 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -2248,10 +2239,10 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
global $DB;
// Change our event's date to the first Thursday of March of the current year at 9am US/Eastern time.
- $firstthursdayofmarch = new DateTime('first Thursday of March');
+ $firstthursdayofmarch = new \DateTime('first Thursday of March');
$startdatetime = $this->change_event_startdate($firstthursdayofmarch->format('Ymd\T090000'), 'US/Eastern');
- $interval = new DateInterval('P1Y');
+ $interval = new \DateInterval('P1Y');
$rrule = 'FREQ=YEARLY;BYMONTH=3;BYDAY=TH';
$mang = new rrule_manager($rrule);
@@ -2261,15 +2252,15 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Get the first 100 samples. This should be enough to verify that we have generated the recurring events correctly.
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart', 0, 100);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
$expecteddate = $startdatetime;
- $startdate = new DateTime($startdatetime->format('Y-m-d'));
+ $startdate = new \DateTime($startdatetime->format('Y-m-d'));
$offsetinterval = $startdatetime->diff($startdate, true);
- $expecteddate->setTimezone(new DateTimeZone(get_user_timezone()));
- $april1st = new DateTime('April 1');
+ $expecteddate->setTimezone(new \DateTimeZone(get_user_timezone()));
+ $april1st = new \DateTime('April 1');
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -2307,14 +2298,14 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
global $DB;
// Change our event's date to the first Thursday of June in the current year at 9am US/Eastern time.
- $firstthursdayofjune = new DateTime('first Thursday of June');
+ $firstthursdayofjune = new \DateTime('first Thursday of June');
$startdatetime = $this->change_event_startdate($firstthursdayofjune->format('Ymd\T090000'), 'US/Eastern');
- $startdate = new DateTime($startdatetime->format('Y-m-d'));
+ $startdate = new \DateTime($startdatetime->format('Y-m-d'));
$offset = $startdatetime->diff($startdate, true);
- $interval = new DateInterval('P1Y');
+ $interval = new \DateInterval('P1Y');
$rrule = 'FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8';
$mang = new rrule_manager($rrule);
@@ -2324,12 +2315,12 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Get the first 100 samples. This should be enough to verify that we have generated the recurring events correctly.
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart', 0, 100);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
- $expecteddate = new DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
- $september1st = new DateTime('September 1');
+ $expecteddate = new \DateTime(date('Y-m-d H:i:s', $startdatetime->getTimestamp()));
+ $september1st = new \DateTime('September 1');
foreach ($records as $record) {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
@@ -2374,8 +2365,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Get the first 100 samples. This should be enough to verify that we have generated the recurring events correctly.
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart', 0, 100);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
foreach ($records as $record) {
@@ -2401,10 +2392,10 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
global $DB;
// Change our event's date to the next Saturday after the first Sunday of the the current month at 9am US/Eastern time.
- $firstsaturdayafterfirstsunday = new DateTime('first Sunday of this month');
+ $firstsaturdayafterfirstsunday = new \DateTime('first Sunday of this month');
$firstsaturdayafterfirstsunday->modify('next Saturday');
$startdatetime = $this->change_event_startdate($firstsaturdayafterfirstsunday->format('Ymd\T090000'), 'US/Eastern');
- $startdate = new DateTime($startdatetime->format('Y-m-d'));
+ $startdate = new \DateTime($startdatetime->format('Y-m-d'));
$offset = $startdatetime->diff($startdate, true);
$rrule = 'FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13';
@@ -2415,8 +2406,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
// Get the first 100 samples. This should be enough to verify that we have generated the recurring events correctly.
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart', 0, 100);
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
$bymonthdays = [7, 8, 9, 10, 11, 12, 13];
foreach ($records as $record) {
@@ -2424,7 +2415,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
// Get first Saturday after the first Sunday of the month.
- $expecteddate = new DateTime('first Sunday of ' . $recordmonthyear);
+ $expecteddate = new \DateTime('first Sunday of ' . $recordmonthyear);
$expecteddate->modify('next Saturday');
$expecteddate->add($offset);
@@ -2457,12 +2448,12 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
while ($electionyear + 4 < $currentyear) {
$electionyear += 4;
}
- $electiondate = new DateTime('first Monday of November ' . $electionyear);
+ $electiondate = new \DateTime('first Monday of November ' . $electionyear);
$electiondate->modify('+1 Tuesday');
// Use the most recent election date as the starting date of our recurring events.
$startdatetime = $this->change_event_startdate($electiondate->format('Ymd\T090000'), 'US/Eastern');
- $startdate = new DateTime($startdatetime->format('Y-m-d'));
+ $startdate = new \DateTime($startdatetime->format('Y-m-d'));
$offset = $startdatetime->diff($startdate, true);
$rrule = 'FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8';
@@ -2472,8 +2463,8 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart');
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
$bymonthdays = [2, 3, 4, 5, 6, 7, 8];
foreach ($records as $record) {
@@ -2481,7 +2472,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertLessThanOrEqual($untiltimestamp, $record->timestart);
// Get first Saturday after the first Sunday of the month.
- $expecteddate = new DateTime('first Monday of ' . $recordmonthyear);
+ $expecteddate = new \DateTime('first Monday of ' . $recordmonthyear);
$expecteddate->modify('next Tuesday');
$expecteddate->add($offset);
@@ -2515,9 +2506,9 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount(3, $records);
$expecteddates = [
- (new DateTime('1997-09-04 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-10-07 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-11-06 09:00:00 EST'))->getTimestamp()
+ (new \DateTime('1997-09-04 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-10-07 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-11-06 09:00:00 EST'))->getTimestamp()
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates,
@@ -2552,17 +2543,17 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$records = $DB->get_records('event', ['repeatid' => $this->event->id], 'timestart ASC', 'id, repeatid, timestart', 0, 7);
$expecteddates = [
- (new DateTime('1997-09-29 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-10-30 09:00:00 EST'))->getTimestamp(),
- (new DateTime('1997-11-27 09:00:00 EST'))->getTimestamp(),
- (new DateTime('1997-12-30 09:00:00 EST'))->getTimestamp(),
- (new DateTime('1998-01-29 09:00:00 EST'))->getTimestamp(),
- (new DateTime('1998-02-26 09:00:00 EST'))->getTimestamp(),
- (new DateTime('1998-03-30 09:00:00 EST'))->getTimestamp(),
+ (new \DateTime('1997-09-29 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-10-30 09:00:00 EST'))->getTimestamp(),
+ (new \DateTime('1997-11-27 09:00:00 EST'))->getTimestamp(),
+ (new \DateTime('1997-12-30 09:00:00 EST'))->getTimestamp(),
+ (new \DateTime('1998-01-29 09:00:00 EST'))->getTimestamp(),
+ (new \DateTime('1998-02-26 09:00:00 EST'))->getTimestamp(),
+ (new \DateTime('1998-03-30 09:00:00 EST'))->getTimestamp(),
];
- $untildate = new DateTime();
- $untildate->add(new DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
+ $untildate = new \DateTime();
+ $untildate->add(new \DateInterval('P' . $mang::TIME_UNLIMITED_YEARS . 'Y'));
$untiltimestamp = $untildate->getTimestamp();
$i = 0;
@@ -2594,9 +2585,9 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount(3, $records);
$expecteddates = [
- (new DateTime('1997-09-02 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-09-02 12:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-09-02 15:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 12:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 15:00:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates,
@@ -2623,12 +2614,12 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount(6, $records);
$expecteddates = [
- (new DateTime('1997-09-02 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-09-02 09:15:00 EDT'))->getTimestamp(),
- (new DateTime('1997-09-02 09:30:00 EDT'))->getTimestamp(),
- (new DateTime('1997-09-02 09:45:00 EDT'))->getTimestamp(),
- (new DateTime('1997-09-02 10:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-09-02 10:15:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 09:15:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 09:30:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 09:45:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 10:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 10:15:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates,
@@ -2655,10 +2646,10 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount(4, $records);
$expecteddates = [
- (new DateTime('1997-09-02 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-09-02 10:30:00 EDT'))->getTimestamp(),
- (new DateTime('1997-09-02 12:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-09-02 13:30:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 10:30:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 12:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-09-02 13:30:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates,
@@ -2686,9 +2677,9 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$mang->parse_rrule();
$mang->create_events($this->event);
- $byminuteinterval = new DateInterval('PT20M');
- $bydayinterval = new DateInterval('P1D');
- $date = new DateTime('1997-09-02 09:00:00 EDT');
+ $byminuteinterval = new \DateInterval('PT20M');
+ $bydayinterval = new \DateInterval('P1D');
+ $date = new \DateTime('1997-09-02 09:00:00 EDT');
$expecteddates = [];
$count = 50;
for ($i = 0; $i < $count; $i++) {
@@ -2731,9 +2722,9 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$mang->parse_rrule();
$mang->create_events($this->event);
- $byminuteinterval = new DateInterval('PT20M');
- $bydayinterval = new DateInterval('P1D');
- $date = new DateTime('1997-09-02 09:00:00');
+ $byminuteinterval = new \DateInterval('PT20M');
+ $bydayinterval = new \DateInterval('P1D');
+ $date = new \DateTime('1997-09-02 09:00:00');
$expecteddates = [];
$count = 50;
for ($i = 0; $i < $count; $i++) {
@@ -2777,10 +2768,10 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount(4, $records);
$expecteddates = [
- (new DateTime('1997-08-05 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-08-10 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-08-19 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-08-24 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-08-05 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-08-10 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-08-19 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-08-24 09:00:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContainsEquals($record->timestart, $expecteddates,
@@ -2810,10 +2801,10 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount(4, $records);
$expecteddates = [
- (new DateTime('1997-08-05 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-08-17 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-08-19 09:00:00 EDT'))->getTimestamp(),
- (new DateTime('1997-08-31 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-08-05 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-08-17 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-08-19 09:00:00 EDT'))->getTimestamp(),
+ (new \DateTime('1997-08-31 09:00:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
@@ -2864,7 +2855,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount(30, $records);
foreach ($records as $record) {
- $date = new DateTime(date('Y-m-d H:i:s', $record->timestart));
+ $date = new \DateTime(date('Y-m-d H:i:s', $record->timestart));
$year = $date->format('Y');
$day = $date->format('d');
if ($year % 4 == 0) {
@@ -2886,14 +2877,14 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
protected function change_event_startdate($datestr, $timezonestr = null) {
// Use default timezone if not provided.
if ($timezonestr === null) {
- $newdatetime = DateTime::createFromFormat('Ymd\THis', $datestr);
+ $newdatetime = \DateTime::createFromFormat('Ymd\THis', $datestr);
} else {
- $timezone = new DateTimeZone($timezonestr);
- $newdatetime = DateTime::createFromFormat('Ymd\THis', $datestr, $timezone);
+ $timezone = new \DateTimeZone($timezonestr);
+ $newdatetime = \DateTime::createFromFormat('Ymd\THis', $datestr, $timezone);
}
// Update the start date of the parent event.
- $calevent = calendar_event::load($this->event->id);
+ $calevent = \calendar_event::load($this->event->id);
$updatedata = (object)[
'timestart' => $newdatetime->getTimestamp(),
'repeatid' => $this->event->id
diff --git a/calendar/tests/std_proxy_test.php b/calendar/tests/std_proxy_test.php
index 5d175ac5e95..b1c712556dc 100644
--- a/calendar/tests/std_proxy_test.php
+++ b/calendar/tests/std_proxy_test.php
@@ -14,25 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * std_proxy tests.
- *
- * @package core_calendar
- * @copyright 2017 Cameron Ball
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_calendar;
use core_calendar\local\event\proxies\std_proxy;
/**
* std_proxy testcase.
*
+ * @package core_calendar
* @copyright 2017 Cameron Ball
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_calendar_std_proxy_testcase extends advanced_testcase {
+class std_proxy_test extends \advanced_testcase {
/**
* @var \stdClass[] $objects Array of objects to proxy.
*/
diff --git a/comment/tests/context_freeze_test.php b/comment/tests/context_freeze_test.php
index 36f1d600bca..29bbd81fa0c 100644
--- a/comment/tests/context_freeze_test.php
+++ b/comment/tests/context_freeze_test.php
@@ -14,16 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for comments when the context is frozen.
- *
- * @package core_comment
- * @copyright 2019 University of Nottingham
- * @author Neill Magill
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_comment;
-defined('MOODLE_INTERNAL') || die();
+use comment;
+use comment_exception;
+use core_comment_external;
/**
* Tests for comments when the context is frozen.
@@ -33,7 +28,7 @@ defined('MOODLE_INTERNAL') || die();
* @author Neill Magill
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class comment_context_freeze_testcase extends advanced_testcase {
+class context_freeze_test extends \advanced_testcase {
/**
* Creates a comment by a student.
*
@@ -42,16 +37,16 @@ class comment_context_freeze_testcase extends advanced_testcase {
* - The sudent that wrote the comment
* - The arguments used to create the comment
*
- * @param stdClass $course Moodle course from the datagenerator
+ * @param \stdClass $course Moodle course from the datagenerator
* @return array
*/
protected function create_student_comment_and_freeze_course($course): array {
set_config('contextlocking', 1);
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
- $args = new stdClass;
+ $args = new \stdClass;
$args->context = $context;
$args->course = $course;
$args->area = 'page_comments';
diff --git a/competency/tests/competency_rule_test.php b/competency/tests/competency_rule_test.php
index f4602c1cf0a..893fa724c45 100644
--- a/competency/tests/competency_rule_test.php
+++ b/competency/tests/competency_rule_test.php
@@ -14,24 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Competency rule tests.
- *
- * @package core_competency
- * @copyright 2015 Frédéric Massart - FMCorz.net
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_competency;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
-use core_competency\user_competency;
-use core_competency\competency;
-use core_competency\competency_rule_all;
-use core_competency\competency_rule_points;
-
/**
* Competency rule testcase.
*
@@ -39,7 +28,7 @@ use core_competency\competency_rule_points;
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_competency_competency_rule_testcase extends externallib_advanced_testcase {
+class competency_rule_test extends \externallib_advanced_testcase {
public function test_rule_all_matching() {
$this->resetAfterTest(true);
diff --git a/competency/tests/competency_test.php b/competency/tests/competency_test.php
index 929ecf07126..eb1c3d523ae 100644
--- a/competency/tests/competency_test.php
+++ b/competency/tests/competency_test.php
@@ -14,18 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Competency tests.
- *
- * @package core_competency
- * @copyright 2016 Frédéric Massart - FMCorz.net
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-global $CFG;
-
-use core_competency\competency;
+namespace core_competency;
/**
* Competency testcase.
@@ -34,7 +23,7 @@ use core_competency\competency;
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_competency_competency_testcase extends advanced_testcase {
+class competency_test extends \advanced_testcase {
public function test_get_framework_depth() {
$this->resetAfterTest();
diff --git a/competency/tests/course_competency_settings_test.php b/competency/tests/course_competency_settings_test.php
index d1803ca68df..b825af74325 100644
--- a/competency/tests/course_competency_settings_test.php
+++ b/competency/tests/course_competency_settings_test.php
@@ -14,20 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Course competency persistent class tests.
- *
- * @package core_competency
- * @copyright 2016 Frédéric Massart - FMCorz.net
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-global $CFG;
-
-use core_competency\course_competency;
-use core_competency\api;
-use core_competency\course_competency_settings;
+namespace core_competency;
/**
* This test ensures that the course competency settings are applied and work correctly.
@@ -36,14 +23,14 @@ use core_competency\course_competency_settings;
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_competency_course_competency_settings_testcase extends advanced_testcase {
+class course_competency_settings_test extends \advanced_testcase {
public function test_who_can_change_settings() {
global $CFG, $DB;
$this->resetAfterTest(true);
- $syscontext = context_system::instance();
+ $syscontext = \context_system::instance();
$dg = $this->getDataGenerator();
$lpg = $dg->get_plugin_generator('core_competency');
$role = create_role('Settings changer role', 'settingschanger', 'Someone who can change course competency settings');
diff --git a/competency/tests/course_competency_test.php b/competency/tests/course_competency_test.php
index ddc2de52c2b..ae1da6a99c8 100644
--- a/competency/tests/course_competency_test.php
+++ b/competency/tests/course_competency_test.php
@@ -14,18 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Course competency persistent class tests.
- *
- * @package core_competency
- * @copyright 2016 Frédéric Massart - FMCorz.net
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-global $CFG;
-
-use core_competency\course_competency;
+namespace core_competency;
/**
* Course competency persistent testcase.
@@ -34,7 +23,7 @@ use core_competency\course_competency;
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_competency_course_competency_testcase extends advanced_testcase {
+class course_competency_test extends \advanced_testcase {
public function test_get_courses_with_competency_and_user() {
global $CFG, $DB;
diff --git a/competency/tests/course_module_competency_test.php b/competency/tests/course_module_competency_test.php
index 8d951dc0da2..1d7bd3b0ac2 100644
--- a/competency/tests/course_module_competency_test.php
+++ b/competency/tests/course_module_competency_test.php
@@ -14,18 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Course module competency persistent class tests.
- *
- * @package core_competency
- * @copyright 2019 Damyon Wiese
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-global $CFG;
-
-use core_competency\course_module_competency;
+namespace core_competency;
/**
* Course module competency persistent testcase.
@@ -34,7 +23,7 @@ use core_competency\course_module_competency;
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_competency_course_module_competency_testcase extends advanced_testcase {
+class course_module_competency_test extends \advanced_testcase {
public function test_count_competencies() {
global $CFG, $DB;
diff --git a/competency/tests/hooks_test.php b/competency/tests/hooks_test.php
index c1890eac6f0..595d31c17c3 100644
--- a/competency/tests/hooks_test.php
+++ b/competency/tests/hooks_test.php
@@ -14,19 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Hook tests.
- *
- * @package core_competency
- * @copyright 2016 Frédéric Massart - FMCorz.net
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-use core_competency\course_competency;
-use core_competency\course_module_competency;
-use core_competency\user_competency_course;
+namespace core_competency;
/**
* Hook tests.
@@ -35,7 +23,7 @@ use core_competency\user_competency_course;
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_competency_hooks_testcase extends advanced_testcase {
+class hooks_test extends \advanced_testcase {
public function test_hook_course_deleted() {
$this->resetAfterTest();
@@ -192,9 +180,9 @@ class core_competency_hooks_testcase extends advanced_testcase {
$t2 = $corecompgen->create_template();
// Create the template cohorts.
- core_competency\api::create_template_cohort($t1->get('id'), $c1->id);
- core_competency\api::create_template_cohort($t1->get('id'), $c2->id);
- core_competency\api::create_template_cohort($t2->get('id'), $c1->id);
+ api::create_template_cohort($t1->get('id'), $c1->id);
+ api::create_template_cohort($t1->get('id'), $c2->id);
+ api::create_template_cohort($t2->get('id'), $c1->id);
// Check that the association was made.
$this->assertEquals(2, \core_competency\template_cohort::count_records(array('templateid' => $t1->get('id'))));
diff --git a/competency/tests/performance_helper_test.php b/competency/tests/performance_helper_test.php
index 52bee4cf8aa..ae9477da573 100644
--- a/competency/tests/performance_helper_test.php
+++ b/competency/tests/performance_helper_test.php
@@ -14,16 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Performance helper tests.
- *
- * @package core_competency
- * @copyright 2016 Frédéric Massart - FMCorz.net
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-global $CFG;
+namespace core_competency;
use core_competency\external\performance_helper;
@@ -34,7 +25,7 @@ use core_competency\external\performance_helper;
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_competency_performance_helper_testcase extends advanced_testcase {
+class performance_helper_test extends \advanced_testcase {
public function test_get_context_from_competency() {
global $DB;
diff --git a/competency/tests/user_evidence_competency_test.php b/competency/tests/user_evidence_competency_test.php
index 8d4766cb83f..60090b43233 100644
--- a/competency/tests/user_evidence_competency_test.php
+++ b/competency/tests/user_evidence_competency_test.php
@@ -14,18 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * User evidence competency persistent class tests.
- *
- * @package core_competency
- * @copyright 2016 Serge Gauthier -
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-global $CFG;
-
-use core_competency\user_evidence_competency;
+namespace core_competency;
/**
* User evidence competency persistent testcase.
@@ -34,7 +23,7 @@ use core_competency\user_evidence_competency;
* @copyright 2016 Serge Gauthier -
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_competency_user_evidence_competency_testcase extends advanced_testcase {
+class user_evidence_competency_test extends \advanced_testcase {
public function test_get_user_competencies_by_userevidenceid() {
global $CFG, $DB;
diff --git a/completion/tests/bulk_update_test.php b/completion/tests/bulk_update_test.php
index 69dcd09129d..e9a4312e284 100644
--- a/completion/tests/bulk_update_test.php
+++ b/completion/tests/bulk_update_test.php
@@ -14,13 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * External completion functions unit tests
- *
- * @package core_completion
- * @copyright 2017 Marina Glancy
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_completion;
+
+use core_completion_bulkedit_form;
defined('MOODLE_INTERNAL') || die();
@@ -34,7 +30,7 @@ require_once($CFG->libdir . '/completionlib.php');
* @copyright 2017 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_completion_bulk_update_testcase extends advanced_testcase {
+class bulk_update_test extends \advanced_testcase {
/**
* Provider for test_bulk_form_submit_single
@@ -130,7 +126,7 @@ class core_completion_bulk_update_testcase extends advanced_testcase {
}
// Apply completion rules to the modules.
- $manager = new core_completion\manager($course->id);
+ $manager = new manager($course->id);
$manager->apply_completion($data, $form->has_custom_completion_rules());
// Make sure either course_modules or instance table was respectfully updated.
@@ -245,7 +241,7 @@ class core_completion_bulk_update_testcase extends advanced_testcase {
}
// Apply completion rules to the modules.
- $manager = new core_completion\manager($course->id);
+ $manager = new manager($course->id);
$manager->apply_completion($data, $form->has_custom_completion_rules());
// Make sure either course_modules or instance table was respectfully updated.
diff --git a/completion/tests/capabilities_test.php b/completion/tests/capabilities_test.php
index 5dd4239e955..cf6e58383b4 100644
--- a/completion/tests/capabilities_test.php
+++ b/completion/tests/capabilities_test.php
@@ -14,16 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests that completion works without requiring unnecessary capabilities.
- *
- * @package core_completion
- * @copyright 2018 University of Nottingham
- * @author Neill Magill
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_completion;
/**
* Tests that completion works without requiring unnecessary capabilities.
@@ -33,14 +24,14 @@ defined('MOODLE_INTERNAL') || die();
* @author Neill Magill
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_completion_capabilities_testcase extends advanced_testcase {
+class capabilities_test extends \advanced_testcase {
/**
* A user who does not have capabilities to add events to the calendar should be able to create activities.
*/
public function test_creation_with_no_calendar_capabilities() {
$this->resetAfterTest();
$course = self::getDataGenerator()->create_course(['enablecompletion' => 1]);
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
$roleid = self::getDataGenerator()->create_role();
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
diff --git a/contentbank/contenttype/h5p/tests/content_h5p_test.php b/contentbank/contenttype/h5p/tests/content_h5p_test.php
index 407a9bc8279..4c145c21244 100644
--- a/contentbank/contenttype/h5p/tests/content_h5p_test.php
+++ b/contentbank/contenttype/h5p/tests/content_h5p_test.php
@@ -14,14 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Test for H5P content bank plugin.
- *
- * @package contenttype_h5p
- * @category test
- * @copyright 2020 Amaia Anabitarte
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace contenttype_h5p;
/**
* Test for H5P content bank plugin.
@@ -32,7 +25,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \contenttype_h5p\content
*/
-class contenttype_h5p_content_plugin_testcase extends advanced_testcase {
+class content_h5p_test extends \advanced_testcase {
/**
* Tests for uploaded file.
@@ -43,10 +36,10 @@ class contenttype_h5p_content_plugin_testcase extends advanced_testcase {
$this->resetAfterTest();
// Create content.
- $record = new stdClass();
+ $record = new \stdClass();
$record->name = 'Test content';
$record->configdata = '';
- $contenttype = new \contenttype_h5p\contenttype(context_system::instance());
+ $contenttype = new \contenttype_h5p\contenttype(\context_system::instance());
$content = $contenttype->create_content($record);
// Create a dummy file.
diff --git a/contentbank/contenttype/h5p/tests/contenttype_h5p_test.php b/contentbank/contenttype/h5p/tests/contenttype_h5p_test.php
index 63c5d087717..592072817ba 100644
--- a/contentbank/contenttype/h5p/tests/contenttype_h5p_test.php
+++ b/contentbank/contenttype/h5p/tests/contenttype_h5p_test.php
@@ -14,14 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Test for H5P content bank plugin.
- *
- * @package contenttype_h5p
- * @category test
- * @copyright 2020 Amaia Anabitarte
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace contenttype_h5p;
/**
* Test for H5P content bank plugin.
@@ -32,7 +25,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \contenttype_h5p\contenttype
*/
-class contenttype_h5p_contenttype_plugin_testcase extends advanced_testcase {
+class contenttype_h5p_test extends \advanced_testcase {
/**
* Test the behaviour of delete_content().
@@ -41,7 +34,7 @@ class contenttype_h5p_contenttype_plugin_testcase extends advanced_testcase {
global $CFG, $USER, $DB;
$this->resetAfterTest();
- $systemcontext = context_system::instance();
+ $systemcontext = \context_system::instance();
// Create users.
$roleid = $DB->get_field('role', 'id', array('shortname' => 'manager'));
@@ -115,9 +108,9 @@ class contenttype_h5p_contenttype_plugin_testcase extends advanced_testcase {
global $CFG;
$this->resetAfterTest();
- $systemcontext = context_system::instance();
+ $systemcontext = \context_system::instance();
$this->setAdminUser();
- $contenttype = new contenttype_h5p\contenttype($systemcontext);
+ $contenttype = new contenttype($systemcontext);
// Add an H5P fill the blanks file to the content bank.
$filepath = $CFG->dirroot . '/h5p/tests/fixtures/filltheblanks.h5p';
@@ -157,9 +150,9 @@ class contenttype_h5p_contenttype_plugin_testcase extends advanced_testcase {
global $CFG;
$this->resetAfterTest();
- $systemcontext = context_system::instance();
+ $systemcontext = \context_system::instance();
$this->setAdminUser();
- $contenttype = new contenttype_h5p\contenttype($systemcontext);
+ $contenttype = new contenttype($systemcontext);
// Add an H5P fill the blanks file to the content bank.
$filename = 'filltheblanks.h5p';
diff --git a/course/format/topics/tests/format_topics_test.php b/course/format/topics/tests/format_topics_test.php
index 5f2ead3a219..31794cfe452 100644
--- a/course/format/topics/tests/format_topics_test.php
+++ b/course/format/topics/tests/format_topics_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Topics course format related unit tests.
- *
- * @package format_topics
- * @copyright 2015 Marina Glancy
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace format_topics;
defined('MOODLE_INTERNAL') || die();
@@ -34,7 +28,7 @@ require_once($CFG->dirroot . '/course/lib.php');
* @copyright 2015 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class format_topics_testcase extends advanced_testcase {
+class format_topics_test extends \advanced_testcase {
/**
* Tests for format_topics::get_section_name method with default section names.
@@ -145,9 +139,9 @@ class format_topics_testcase extends advanced_testcase {
// Call webservice without necessary permissions.
try {
- core_external::update_inplace_editable('format_topics', 'sectionname', $section->id, 'New section name');
+ \core_external::update_inplace_editable('format_topics', 'sectionname', $section->id, 'New section name');
$this->fail('Exception expected');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertEquals('Course or activity not accessible. (Not enrolled)',
$e->getMessage());
}
@@ -156,8 +150,8 @@ class format_topics_testcase extends advanced_testcase {
$teacherrole = $DB->get_record('role', ['shortname' => 'editingteacher']);
$this->getDataGenerator()->enrol_user($user->id, $course->id, $teacherrole->id);
- $res = core_external::update_inplace_editable('format_topics', 'sectionname', $section->id, 'New section name');
- $res = external_api::clean_returnvalue(core_external::update_inplace_editable_returns(), $res);
+ $res = \core_external::update_inplace_editable('format_topics', 'sectionname', $section->id, 'New section name');
+ $res = \external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
$this->assertEquals('New section name', $res['value']);
$this->assertEquals('New section name', $DB->get_field('course_sections', 'name', ['id' => $section->id]));
}
@@ -191,7 +185,7 @@ class format_topics_testcase extends advanced_testcase {
try {
component_callback('format_weeks', 'inplace_editable', ['sectionname', $section->id, 'New name']);
$this->fail('Exception expected');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertEquals(1, preg_match('/^Can\'t find data record in database/', $e->getMessage()));
}
}
@@ -218,14 +212,14 @@ class format_topics_testcase extends advanced_testcase {
'course' => $course,
'category' => $category,
'editoroptions' => [
- 'context' => context_course::instance($course->id),
+ 'context' => \context_course::instance($course->id),
'subdirs' => 0
],
- 'returnto' => new moodle_url('/'),
- 'returnurl' => new moodle_url('/'),
+ 'returnto' => new \moodle_url('/'),
+ 'returnurl' => new \moodle_url('/'),
];
- $courseform = new testable_course_edit_form(null, $args);
+ $courseform = new \testable_course_edit_form(null, $args);
$courseform->definition_after_data();
$enddate = $params['startdate'] + get_config('moodlecourse', 'courseduration');
diff --git a/course/format/weeks/tests/format_weeks_test.php b/course/format/weeks/tests/format_weeks_test.php
index e416787d3b1..dd5eb990a36 100644
--- a/course/format/weeks/tests/format_weeks_test.php
+++ b/course/format/weeks/tests/format_weeks_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * format_weeks related unit tests
- *
- * @package format_weeks
- * @copyright 2015 Marina Glancy
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace format_weeks;
defined('MOODLE_INTERNAL') || die();
@@ -34,7 +28,7 @@ require_once($CFG->dirroot . '/course/lib.php');
* @copyright 2015 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class format_weeks_testcase extends advanced_testcase {
+class format_weeks_test extends \advanced_testcase {
/**
* Tests for format_weeks::get_section_name method with default section names.
@@ -143,9 +137,9 @@ class format_weeks_testcase extends advanced_testcase {
// Call webservice without necessary permissions.
try {
- core_external::update_inplace_editable('format_weeks', 'sectionname', $section->id, 'New section name');
+ \core_external::update_inplace_editable('format_weeks', 'sectionname', $section->id, 'New section name');
$this->fail('Exception expected');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertEquals('Course or activity not accessible. (Not enrolled)',
$e->getMessage());
}
@@ -154,8 +148,8 @@ class format_weeks_testcase extends advanced_testcase {
$teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $teacherrole->id);
- $res = core_external::update_inplace_editable('format_weeks', 'sectionname', $section->id, 'New section name');
- $res = external_api::clean_returnvalue(core_external::update_inplace_editable_returns(), $res);
+ $res = \core_external::update_inplace_editable('format_weeks', 'sectionname', $section->id, 'New section name');
+ $res = \external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
$this->assertEquals('New section name', $res['value']);
$this->assertEquals('New section name', $DB->get_field('course_sections', 'name', array('id' => $section->id)));
}
@@ -187,7 +181,7 @@ class format_weeks_testcase extends advanced_testcase {
try {
$tmpl = component_callback('format_topics', 'inplace_editable', array('sectionname', $section->id, 'New name'));
$this->fail('Exception expected');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertEquals(1, preg_match('/^Can\'t find data record in database/', $e->getMessage()));
}
}
@@ -214,15 +208,15 @@ class format_weeks_testcase extends advanced_testcase {
'course' => $course,
'category' => $category,
'editoroptions' => [
- 'context' => context_course::instance($course->id),
+ 'context' => \context_course::instance($course->id),
'subdirs' => 0
],
- 'returnto' => new moodle_url('/'),
- 'returnurl' => new moodle_url('/'),
+ 'returnto' => new \moodle_url('/'),
+ 'returnurl' => new \moodle_url('/'),
];
$PAGE->set_course($course);
- $courseform = new testable_course_edit_form(null, $args);
+ $courseform = new \testable_course_edit_form(null, $args);
$courseform->definition_after_data();
// format_weeks::get_section_dates is adding 2h to avoid DST problems, we need to replicate it here.
diff --git a/course/tests/category_test.php b/course/tests/category_test.php
index 5d463dec0d1..9b58aae8a8c 100644
--- a/course/tests/category_test.php
+++ b/course/tests/category_test.php
@@ -14,21 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_course;
+
+use core_course_category;
+
/**
* Tests for class core_course_category
*
* @package core_course
- * @category phpunit
+ * @category test
* @copyright 2013 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-/**
- * Functional test for class core_course_category
- */
-class core_course_category_testcase extends advanced_testcase {
+class category_test extends \advanced_testcase {
protected $roles;
@@ -42,7 +40,7 @@ class core_course_category_testcase extends advanced_testcase {
protected function get_roleid($context = null) {
global $USER;
if ($context === null) {
- $context = context_system::instance();
+ $context = \context_system::instance();
}
if (is_object($context)) {
$context = $context->id;
@@ -62,7 +60,7 @@ class core_course_category_testcase extends advanced_testcase {
protected function assign_capability($capability, $permission = CAP_ALLOW, $contextid = null) {
if ($contextid === null) {
- $contextid = context_system::instance();
+ $contextid = \context_system::instance();
}
if (is_object($contextid)) {
$contextid = $contextid->id;
@@ -73,7 +71,7 @@ class core_course_category_testcase extends advanced_testcase {
public function test_create_coursecat() {
// Create the category.
- $data = new stdClass();
+ $data = new \stdClass();
$data->name = 'aaa';
$data->description = 'aaa';
$data->idnumber = '';
@@ -102,27 +100,27 @@ class core_course_category_testcase extends advanced_testcase {
try {
core_course_category::create(array('name' => ''));
$this->fail('Missing category name exception expected in core_course_category::create');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertInstanceOf('moodle_exception', $e);
}
$cat1 = core_course_category::create(array('name' => 'Cat1', 'idnumber' => '1'));
try {
$cat1->update(array('name' => ''));
$this->fail('Missing category name exception expected in core_course_category::update');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertInstanceOf('moodle_exception', $e);
}
try {
core_course_category::create(array('name' => 'Cat2', 'idnumber' => '1'));
$this->fail('Duplicate idnumber exception expected in core_course_category::create');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertInstanceOf('moodle_exception', $e);
}
$cat2 = core_course_category::create(array('name' => 'Cat2', 'idnumber' => '2'));
try {
$cat2->update(array('idnumber' => '1'));
$this->fail('Duplicate idnumber exception expected in core_course_category::update');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertInstanceOf('moodle_exception', $e);
}
// Test that duplicates with an idnumber of 0 cannot be created.
@@ -130,14 +128,14 @@ class core_course_category_testcase extends advanced_testcase {
try {
core_course_category::create(array('name' => 'Cat4', 'idnumber' => '0'));
$this->fail('Duplicate idnumber "0" exception expected in core_course_category::create');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertInstanceOf('moodle_exception', $e);
}
// Test an update cannot make a duplicate idnumber of 0.
try {
$cat2->update(array('idnumber' => '0'));
$this->fail('Duplicate idnumber "0" exception expected in core_course_category::update');
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->assertInstanceOf('moodle_exception', $e);
}
}
@@ -233,7 +231,7 @@ class core_course_category_testcase extends advanced_testcase {
try {
$category2->change_parent($category4->id);
$this->fail('Exception expected - can not move category');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertInstanceOf('moodle_exception', $e);
}
@@ -254,7 +252,7 @@ class core_course_category_testcase extends advanced_testcase {
$this->assertSame($testdescription, $category1->description);
$category1 = core_course_category::get($category1->id);
$this->assertSame($testdescription, $category1->description);
- cache_helper::purge_by_event('changesincoursecat');
+ \cache_helper::purge_by_event('changesincoursecat');
$category1 = core_course_category::get($category1->id);
$this->assertSame($testdescription, $category1->description);
@@ -296,7 +294,7 @@ class core_course_category_testcase extends advanced_testcase {
// Delete category 2 and move content to category 3.
$this->assertFalse($category2->can_move_content_to($category3->id)); // No luck!
// Add necessary capabilities.
- $this->assign_capability('moodle/course:create', CAP_ALLOW, context_coursecat::instance($category3->id));
+ $this->assign_capability('moodle/course:create', CAP_ALLOW, \context_coursecat::instance($category3->id));
$this->assign_capability('moodle/category:manage');
$this->assertTrue($category2->can_move_content_to($category3->id)); // Hurray!
$category2->delete_move($category3->id);
@@ -321,7 +319,7 @@ class core_course_category_testcase extends advanced_testcase {
// Delete category 3 completely.
$this->assertFalse($category3->can_delete_full()); // No luck!
// Add necessary capabilities.
- $this->assign_capability('moodle/course:delete', CAP_ALLOW, context_coursecat::instance($category3->id));
+ $this->assign_capability('moodle/course:delete', CAP_ALLOW, \context_coursecat::instance($category3->id));
$this->assertTrue($category3->can_delete_full()); // Hurray!
$category3->delete_full();
@@ -373,7 +371,7 @@ class core_course_category_testcase extends advanced_testcase {
$this->assertEquals(array($category2->id, $category7->id, $category6->id, $category4->id), array_keys($children));
// Check that everything is all right after purging the caches.
- cache_helper::purge_by_event('changesincoursecat');
+ \cache_helper::purge_by_event('changesincoursecat');
$children = $category1->get_children();
$this->assertEquals(array($category2->id, $category4->id, $category6->id, $category7->id), array_keys($children));
$this->assertEquals(4, $category1->get_children_count());
@@ -427,7 +425,7 @@ class core_course_category_testcase extends advanced_testcase {
$this->assertEquals($numcategories + 3, core_course_category::count_all());
$this->assertDebuggingCalled('Method core_course_category::count_all() is deprecated. Please use ' .
'core_course_category::is_simple_site()', DEBUG_DEVELOPER);
- cache_helper::purge_by_event('changesincoursecat');
+ \cache_helper::purge_by_event('changesincoursecat');
// We should still have 4.
$this->assertEquals($numcategories + 3, core_course_category::count_all());
$this->assertDebuggingCalled('Method core_course_category::count_all() is deprecated. Please use ' .
@@ -503,11 +501,11 @@ class core_course_category_testcase extends advanced_testcase {
try {
// Enable the multilang filter and set it to apply to headings and content.
- filter_manager::reset_caches();
+ \filter_manager::reset_caches();
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', true);
$expected = array($c3, $c4, $c1, $c2);
- } catch (coding_exception $ex) {
+ } catch (\coding_exception $ex) {
$expected = array($c3, $c4, $c2, $c1);
}
$this->assertTrue($coursecat->resort_courses('fullname'));
@@ -583,7 +581,7 @@ class core_course_category_testcase extends advanced_testcase {
$this->setUser($this->getDataGenerator()->create_user());
// Add necessary capabilities.
- $this->assign_capability('moodle/course:create', CAP_ALLOW, context_coursecat::instance($cat2->id));
+ $this->assign_capability('moodle/course:create', CAP_ALLOW, \context_coursecat::instance($cat2->id));
// Do another search with restricted capabilities.
$reqcaps = array('moodle/course:create');
$res = core_course_category::search_courses(array('search' => 'test'), array(), $reqcaps);
@@ -650,27 +648,27 @@ class core_course_category_testcase extends advanced_testcase {
}
// Cat1 (user2 has teacher role)
- role_assign($teacherrole->id, $user[2], context_coursecat::instance($category[1]));
+ role_assign($teacherrole->id, $user[2], \context_coursecat::instance($category[1]));
// course21 (user2 is enrolled as manager)
$manual->enrol_user($enrol[2][1], $user[2], $managerrole->id);
// course22 (user2 is enrolled as student)
$manual->enrol_user($enrol[2][2], $user[2], $studentrole->id);
// Cat4 (user2 has manager role)
- role_assign($managerrole->id, $user[2], context_coursecat::instance($category[4]));
+ role_assign($managerrole->id, $user[2], \context_coursecat::instance($category[4]));
// course41 (user4 is enrolled as teacher, user5 is enrolled as manager)
$manual->enrol_user($enrol[4][1], $user[4], $teacherrole->id);
$manual->enrol_user($enrol[4][1], $user[5], $managerrole->id);
// course42 (user2 is enrolled as teacher)
$manual->enrol_user($enrol[4][2], $user[2], $teacherrole->id);
// Cat3 (user3 has manager role)
- role_assign($managerrole->id, $user[3], context_coursecat::instance($category[3]));
+ role_assign($managerrole->id, $user[3], \context_coursecat::instance($category[3]));
// course31 (user3 is enrolled as student)
$manual->enrol_user($enrol[3][1], $user[3], $studentrole->id);
// course11 (user1 is enrolled as teacher)
$manual->enrol_user($enrol[1][1], $user[1], $teacherrole->id);
// -- course12 (user1 has teacher role)
// also user4 is enrolled as teacher but enrolment is not active
- role_assign($teacherrole->id, $user[1], context_course::instance($course[1][2]));
+ role_assign($teacherrole->id, $user[1], \context_course::instance($course[1][2]));
$manual->enrol_user($enrol[1][2], $user[4], $teacherrole->id, 0, 0, ENROL_USER_SUSPENDED);
$allcourses = core_course_category::get(0)->get_courses(
@@ -798,29 +796,29 @@ class core_course_category_testcase extends advanced_testcase {
}
// Cat1: user2 has teacher role.
- role_assign($teacherrole->id, $user[2], context_coursecat::instance($category[1]));
+ role_assign($teacherrole->id, $user[2], \context_coursecat::instance($category[1]));
// Course21: user2 is enrolled as manager.
$manual->enrol_user($enrol[2][1], $user[2], $managerrole->id);
// Course22: user2 is enrolled as student.
$manual->enrol_user($enrol[2][2], $user[2], $studentrole->id);
// Cat4: user2 has manager role.
- role_assign($managerrole->id, $user[2], context_coursecat::instance($category[4]));
+ role_assign($managerrole->id, $user[2], \context_coursecat::instance($category[4]));
// Course41: user4 is enrolled as teacher, user5 is enrolled as manager.
$manual->enrol_user($enrol[4][1], $user[4], $teacherrole->id);
$manual->enrol_user($enrol[4][1], $user[5], $managerrole->id);
// Course42: user2 is enrolled as teacher.
$manual->enrol_user($enrol[4][2], $user[2], $teacherrole->id);
// Cat3: user3 has manager role.
- role_assign($managerrole->id, $user[3], context_coursecat::instance($category[3]));
+ role_assign($managerrole->id, $user[3], \context_coursecat::instance($category[3]));
// Course31: user3 is enrolled as student.
$manual->enrol_user($enrol[3][1], $user[3], $studentrole->id);
// Course11: user1 is enrolled as teacher and user4 is enrolled as teacher and has manager role.
$manual->enrol_user($enrol[1][1], $user[1], $teacherrole->id);
$manual->enrol_user($enrol[1][1], $user[4], $teacherrole->id);
- role_assign($managerrole->id, $user[4], context_course::instance($course[1][1]));
+ role_assign($managerrole->id, $user[4], \context_course::instance($course[1][1]));
// Course12: user1 has teacher role, but is not enrolled, as well as user4 is enrolled as teacher, but user4's enrolment is
// not active.
- role_assign($teacherrole->id, $user[1], context_course::instance($course[1][2]));
+ role_assign($teacherrole->id, $user[1], \context_course::instance($course[1][2]));
$manual->enrol_user($enrol[1][2], $user[4], $teacherrole->id, 0, 0, ENROL_USER_SUSPENDED);
$allcourses = core_course_category::get(0)->get_courses(
@@ -1068,7 +1066,7 @@ class core_course_category_testcase extends advanced_testcase {
*/
protected function fill_draft_area(array $files) {
global $USER;
- $usercontext = context_user::instance($USER->id);
+ $usercontext = \context_user::instance($USER->id);
$draftid = file_get_unused_draft_itemid();
foreach ($files as $filename => $filecontents) {
// Add actual file there.
diff --git a/course/tests/courselib_test.php b/course/tests/courselib_test.php
index 8ba54a4a01d..18f95cad224 100644
--- a/course/tests/courselib_test.php
+++ b/course/tests/courselib_test.php
@@ -14,23 +14,58 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Course related unit tests
- *
- * @package core
- * @category phpunit
- * @copyright 2012 Petr Skoda {@link http://skodak.org}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_course;
-defined('MOODLE_INTERNAL') || die();
+use advanced_testcase;
+use backup_controller;
+use backup;
+use blog_entry;
+use cache;
+use calendar_event;
+use coding_exception;
+use comment;
+use completion_criteria_date;
+use completion_completion;
+use context_course;
+use context_module;
+use context_system;
+use context_coursecat;
+use core_completion_external;
+use core_external;
+use core_tag_index_builder;
+use core_tag_tag;
+use course_capability_assignment;
+use course_request;
+use core_course_category;
+use enrol_imsenterprise\imsenterprise_test;
+use external_api;
+use grade_item;
+use grading_manager;
+use moodle_exception;
+use moodle_url;
+use phpunit_util;
+use rating_manager;
+use restore_controller;
+use stdClass;
+use testing_data_generator;
+defined('MOODLE_INTERNAL') or die();
+
+// Require library globally because it's constants are used within dataProvider methods, executed before setUpBeforeClass.
global $CFG;
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/course/tests/fixtures/course_capability_assignment.php');
require_once($CFG->dirroot . '/enrol/imsenterprise/tests/imsenterprise_test.php');
-class core_course_courselib_testcase extends advanced_testcase {
+/**
+ * Course related unit tests
+ *
+ * @package core_course
+ * @category test
+ * @copyright 2012 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class courselib_test extends advanced_testcase {
/**
* Set forum specific test values for calling create_module().
@@ -1782,7 +1817,7 @@ class core_course_courselib_testcase extends advanced_testcase {
// Create the XML file we want to use.
$course->category = (array)$course->category;
- $imstestcase = new enrol_imsenterprise_testcase();
+ $imstestcase = new imsenterprise_test();
$imstestcase->imsplugin = enrol_get_plugin('imsenterprise');
$imstestcase->set_test_config();
$imstestcase->set_xml_file(false, array($course));
diff --git a/course/tests/courserequest_test.php b/course/tests/courserequest_test.php
index fa76479026c..e47df520e4b 100644
--- a/course/tests/courserequest_test.php
+++ b/course/tests/courserequest_test.php
@@ -1,5 +1,4 @@
.
-/**
- * Course request related unit tests
- *
- * @package core
- * @category phpunit
- * @copyright 2012 Frédéric Massart
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_course;
+
+use course_request;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/course/lib.php');
-class core_course_courserequest_testcase extends advanced_testcase {
+/**
+ * Course request related unit tests
+ *
+ * @package core_course
+ * @category test
+ * @copyright 2012 Frédéric Massart
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class courserequest_test extends \advanced_testcase {
public function test_create_request() {
global $DB, $USER;
@@ -46,7 +48,7 @@ class core_course_courserequest_testcase extends advanced_testcase {
$cat3 = $this->getDataGenerator()->create_category();
// Basic course request.
- $data = new stdClass();
+ $data = new \stdClass();
$data->fullname = 'Həllo World!';
$data->shortname = 'Hi th€re!';
$data->summary_editor['text'] = 'Lorem Ipsum ©';
@@ -94,11 +96,11 @@ class core_course_courserequest_testcase extends advanced_testcase {
$requester = $this->getDataGenerator()->create_user();
$roleid = create_role('Course requestor role', 'courserequestor', '');
assign_capability('moodle/course:request', CAP_ALLOW, $roleid,
- context_system::instance()->id);
- role_assign($roleid, $requester->id, context_system::instance()->id);
+ \context_system::instance()->id);
+ role_assign($roleid, $requester->id, \context_system::instance()->id);
accesslib_clear_all_caches_for_unit_testing();
- $data = new stdClass();
+ $data = new \stdClass();
$data->fullname = 'Həllo World!';
$data->shortname = 'Hi th€re!';
$data->summary_editor['text'] = 'Lorem Ipsum ©';
@@ -151,11 +153,11 @@ class core_course_courserequest_testcase extends advanced_testcase {
$requester = $this->getDataGenerator()->create_user();
$roleid = create_role('Course requestor role', 'courserequestor', '');
assign_capability('moodle/course:request', CAP_ALLOW, $roleid,
- context_system::instance()->id);
- role_assign($roleid, $requester->id, context_system::instance()->id);
+ \context_system::instance()->id);
+ role_assign($roleid, $requester->id, \context_system::instance()->id);
accesslib_clear_all_caches_for_unit_testing();
- $data = new stdClass();
+ $data = new \stdClass();
$data->fullname = 'Həllo World!';
$data->shortname = 'Hi th€re!';
$data->summary_editor['text'] = 'Lorem Ipsum ©';
diff --git a/course/tests/management_helper_test.php b/course/tests/management_helper_test.php
index ea3c2c25206..34de099bac6 100644
--- a/course/tests/management_helper_test.php
+++ b/course/tests/management_helper_test.php
@@ -14,13 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Course and category management helper class tests.
- *
- * @package core_course
- * @copyright 2013 Sam Hemelryk
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_course;
+
+use core_course_category;
+use core_course_list_element;
+use course_capability_assignment;
defined('MOODLE_INTERNAL') || die();
@@ -29,11 +27,13 @@ require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->dirroot.'/course/tests/fixtures/course_capability_assignment.php');
/**
- * Class core_course_management_helper_test
+ * Course and category management helper class tests.
*
- * This class tests \core_course\management\helper
+ * @package core_course
+ * @copyright 2013 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_course_management_helper_test extends advanced_testcase {
+class management_helper_test extends \advanced_testcase {
/** Category management capability: moodle/category:manage */
const CATEGORY_MANAGE = 'moodle/category:manage';
@@ -51,7 +51,7 @@ class core_course_management_helper_test extends advanced_testcase {
* @param $contextid
* @return array The user object and the role ID
*/
- protected function get_user_objects(testing_data_generator $generator, $contextid) {
+ protected function get_user_objects(\testing_data_generator $generator, $contextid) {
global $USER;
if (empty($USER->id)) {
@@ -145,7 +145,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_hide($category);
$this->fail('Expected exception did not occur when trying to hide a category without permission.');
- } catch (moodle_exception $ex) {
+ } catch (\moodle_exception $ex) {
// The category must still be visible.
$cat = core_course_category::get($category->id);
$subcat = core_course_category::get($subcategory->id);
@@ -176,7 +176,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_show($category);
$this->fail('Expected exception did not occur when trying to show a category without permission.');
- } catch (moodle_exception $ex) {
+ } catch (\moodle_exception $ex) {
// The category must still be hidden.
$cat = core_course_category::get($category->id);
$subcat = core_course_category::get($subcategory->id);
@@ -223,7 +223,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_hide($category);
$this->fail('Expected exception did not occur when trying to hide a category without permission.');
- } catch (moodle_exception $ex) {
+ } catch (\moodle_exception $ex) {
// The category must still be visible.
$this->assertEquals(1, core_course_category::get($category->id)->visible);
}
@@ -303,7 +303,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_hide_by_id($category->id);
$this->fail('Expected exception did not occur when trying to hide a category without permission.');
- } catch (moodle_exception $ex) {
+ } catch (\moodle_exception $ex) {
// The category must still be visible.
$cat = core_course_category::get($category->id);
$subcat = core_course_category::get($subcategory->id);
@@ -333,7 +333,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_show_by_id($category->id);
$this->fail('Expected exception did not occur when trying to show a category without permission.');
- } catch (moodle_exception $ex) {
+ } catch (\moodle_exception $ex) {
// The category must still be hidden.
$cat = core_course_category::get($category->id);
$subcat = core_course_category::get($subcategory->id);
@@ -380,7 +380,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_hide_by_id($category->id);
$this->fail('Expected exception did not occur when trying to hide a category without permission.');
- } catch (moodle_exception $ex) {
+ } catch (\moodle_exception $ex) {
// The category must still be visible.
$this->assertEquals(1, core_course_category::get($category->id)->visible);
}
@@ -403,7 +403,7 @@ class core_course_management_helper_test extends advanced_testcase {
$course3 = $generator->create_course(array('category' => $sub1->id));
$course4 = $generator->create_course(array('category' => $cat2->id));
- $syscontext = context_system::instance();
+ $syscontext = \context_system::instance();
list($user, $roleid) = $this->get_user_objects($generator, $syscontext->id);
@@ -456,7 +456,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_move_courses_into($cat2, $sub2, array($course4->id));
$this->fail('Moved a course from a category it wasn\'t within');
- } catch (moodle_exception $exception) {
+ } catch (\moodle_exception $exception) {
// Check that everything is as it was.
$this->assertEquals(1, $cat1->get_courses_count());
$this->assertEquals(0, $cat2->get_courses_count());
@@ -468,7 +468,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_move_courses_into($cat2, $sub2, array($course4->id, $course1->id));
$this->fail('Moved a course from a category it wasn\'t within');
- } catch (moodle_exception $exception) {
+ } catch (\moodle_exception $exception) {
// Check that everything is as it was. Nothing should have been moved.
$this->assertEquals(1, $cat1->get_courses_count());
$this->assertEquals(0, $cat2->get_courses_count());
@@ -494,7 +494,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_move_courses_into($sub1, $sub2, array($course2->id));
$this->fail('Invalid move of course between categories, action can\'t be undone.');
- } catch (moodle_exception $ex) {
+ } catch (\moodle_exception $ex) {
$this->assertEquals(get_string('cannotmovecourses', 'error'), $ex->getMessage());
}
// Nothing should have changed.
@@ -509,7 +509,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_move_courses_into($sub2, $cat2, array($course4->id));
$this->fail('Invalid move of course between categories, action can\'t be undone.');
- } catch (moodle_exception $ex) {
+ } catch (\moodle_exception $ex) {
$this->assertEquals(get_string('cannotmovecourses', 'error'), $ex->getMessage());
}
// Nothing should have changed.
@@ -534,7 +534,7 @@ class core_course_management_helper_test extends advanced_testcase {
$cat2 = $generator->create_category(array('parent' => $parent->id, 'name' => 'Two'));
$cat3 = $generator->create_category(array('parent' => $parent->id, 'name' => 'Three'));
- $syscontext = context_system::instance();
+ $syscontext = \context_system::instance();
list($user, $roleid) = $this->get_user_objects($generator, $syscontext->id);
course_capability_assignment::allow(self::CATEGORY_MANAGE, $roleid, $syscontext->id);
@@ -636,7 +636,7 @@ class core_course_management_helper_test extends advanced_testcase {
course_capability_assignment::prevent(self::CATEGORY_MANAGE, $roleid, $parent->get_context()->id);
try {
\core_course\management\helper::action_category_change_sortorder_up_one($cat1);
- } catch (moodle_exception $exception) {
+ } catch (\moodle_exception $exception) {
// Check everything is still where it should be.
$this->assertEquals(
array('Three', 'One', 'Two'),
@@ -645,7 +645,7 @@ class core_course_management_helper_test extends advanced_testcase {
}
try {
\core_course\management\helper::action_category_change_sortorder_down_one($cat3);
- } catch (moodle_exception $exception) {
+ } catch (\moodle_exception $exception) {
// Check everything is still where it should be.
$this->assertEquals(
array('Three', 'One', 'Two'),
@@ -671,7 +671,7 @@ class core_course_management_helper_test extends advanced_testcase {
'shortname' => 'Beginning Jade', 'idnumber' => '10003'));
$course3 = $generator->create_course(array('category' => $category->id, 'fullname' => 'Advanced algebra',
'shortname' => 'Advanced algebra', 'idnumber' => '10002'));
- $syscontext = context_system::instance();
+ $syscontext = \context_system::instance();
// Update category object from DB so the course count is correct.
$category = core_course_category::get($category->id);
@@ -713,7 +713,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_resort_courses($category, 'category');
$this->fail('Category courses resorted by invalid sort field.');
- } catch (coding_exception $exception) {
+ } catch (\coding_exception $exception) {
// Test things are as they were before.
$courses = $category->get_courses();
$this->assertIsArray($courses);
@@ -726,7 +726,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_resort_courses($category, 'monkeys');
$this->fail('Category courses resorted by completely ridiculous field.');
- } catch (coding_exception $exception) {
+ } catch (\coding_exception $exception) {
// Test things are as they were before.
$courses = $category->get_courses();
$this->assertIsArray($courses);
@@ -744,7 +744,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_resort_courses($category, 'shortname');
$this->fail('Courses sorted without having the required permission.');
- } catch (moodle_exception $exception) {
+ } catch (\moodle_exception $exception) {
// Check its the right exception.
$this->assertEquals('core_course_category::can_resort', $exception->debuginfo);
// Test things are as they were before.
@@ -771,7 +771,7 @@ class core_course_management_helper_test extends advanced_testcase {
$cat2 = $generator->create_category(array('parent' => $parent->id, 'name' => 'School of Commerce', 'idnumber' => '10003'));
$cat3 = $generator->create_category(array('parent' => $parent->id, 'name' => 'School of Arts', 'idnumber' => '10002'));
- $syscontext = context_system::instance();
+ $syscontext = \context_system::instance();
list($user, $roleid) = $this->get_user_objects($generator, $syscontext->id);
$caps = course_capability_assignment::allow(self::CATEGORY_MANAGE, $roleid, $syscontext->id);
@@ -800,7 +800,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_resort_subcategories($parent, 'summary');
$this->fail('Categories resorted by invalid field.');
- } catch (coding_exception $exception) {
+ } catch (\coding_exception $exception) {
// Check that nothing was changed.
$categories = $parent->get_children();
$this->assertIsArray($categories);
@@ -813,7 +813,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_resort_subcategories($parent, 'monkeys');
$this->fail('Categories resorted by completely bogus field.');
- } catch (coding_exception $exception) {
+ } catch (\coding_exception $exception) {
// Check that nothing was changed.
$categories = $parent->get_children();
$this->assertIsArray($categories);
@@ -839,7 +839,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_category_resort_subcategories($parent, 'idnumber');
$this->fail('Categories sorted without having the required permission.');
- } catch (moodle_exception $exception) {
+ } catch (\moodle_exception $exception) {
// Check its the right exception.
$this->assertEquals('core_course_category::can_resort', $exception->debuginfo);
// Test things are as they were before.
@@ -864,7 +864,7 @@ class core_course_management_helper_test extends advanced_testcase {
$category = $generator->create_category();
$course = $generator->create_course();
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
list($user, $roleid) = $this->get_user_objects($generator, $coursecontext->id);
$caps = array(self::COURSE_VIEW, self::COURSE_VIEWHIDDEN);
@@ -910,7 +910,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_course_show($course);
- } catch (moodle_exception $exception) {
+ } catch (\moodle_exception $exception) {
$this->assertEquals('core_course_list_element::can_change_visbility', $exception->debuginfo);
}
}
@@ -928,7 +928,7 @@ class core_course_management_helper_test extends advanced_testcase {
$category = $generator->create_category();
$course = $generator->create_course();
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
list($user, $roleid) = $this->get_user_objects($generator, $coursecontext->id);
$caps = array(self::COURSE_VIEW, self::COURSE_VIEWHIDDEN);
@@ -974,7 +974,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::action_course_show_by_record($course);
- } catch (moodle_exception $exception) {
+ } catch (\moodle_exception $exception) {
$this->assertEquals('core_course_list_element::can_change_visbility', $exception->debuginfo);
}
}
@@ -1079,7 +1079,7 @@ class core_course_management_helper_test extends advanced_testcase {
\core_course\management\helper::action_course_change_sortorder_down_one(
new core_course_list_element(get_course($course2->id)), $category);
$this->fail('Course moved without having the required permissions.');
- } catch (moodle_exception $exception) {
+ } catch (\moodle_exception $exception) {
// Check nothing has changed.
$courses = $category->get_courses();
$this->assertIsArray($courses);
@@ -1096,11 +1096,11 @@ class core_course_management_helper_test extends advanced_testcase {
global $PAGE;
$this->resetAfterTest(true);
- $PAGE->set_url(new moodle_url('/course/management.php'));
+ $PAGE->set_url(new \moodle_url('/course/management.php'));
$generator = $this->getDataGenerator();
$category = $generator->create_category();
- $context = context_system::instance();
+ $context = \context_system::instance();
list($user, $roleid) = $this->get_user_objects($generator, $context->id);
course_capability_assignment::allow(array(
self::CATEGORY_MANAGE,
@@ -1133,7 +1133,7 @@ class core_course_management_helper_test extends advanced_testcase {
$generator = $this->getDataGenerator();
$category = $generator->create_category();
$course = $generator->create_course();
- $context = context_system::instance();
+ $context = \context_system::instance();
list($user, $roleid) = $this->get_user_objects($generator, $context->id);
$generator->enrol_user($user->id, $course->id, $roleid);
course_capability_assignment::allow(array(
@@ -1166,7 +1166,7 @@ class core_course_management_helper_test extends advanced_testcase {
$generator = $this->getDataGenerator();
$category = $generator->create_category();
$course = $generator->create_course();
- $context = context_system::instance();
+ $context = \context_system::instance();
list($user, $roleid) = $this->get_user_objects($generator, $context->id);
$generator->enrol_user($user->id, $course->id, $roleid);
course_capability_assignment::allow(array(
@@ -1209,7 +1209,7 @@ class core_course_management_helper_test extends advanced_testcase {
$course3 = $generator->create_course(array('category' => $sub1->id));
$course4 = $generator->create_course(array('category' => $cat2->id));
- $syscontext = context_system::instance();
+ $syscontext = \context_system::instance();
list($user, $roleid) = $this->get_user_objects($generator, $syscontext->id);
@@ -1276,7 +1276,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::move_courses_into_category($sub2->id, array($course2->id));
$this->fail('Invalid move of course between categories, action can\'t be undone.');
- } catch (moodle_exception $ex) {
+ } catch (\moodle_exception $ex) {
$this->assertEquals(get_string('cannotmovecourses', 'error'), $ex->getMessage());
}
// Nothing should have changed.
@@ -1291,7 +1291,7 @@ class core_course_management_helper_test extends advanced_testcase {
try {
\core_course\management\helper::move_courses_into_category($cat2->id, array($course4->id));
$this->fail('Invalid move of course between categories, action can\'t be undone.');
- } catch (moodle_exception $ex) {
+ } catch (\moodle_exception $ex) {
$this->assertEquals(get_string('cannotmovecourses', 'error'), $ex->getMessage());
}
// Nothing should have changed.
diff --git a/course/tests/modlib_test.php b/course/tests/modlib_test.php
index c6eab11cc9c..6e3be5a2a5b 100644
--- a/course/tests/modlib_test.php
+++ b/course/tests/modlib_test.php
@@ -14,14 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Module lib related unit tests
- *
- * @package core
- * @category phpunit
- * @copyright 2016 Juan Leyva
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_course;
defined('MOODLE_INTERNAL') || die();
@@ -29,7 +22,15 @@ global $CFG;
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/course/modlib.php');
-class core_course_modlib_testcase extends advanced_testcase {
+/**
+ * Module lib related unit tests
+ *
+ * @package core_course
+ * @category test
+ * @copyright 2016 Juan Leyva
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class modlib_test extends \advanced_testcase {
/**
* Test prepare_new_moduleinfo_data
@@ -40,7 +41,7 @@ class core_course_modlib_testcase extends advanced_testcase {
$this->setAdminUser();
$course = self::getDataGenerator()->create_course();
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
// Test with a complex module, like assign.
$assignmodule = $DB->get_record('modules', array('name' => 'assign'), '*', MUST_EXIST);
$sectionnumber = 1;
@@ -50,7 +51,7 @@ class core_course_modlib_testcase extends advanced_testcase {
$this->assertEquals($coursecontext, $context);
$this->assertNull($cm); // Not cm yet.
- $expecteddata = new stdClass();
+ $expecteddata = new \stdClass();
$expecteddata->section = $sectionnumber;
$expecteddata->visible = 1;
$expecteddata->course = $course->id;
@@ -88,7 +89,7 @@ class core_course_modlib_testcase extends advanced_testcase {
$assignmodule = $DB->get_record('modules', array('name' => 'assign'), '*', MUST_EXIST);
$assign = self::getDataGenerator()->create_module('assign', array('course' => $course->id));
$assigncm = get_coursemodule_from_id('assign', $assign->cmid);
- $assigncontext = context_module::instance($assign->cmid);
+ $assigncontext = \context_module::instance($assign->cmid);
list($cm, $context, $module, $data, $cw) = get_moduleinfo_data($assigncm, $course);
$this->assertEquals($assigncm, $cm);
@@ -114,10 +115,10 @@ class core_course_modlib_testcase extends advanced_testcase {
$expecteddata->completionusegrade = is_null($assigncm->completiongradeitemnumber) ? 0 : 1;
$expecteddata->completiongradeitemnumber = null;
$expecteddata->showdescription = $assigncm->showdescription;
- $expecteddata->tags = core_tag_tag::get_item_tags_array('core', 'course_modules', $assigncm->id);
+ $expecteddata->tags = \core_tag_tag::get_item_tags_array('core', 'course_modules', $assigncm->id);
$expecteddata->availabilityconditionsjson = null;
$expecteddata->advancedgradingmethod_submissions = null;
- if ($items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => 'assign',
+ if ($items = \grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => 'assign',
'iteminstance' => $assign->id, 'courseid' => $course->id))) {
// set category if present
$gradecat = false;
diff --git a/course/tests/targets_test.php b/course/tests/targets_test.php
index 7bd31482098..9e2e72b9823 100644
--- a/course/tests/targets_test.php
+++ b/course/tests/targets_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for core targets.
- *
- * @package core_course
- * @copyright 2019 Victor Deniz
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_course;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -39,7 +33,7 @@ require_once($CFG->dirroot . '/lib/grade/constants.php');
* @copyright 2019 Victor Deniz
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_analytics_targets_testcase extends advanced_testcase {
+class targets_test extends \advanced_testcase {
/**
* Provides course params for the {@link self::test_core_target_course_completion_analysable()} method.
@@ -48,7 +42,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
*/
public function analysable_provider() {
- $now = new DateTime("now", core_date::get_server_timezone_object());
+ $now = new \DateTime("now", \core_date::get_server_timezone_object());
$year = $now->format('Y');
$month = $now->format('m');
@@ -351,7 +345,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
try {
$course = $this->getDataGenerator()->create_course($courseparams);
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$course = $this->getDataGenerator()->create_course();
$courserecord = $courseparams;
$courserecord['id'] = $course->id;
@@ -372,7 +366,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
$cm->id => 1
]
];
- $criterion = new completion_criteria_activity();
+ $criterion = new \completion_criteria_activity();
$criterion->update_config($criteriadata);
}
@@ -405,7 +399,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
$this->resetAfterTest(true);
- $courserecord = new stdClass();
+ $courserecord = new \stdClass();
$courserecord->startdate = $coursestart;
$courserecord->enddate = $courseend;
@@ -417,7 +411,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
$analyser = new \core\analytics\analyser\student_enrolments(1, $target, [], [], []);
$analysable = new \core_analytics\course($course);
- $class = new ReflectionClass('\core\analytics\analyser\student_enrolments');
+ $class = new \ReflectionClass('\core\analytics\analyser\student_enrolments');
$method = $class->getMethod('get_all_samples');
$method->setAccessible(true);
@@ -452,7 +446,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
$analyser = new \core\analytics\analyser\student_enrolments(1, $target, [], [], []);
$analysable = new \core_analytics\course($course);
- $class = new ReflectionClass('\core\analytics\analyser\student_enrolments');
+ $class = new \ReflectionClass('\core\analytics\analyser\student_enrolments');
$method = $class->getMethod('get_all_samples');
$method->setAccessible(true);
@@ -460,7 +454,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
$target->add_sample_data($samplesdata);
$sampleid = reset($sampleids);
- $reftarget = new ReflectionObject($target);
+ $reftarget = new \ReflectionObject($target);
$refmethod = $reftarget->getMethod('calculate_sample');
$refmethod->setAccessible(true);
@@ -536,7 +530,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
$analyser = new \core\analytics\analyser\student_enrolments(1, $target, [], [], []);
$analysable = new \core_analytics\course($data['course']);
- $class = new ReflectionClass('\core\analytics\analyser\student_enrolments');
+ $class = new \ReflectionClass('\core\analytics\analyser\student_enrolments');
$method = $class->getMethod('get_all_samples');
$method->setAccessible(true);
@@ -544,7 +538,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
$target->add_sample_data($samplesdata);
$sampleid = reset($sampleids);
- $class = new ReflectionClass('\core_course\analytics\target\course_competencies');
+ $class = new \ReflectionClass('\core_course\analytics\target\course_competencies');
$method = $class->getMethod('calculate_sample');
$method->setAccessible(true);
@@ -582,7 +576,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
$this->assertEquals(get_string('gradetopassnotset', 'course'), $target->is_valid_analysable($analysable));
// Set grade to pass.
- $courseitem = grade_item::fetch_course_item($course1->id);
+ $courseitem = \grade_item::fetch_course_item($course1->id);
$courseitem->gradepass = 50;
$DB->update_record('grade_items', $courseitem);
// Since the grade to pass value is cached in the target, a new one it is instanciated.
@@ -615,7 +609,7 @@ class core_analytics_targets_testcase extends advanced_testcase {
// Expectations format being array($userid => expectation, ...)
$expectations = [];
- $courseitem = grade_item::fetch_course_item($course1->id);
+ $courseitem = \grade_item::fetch_course_item($course1->id);
// Student1 (< gradepass) fails, so it's non achieved sample.
$courseitem->update_final_grade($student1->id, 30);
$expectations[$student1->id] = 1;
@@ -634,14 +628,14 @@ class core_analytics_targets_testcase extends advanced_testcase {
$analyser = new \core\analytics\analyser\student_enrolments(1, $target, [], [], []);
$analysable = new \core_analytics\course($course1);
- $class = new ReflectionClass('\core\analytics\analyser\student_enrolments');
+ $class = new \ReflectionClass('\core\analytics\analyser\student_enrolments');
$method = $class->getMethod('get_all_samples');
$method->setAccessible(true);
list($sampleids, $samplesdata) = $method->invoke($analyser, $analysable);
$target->add_sample_data($samplesdata);
- $class = new ReflectionClass('\core_course\analytics\target\course_gradetopass');
+ $class = new \ReflectionClass('\core_course\analytics\target\course_gradetopass');
$method = $class->getMethod('calculate_sample');
$method->setAccessible(true);
diff --git a/customfield/tests/category_controller_test.php b/customfield/tests/category_controller_test.php
index 04ce151e65e..5179a4135ff 100644
--- a/customfield/tests/category_controller_test.php
+++ b/customfield/tests/category_controller_test.php
@@ -14,27 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_customfield;
+
+use core_customfield_generator;
+
/**
- * Tests for class \core_customfield\category_controller.
+ * Functional test for class \core_customfield\category_controller.
*
* @package core_customfield
* @category test
* @copyright 2018 Toni Barbera
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-use \core_customfield\category_controller;
-use \core_customfield\field_controller;
-
-/**
- * Functional test for class \core_customfield\category_controller.
- * @package core_customfield
- * @copyright 2018 Toni Barbera
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class core_customfield_category_controller_testcase extends advanced_testcase {
+class category_controller_test extends \advanced_testcase {
/**
* Get generator.
@@ -92,39 +84,39 @@ class core_customfield_category_controller_testcase extends advanced_testcase {
try {
category_controller::create($catrecord->id + 1);
$this->fail('Expected exception');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertEquals('Category not found', $e->getMessage());
- $this->assertEquals(moodle_exception::class, get_class($e));
+ $this->assertEquals(\moodle_exception::class, get_class($e));
}
// Missing required elements.
try {
category_controller::create(0, (object)['area' => 'course', 'itemid' => 0]);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Not enough parameters ' .
'to initialise category_controller - unknown component', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
// Missing required elements.
try {
category_controller::create(0, (object)['component' => 'core_course', 'itemid' => 0]);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Not enough parameters ' .
'to initialise category_controller - unknown area', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
// Missing required elements.
try {
category_controller::create(0, (object)['component' => 'core_course', 'area' => 'course']);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Not enough parameters ' .
'to initialise category_controller - unknown itemid', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
$handler = \core_course\customfield\course_handler::create();
@@ -132,39 +124,39 @@ class core_customfield_category_controller_testcase extends advanced_testcase {
try {
category_controller::create(0, (object)['component' => 'x', 'area' => 'course', 'itemid' => 0], $handler);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Component of the handler ' .
'does not match the one from the record', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
try {
category_controller::create(0, (object)['component' => 'core_course', 'area' => 'x', 'itemid' => 0], $handler);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Area of the handler ' .
'does not match the one from the record', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
try {
category_controller::create(0, (object)['component' => 'core_course', 'area' => 'course', 'itemid' => 1], $handler);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Itemid of the ' .
'handler does not match the one from the record', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
try {
$user = $this->getDataGenerator()->create_user();
category_controller::create(0, (object)['component' => 'core_course', 'area' => 'course', 'itemid' => 0,
- 'contextid' => context_user::instance($user->id)->id], $handler);
+ 'contextid' => \context_user::instance($user->id)->id], $handler);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Context of the ' .
'handler does not match the one from the record', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
}
@@ -178,12 +170,12 @@ class core_customfield_category_controller_testcase extends advanced_testcase {
// Create the category.
$lpg = $this->get_generator();
- $categorydata = new stdClass();
+ $categorydata = new \stdClass();
$categorydata->name = 'Category1';
$categorydata->component = 'core_course';
$categorydata->area = 'course';
$categorydata->itemid = 0;
- $categorydata->contextid = context_system::instance()->id;
+ $categorydata->contextid = \context_system::instance()->id;
$category = category_controller::create(0, $categorydata);
$category->save();
$this->assertNotEmpty($category->get('id'));
@@ -207,7 +199,7 @@ class core_customfield_category_controller_testcase extends advanced_testcase {
// Create the category.
$params = ['component' => 'core_course', 'area' => 'course', 'itemid' => 0, 'name' => 'Cat1',
- 'contextid' => context_system::instance()->id];
+ 'contextid' => \context_system::instance()->id];
$c1 = category_controller::create(0, (object)$params);
$c1->save();
$this->assertNotEmpty($c1->get('id'));
diff --git a/customfield/tests/data_controller_test.php b/customfield/tests/data_controller_test.php
index d125c5c9c21..56b86c2e4d7 100644
--- a/customfield/tests/data_controller_test.php
+++ b/customfield/tests/data_controller_test.php
@@ -14,25 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_customfield;
+
+use core_customfield_generator;
+use customfield_checkbox;
+use customfield_date;
+use customfield_select;
+use customfield_text;
+use customfield_textarea;
+
/**
- * Tests for class data_controller.
+ * Functional test for class data_controller.
*
* @package core_customfield
* @category test
* @copyright 2018 Toni Barbera
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-use core_customfield\data_controller;
-
-/**
- * Functional test for class data_controller.
- * @copyright 2018 Toni Barbera
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class core_customfield_data_controller_testcase extends advanced_testcase {
+class data_controller_test extends \advanced_testcase {
/**
* Get generator.
@@ -55,7 +54,7 @@ class core_customfield_data_controller_testcase extends advanced_testcase {
$category0 = $this->get_generator()->create_category(['name' => 'aaaa']);
// Add fields to this category.
- $fielddata = new stdClass();
+ $fielddata = new \stdClass();
$fielddata->categoryid = $category0->get('id');
$fielddata->configdata = "{\"required\":\"0\",\"uniquevalues\":\"0\",\"locked\":\"0\",\"visibility\":\"0\",
\"defaultvalue\":\"\",\"displaysize\":0,\"maxlength\":0,\"ispassword\":\"0\",
@@ -72,7 +71,7 @@ class core_customfield_data_controller_testcase extends advanced_testcase {
$fielddata->type = 'textarea';
$field4 = $this->get_generator()->create_field($fielddata);
- $params = ['instanceid' => $course->id, 'contextid' => context_course::instance($course->id)->id];
+ $params = ['instanceid' => $course->id, 'contextid' => \context_course::instance($course->id)->id];
// Generate new data_controller records for these fields, specifying field controller or fieldid or both.
$data0 = data_controller::create(0, (object)$params, $field0);
@@ -125,7 +124,7 @@ class core_customfield_data_controller_testcase extends advanced_testcase {
$field = $this->get_generator()->create_field(['categoryid' => $category->get('id')]);
$course = $this->getDataGenerator()->create_course();
$data = data_controller::create(0, (object)['instanceid' => $course->id,
- 'contextid' => context_course::instance($course->id)->id], $field);
+ 'contextid' => \context_course::instance($course->id)->id], $field);
$data->save();
$datarecord = $DB->get_record(\core_customfield\data::TABLE, ['id' => $data->get('id')], '*', MUST_EXIST);
@@ -143,29 +142,29 @@ class core_customfield_data_controller_testcase extends advanced_testcase {
try {
data_controller::create($datarecord->id + 1);
$this->fail('Expected exception');
- } catch (dml_missing_record_exception $e) {
+ } catch (\dml_missing_record_exception $e) {
$this->assertStringMatchesFormat('Can\'t find data record in database table customfield_data%a', $e->getMessage());
- $this->assertEquals(dml_missing_record_exception::class, get_class($e));
+ $this->assertEquals(\dml_missing_record_exception::class, get_class($e));
}
// Missing field id.
try {
data_controller::create(0, (object)['instanceid' => $course->id]);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Not enough parameters to ' .
'initialise data_controller - unknown field', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
// Mismatching field id.
try {
data_controller::create(0, (object)['instanceid' => $course->id, 'fieldid' => $field->get('id') + 1], $field);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Field id from the record ' .
'does not match field from the parameter', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
// Nonexisting class.
@@ -173,9 +172,9 @@ class core_customfield_data_controller_testcase extends advanced_testcase {
$field->set('type', 'invalid');
data_controller::create(0, (object)['instanceid' => $course->id], $field);
$this->fail('Expected exception');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertEquals('Field type invalid not found', $e->getMessage());
- $this->assertEquals(moodle_exception::class, get_class($e));
+ $this->assertEquals(\moodle_exception::class, get_class($e));
}
}
}
diff --git a/customfield/tests/field_controller_test.php b/customfield/tests/field_controller_test.php
index a642919e262..1600310d067 100644
--- a/customfield/tests/field_controller_test.php
+++ b/customfield/tests/field_controller_test.php
@@ -14,19 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests for class \core_customfield\field_controller.
- *
- * @package core_customfield
- * @category test
- * @copyright 2018 Ruslan Kabalin
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_customfield;
-defined('MOODLE_INTERNAL') || die();
-
-use \core_customfield\category_controller;
-use \core_customfield\field_controller;
+use core_customfield_generator;
+use customfield_checkbox;
+use customfield_date;
+use customfield_select;
+use customfield_text;
+use customfield_textarea;
/**
* Functional test for class \core_customfield\field_controller.
@@ -36,7 +31,7 @@ use \core_customfield\field_controller;
* @copyright 2018 Ruslan Kabalin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_customfield_field_controller_testcase extends advanced_testcase {
+class field_controller_test extends \advanced_testcase {
/**
* Get generator.
@@ -120,48 +115,48 @@ class core_customfield_field_controller_testcase extends advanced_testcase {
try {
field_controller::create($fieldrecord->id + 1);
$this->fail('Expected exception');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertEquals('Field not found', $e->getMessage());
- $this->assertEquals(moodle_exception::class, get_class($e));
+ $this->assertEquals(\moodle_exception::class, get_class($e));
}
// Retrieve without id and without type.
try {
field_controller::create(0, (object)['name' => 'a'], $category);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Not enough parameters to ' .
'initialise field_controller - unknown field type', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
// Missing category id.
try {
field_controller::create(0, (object)['type' => 'text']);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Not enough parameters ' .
'to initialise field_controller - unknown category', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
// Mismatching category id.
try {
field_controller::create(0, (object)['type' => 'text', 'categoryid' => $category->get('id') + 1], $category);
$this->fail('Expected exception');
- } catch (coding_exception $e) {
+ } catch (\coding_exception $e) {
$this->assertEquals('Coding error detected, it must be fixed by a programmer: Category of the field ' .
'does not match category from the parameter', $e->getMessage());
- $this->assertEquals(coding_exception::class, get_class($e));
+ $this->assertEquals(\coding_exception::class, get_class($e));
}
// Non-existing type.
try {
field_controller::create(0, (object)['type' => 'nonexisting'], $category);
$this->fail('Expected exception');
- } catch (moodle_exception $e) {
+ } catch (\moodle_exception $e) {
$this->assertEquals('Field type nonexisting not found', $e->getMessage());
- $this->assertEquals(moodle_exception::class, get_class($e));
+ $this->assertEquals(\moodle_exception::class, get_class($e));
}
}
@@ -181,7 +176,7 @@ class core_customfield_field_controller_testcase extends advanced_testcase {
$this->assertCount(0, $fields);
// Create field.
- $fielddata = new stdClass();
+ $fielddata = new \stdClass();
$fielddata->name = 'Field';
$fielddata->shortname = 'field';
$fielddata->type = 'text';
diff --git a/enrol/flatfile/tests/flatfile_test.php b/enrol/flatfile/tests/flatfile_test.php
index 8f48e3751a3..74bdd992761 100644
--- a/enrol/flatfile/tests/flatfile_test.php
+++ b/enrol/flatfile/tests/flatfile_test.php
@@ -18,15 +18,24 @@
* flatfile enrolment sync tests.
*
* @package enrol_flatfile
- * @category phpunit
+ * @category test
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
+namespace enrol_flatfile;
+use enrol_flatfile\task\flatfile_sync_task;
-class enrol_flatfile_testcase extends advanced_testcase {
+/**
+ * flatfile enrolment sync tests.
+ *
+ * @package enrol_flatfile
+ * @category test
+ * @copyright 2012 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class flatfile_test extends \advanced_testcase {
protected function enable_plugin() {
$enabled = enrol_get_plugins(true);
@@ -56,9 +65,9 @@ class enrol_flatfile_testcase extends advanced_testcase {
$flatfileplugin = enrol_get_plugin('flatfile');
// Just make sure the sync does not throw any errors when nothing to do.
- $flatfileplugin->sync(new null_progress_trace());
+ $flatfileplugin->sync(new \null_progress_trace());
$this->enable_plugin();
- $flatfileplugin->sync(new null_progress_trace());
+ $flatfileplugin->sync(new \null_progress_trace());
}
public function test_sync() {
@@ -71,7 +80,7 @@ class enrol_flatfile_testcase extends advanced_testcase {
$manualplugin = enrol_get_plugin('manual');
$this->assertNotEmpty($manualplugin);
- $trace = new null_progress_trace();
+ $trace = new \null_progress_trace();
$this->enable_plugin();
$file = "$CFG->dataroot/enrol.txt";
@@ -93,9 +102,9 @@ class enrol_flatfile_testcase extends advanced_testcase {
$course1 = $this->getDataGenerator()->create_course(array('idnumber'=>'c1'));
$course2 = $this->getDataGenerator()->create_course(array('idnumber'=>'c2'));
$course3 = $this->getDataGenerator()->create_course(array('idnumber'=>'c3'));
- $context1 = context_course::instance($course1->id);
- $context2 = context_course::instance($course2->id);
- $context3 = context_course::instance($course3->id);
+ $context1 = \context_course::instance($course1->id);
+ $context2 = \context_course::instance($course2->id);
+ $context3 = \context_course::instance($course3->id);
$maninstance1 = $DB->get_record('enrol', array('courseid'=>$course1->id, 'enrol'=>'manual'), '*', MUST_EXIST);
$maninstance2 = $DB->get_record('enrol', array('courseid'=>$course2->id, 'enrol'=>'manual'), '*', MUST_EXIST);
@@ -167,7 +176,7 @@ class enrol_flatfile_testcase extends advanced_testcase {
// Test encoding.
$data = "add;student;čtvrtý;c3";
- $data = core_text::convert($data, 'utf-8', 'iso-8859-2');
+ $data = \core_text::convert($data, 'utf-8', 'iso-8859-2');
file_put_contents($file, $data);
$flatfileplugin->set_config('encoding', 'iso-8859-2');
@@ -282,7 +291,7 @@ class enrol_flatfile_testcase extends advanced_testcase {
$this->enable_plugin();
- $trace = new progress_trace_buffer(new text_progress_trace(), false);
+ $trace = new \progress_trace_buffer(new \text_progress_trace(), false);
$file = "$CFG->dataroot/enrol.txt";
$flatfileplugin->set_config('location', $file);
@@ -298,8 +307,8 @@ class enrol_flatfile_testcase extends advanced_testcase {
$course1 = $this->getDataGenerator()->create_course(array('idnumber'=>'c1'));
$course2 = $this->getDataGenerator()->create_course(array('idnumber'=>'c2'));
- $context1 = context_course::instance($course1->id);
- $context2 = context_course::instance($course2->id);
+ $context1 = \context_course::instance($course1->id);
+ $context2 = \context_course::instance($course2->id);
$maninstance1 = $DB->get_record('enrol', array('courseid'=>$course1->id, 'enrol'=>'manual'), '*', MUST_EXIST);
@@ -366,7 +375,7 @@ class enrol_flatfile_testcase extends advanced_testcase {
$this->assertNotEmpty($manualplugin);
$now = time();
- $trace = new null_progress_trace();
+ $trace = new \null_progress_trace();
$this->enable_plugin();
@@ -386,8 +395,8 @@ class enrol_flatfile_testcase extends advanced_testcase {
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
- $context1 = context_course::instance($course1->id);
- $context2 = context_course::instance($course2->id);
+ $context1 = \context_course::instance($course1->id);
+ $context2 = \context_course::instance($course2->id);
$data = array('roleid'=>$studentrole->id, 'courseid'=>$course1->id);
$id = $flatfileplugin->add_instance($course1, $data);
@@ -477,7 +486,7 @@ class enrol_flatfile_testcase extends advanced_testcase {
$flatfileplugin = enrol_get_plugin('flatfile');
- $trace = new null_progress_trace();
+ $trace = new \null_progress_trace();
$this->enable_plugin();
$file = "$CFG->dataroot/enrol.txt";
$flatfileplugin->set_config('location', $file);
@@ -487,13 +496,13 @@ class enrol_flatfile_testcase extends advanced_testcase {
$user1 = $this->getDataGenerator()->create_user(array('idnumber' => 'u1'));
$course1 = $this->getDataGenerator()->create_course(array('idnumber' => 'c1'));
- $context1 = context_course::instance($course1->id);
+ $context1 = \context_course::instance($course1->id);
$data =
"add,student,u1,c1";
file_put_contents($file, $data);
- $task = new enrol_flatfile\task\flatfile_sync_task;
+ $task = new flatfile_sync_task;
$task->execute();
$this->assertEquals(1, $DB->count_records('role_assignments', array('roleid' => $studentrole->id)));
@@ -534,7 +543,7 @@ class enrol_flatfile_testcase extends advanced_testcase {
$this->setAdminUser();
require_once($CFG->dirroot . '/enrol/locallib.php');
- $manager = new course_enrolment_manager($PAGE, $course);
+ $manager = new \course_enrolment_manager($PAGE, $course);
$userenrolments = $manager->get_user_enrolments($student->id);
$this->assertCount(1, $userenrolments);
diff --git a/enrol/imsenterprise/tests/imsenterprise_test.php b/enrol/imsenterprise/tests/imsenterprise_test.php
index bbf3e25cd00..e0056a89c4e 100644
--- a/enrol/imsenterprise/tests/imsenterprise_test.php
+++ b/enrol/imsenterprise/tests/imsenterprise_test.php
@@ -14,14 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * IMS Enterprise enrolment tests.
- *
- * @package enrol_imsenterprise
- * @category test
- * @copyright 2012 David Monllaó
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace enrol_imsenterprise;
+
+use enrol_imsenterprise_plugin;
+use enrol_imsenterprise\task\cron_task;
defined('MOODLE_INTERNAL') || die();
@@ -37,7 +33,7 @@ require_once($CFG->dirroot . '/enrol/imsenterprise/lib.php');
* @copyright 2012 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class enrol_imsenterprise_testcase extends advanced_testcase {
+class imsenterprise_test extends \advanced_testcase {
/**
* @var $imsplugin enrol_imsenterprise_plugin IMS plugin instance.
@@ -95,7 +91,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$prevnusers = $DB->count_records('user');
- $user1 = new StdClass();
+ $user1 = new \stdClass();
$user1->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$user1->username = 'u1';
$user1->email = 'u1@example.com';
@@ -117,7 +113,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$prevnusers = $DB->count_records('user');
- $user2 = new StdClass();
+ $user2 = new \stdClass();
$user2->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$user2->username = 'u2';
$user2->auth = 'cas';
@@ -146,7 +142,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
global $DB;
$user = $this->getDataGenerator()->create_user(array('idnumber' => 'test-update-user'));
- $imsuser = new stdClass();
+ $imsuser = new \stdClass();
$imsuser->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_UPDATE;
// THIS SHOULD WORK, surely?: $imsuser->username = $user->username;
// But this is required...
@@ -169,7 +165,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('imsupdateusers', false);
$user = $this->getDataGenerator()->create_user(array('idnumber' => 'test-update-user'));
- $imsuser = new stdClass();
+ $imsuser = new \stdClass();
$imsuser->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_UPDATE;
// THIS SHOULD WORK, surely?: $imsuser->username = $user->username;
// But this is required...
@@ -197,7 +193,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('imsdeleteusers', true);
$user = $this->getDataGenerator()->create_user(array('idnumber' => 'test-update-user'));
- $imsuser = new stdClass();
+ $imsuser = new \stdClass();
$imsuser->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_DELETE;
$imsuser->username = $user->username;
$imsuser->firstname = $user->firstname;
@@ -218,7 +214,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('imsdeleteusers', false);
$user = $this->getDataGenerator()->create_user(array('idnumber' => 'test-update-user'));
- $imsuser = new stdClass();
+ $imsuser = new \stdClass();
$imsuser->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_DELETE;
$imsuser->username = $user->username;
$imsuser->firstname = $user->firstname;
@@ -262,13 +258,13 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$prevncourses = $DB->count_records('course');
- $course1 = new StdClass();
+ $course1 = new \stdClass();
$course1->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course1->idnumber = 'id1';
$course1->imsshort = 'id1';
$course1->category[] = 'DEFAULT CATNAME';
- $course2 = new StdClass();
+ $course2 = new \stdClass();
$course2->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course2->idnumber = 'id2';
$course2->imsshort = 'id2';
@@ -293,13 +289,13 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('createnewcourses', false);
$prevncourses = $DB->count_records('course');
- $course1 = new StdClass();
+ $course1 = new \stdClass();
$course1->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course1->idnumber = 'id1';
$course1->imsshort = 'id1';
$course1->category[] = 'DEFAULT CATNAME';
- $course2 = new StdClass();
+ $course2 = new \stdClass();
$course2->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course2->idnumber = 'id2';
$course2->imsshort = 'id2';
@@ -327,7 +323,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$prevncourses = $DB->count_records('course');
- $course1 = new StdClass();
+ $course1 = new \stdClass();
$course1->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course1->idnumber = '';
$course1->imsshort = 'id1';
@@ -351,7 +347,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('truncatecoursecodes', $truncatelength);
$prevncourses = $DB->count_records('course');
- $course1 = new StdClass();
+ $course1 = new \stdClass();
$course1->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course1->idnumber = '123456789';
$course1->imsshort = 'id1';
@@ -377,11 +373,11 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('createnewcategories', false);
// Delete the default category, to ensure the plugin handles this gracefully.
- $defaultcat = core_course_category::get_default();
+ $defaultcat = \core_course_category::get_default();
$defaultcat->delete_full(false);
// Create an course with the IMS plugin without a category.
- $course1 = new stdClass();
+ $course1 = new \stdClass();
$course1->idnumber = 'id1';
$course1->imsshort = 'id1';
$course1->category[] = '';
@@ -405,7 +401,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('imscoursemapfullname', 'coursecode');
$this->imsplugin->set_config('imscoursemapsummary', 'coursecode');
- $course1 = new StdClass();
+ $course1 = new \stdClass();
$course1->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course1->idnumber = 'id1';
$course1->imsshort = 'description_short1';
@@ -427,7 +423,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('imscoursemapfullname', 'long');
$this->imsplugin->set_config('imscoursemapsummary', 'full');
- $course2 = new StdClass();
+ $course2 = new \stdClass();
$course2->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course2->idnumber = 'id2';
$course2->imsshort = 'description_short2';
@@ -449,7 +445,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('imscoursemapfullname', 'long');
$this->imsplugin->set_config('imscoursemapsummary', 'full');
- $course3 = new StdClass();
+ $course3 = new \stdClass();
$course3->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course3->idnumber = 'id3';
$course3->imsshort = 'description_short3';
@@ -472,7 +468,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
public function test_course_update() {
global $DB;
- $course4 = new StdClass();
+ $course4 = new \stdClass();
$course4->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course4->idnumber = 'id4';
$course4->imsshort = 'id4';
@@ -504,7 +500,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
public function test_course_delete() {
global $DB;
- $course8 = new StdClass();
+ $course8 = new \stdClass();
$course8->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course8->idnumber = 'id8';
$course8->imsshort = 'id8';
@@ -540,7 +536,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$topcat = 'DEFAULT CATNAME';
$subcat = 'DEFAULT SUB CATNAME';
- $course5 = new StdClass();
+ $course5 = new \stdClass();
$course5->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course5->idnumber = 'id5';
$course5->imsshort = 'description_short';
@@ -562,7 +558,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$topcat = 'DEFAULT CATNAME';
$subcat = 'DEFAULT SUB CATNAME TEST2';
- $course6 = new StdClass();
+ $course6 = new \stdClass();
$course6->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course6->idnumber = 'id6';
$course6->imsshort = 'description_short';
@@ -594,7 +590,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$topcat = 'DEFAULT CATNAME';
$subcat = 'DEFAULT SUB CATNAME DUPTEST';
- $course7 = new StdClass();
+ $course7 = new \stdClass();
$course7->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course7->idnumber = 'id7';
$course7->imsshort = 'description_short';
@@ -608,7 +604,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$prevncategories = $DB->count_records('course_categories');
- $course8 = new StdClass();
+ $course8 = new \stdClass();
$course8->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course8->idnumber = 'id8';
$course8->imsshort = 'description_short';
@@ -643,7 +639,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$topcat = $topcatname.$catsep.$topcatidnumber;
$subcat = $subcatname.$catsep.$subcatidnumber;
- $course1 = new StdClass();
+ $course1 = new \stdClass();
$course1->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course1->idnumber = 'id5';
$course1->imsshort = 'description_short';
@@ -674,7 +670,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$topcat = $topcatname.$catsep.$topcatidnumber;
$subcat = $subcatname.$catsep.$subcatidnumber;
- $course2 = new StdClass();
+ $course2 = new \stdClass();
$course2->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course2->idnumber = 'id6';
$course2->imsshort = 'description_short';
@@ -713,7 +709,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$topcat = $topcatname.$catsep.$topcatidnumber;
$subcat = $subcatname.$catsep.$subcatidnumber;
- $course1 = new StdClass();
+ $course1 = new \stdClass();
$course1->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course1->idnumber = 'id1';
$course1->imsshort = 'description_short';
@@ -727,7 +723,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$prevncategories = $DB->count_records('course_categories');
- $course2 = new StdClass();
+ $course2 = new \stdClass();
$course2->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course2->idnumber = 'id2';
$course2->imsshort = 'description_short';
@@ -761,7 +757,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$topcat = $topcatname.$catsep.$topcatidnumber;
$subcat = $subcatname.$catsep.$subcatidnumber;
- $course1 = new StdClass();
+ $course1 = new \stdClass();
$course1->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course1->idnumber = 'id1';
$course1->imsshort = 'description_short';
@@ -780,7 +776,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->assertFalse((boolean)$subcatid);
// Check course was put in default category.
- $defaultcat = core_course_category::get_default();
+ $defaultcat = \core_course_category::get_default();
$dbcourse = $DB->get_record('course', array('idnumber' => $course1->idnumber), '*', MUST_EXIST);
$this->assertEquals($dbcourse->category, $defaultcat->id);
@@ -792,7 +788,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
public function test_create_category_name_no_nested() {
global $DB;
- $course = new StdClass();
+ $course = new \stdClass();
$course->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course->idnumber = 'id';
$course->imsshort = 'description_short';
@@ -823,7 +819,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$catsub = $this->getDataGenerator()->create_category(array('name' => 'CAT-SUB', 'parent' => $cattop->id));
$prevcats = $DB->count_records('course_categories');
- $course = new StdClass();
+ $course = new \stdClass();
$course->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course->idnumber = 'id';
$course->imsshort = 'description_short';
@@ -856,7 +852,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('categoryseparator', '|');
$catsep = trim($this->imsplugin->get_config('categoryseparator'));
- $course = new StdClass();
+ $course = new \stdClass();
$course->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course->idnumber = 'id';
$course->imsshort = 'description_short';
@@ -898,7 +894,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
'parent' => $cattop->id));
$prevcats = $DB->count_records('course_categories');
- $course = new StdClass();
+ $course = new \stdClass();
$course->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course->idnumber = 'id';
$course->imsshort = 'description_short';
@@ -932,7 +928,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$catidnumber = '01';
- $course = new StdClass();
+ $course = new \stdClass();
$course->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course->idnumber = 'id1';
$course->imsshort = 'description_short';
@@ -948,7 +944,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->assertFalse($catid);
// Check course was put in default category.
- $defaultcat = core_course_category::get_default();
+ $defaultcat = \core_course_category::get_default();
$dbcourse = $DB->get_record('course', array('idnumber' => $course->idnumber), '*', MUST_EXIST);
$this->assertEquals($dbcourse->category, $defaultcat->id);
@@ -973,8 +969,8 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
/**
* Creates an IMS enterprise XML file and adds it's path to config settings.
*
- * @param bool|array $users false or array of users StdClass
- * @param bool|array $courses false or of courses StdClass
+ * @param bool|array $users false or array of users stdClass
+ * @param bool|array $courses false or of courses stdClass
*/
public function set_xml_file($users = false, $courses = false) {
@@ -1092,7 +1088,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
global $DB;
$prevnusers = $DB->count_records('user');
- $user1 = new StdClass();
+ $user1 = new \stdClass();
$user1->username = 'u1';
$user1->email = 'u1@example.com';
$user1->firstname = 'U';
@@ -1101,7 +1097,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$users = array($user1);
$this->set_xml_file($users);
- $task = new enrol_imsenterprise\task\cron_task();
+ $task = new cron_task();
$task->execute();
$this->assertEquals(($prevnusers + 1), $DB->count_records('user'));
diff --git a/enrol/ldap/tests/ldap_test.php b/enrol/ldap/tests/ldap_test.php
index 9893146415f..13bea0effdb 100644
--- a/enrol/ldap/tests/ldap_test.php
+++ b/enrol/ldap/tests/ldap_test.php
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace enrol_ldap;
+
/**
* LDAP enrolment plugin tests.
*
@@ -27,17 +29,11 @@
* define('TEST_ENROL_LDAP_DOMAIN', 'dc=example,dc=local');
*
* @package enrol_ldap
- * @category phpunit
+ * @category test
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-
-class enrol_ldap_testcase extends advanced_testcase {
+class ldap_test extends \advanced_testcase {
/**
* Data provider for enrol_ldap tests
@@ -210,7 +206,7 @@ class enrol_ldap_testcase extends advanced_testcase {
$this->assertEquals(0, $DB->count_records('role_assignments'));
$this->assertEquals(4, $DB->count_records('course'));
- $enrol->sync_enrolments(new null_progress_trace());
+ $enrol->sync_enrolments(new \null_progress_trace());
$this->assertEquals(8, $DB->count_records('user_enrolments'));
$this->assertEquals(8, $DB->count_records('role_assignments'));
@@ -230,7 +226,7 @@ class enrol_ldap_testcase extends advanced_testcase {
// Test course creation.
$enrol->set_config('autocreate', 1);
- $enrol->sync_enrolments(new null_progress_trace());
+ $enrol->sync_enrolments(new \null_progress_trace());
$this->assertEquals(12, $DB->count_records('user_enrolments'));
$this->assertEquals(12, $DB->count_records('role_assignments'));
@@ -253,13 +249,13 @@ class enrol_ldap_testcase extends advanced_testcase {
ldap_add($connection, 'cn='.$o['cn'].',ou=students,'.$topdn, $o);
$enrol->set_config('unenrolaction', ENROL_EXT_REMOVED_KEEP);
- $enrol->sync_enrolments(new null_progress_trace());
+ $enrol->sync_enrolments(new \null_progress_trace());
$this->assertEquals(12, $DB->count_records('user_enrolments'));
$this->assertEquals(12, $DB->count_records('role_assignments'));
$this->assertEquals(5, $DB->count_records('course'));
$enrol->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPEND);
- $enrol->sync_enrolments(new null_progress_trace());
+ $enrol->sync_enrolments(new \null_progress_trace());
$this->assertEquals(12, $DB->count_records('user_enrolments'));
$this->assertEquals(12, $DB->count_records('role_assignments'));
$this->assertEquals(5, $DB->count_records('course'));
@@ -275,7 +271,7 @@ class enrol_ldap_testcase extends advanced_testcase {
$o['memberUid'] = array('user1', 'user2', 'user3');
ldap_add($connection, 'cn='.$o['cn'].',ou=students,'.$topdn, $o);
- $enrol->sync_enrolments(new null_progress_trace());
+ $enrol->sync_enrolments(new \null_progress_trace());
$this->assertEquals(12, $DB->count_records('user_enrolments'));
$this->assertEquals(12, $DB->count_records('role_assignments'));
$this->assertEquals(5, $DB->count_records('course'));
@@ -291,7 +287,7 @@ class enrol_ldap_testcase extends advanced_testcase {
ldap_add($connection, 'cn='.$o['cn'].',ou=students,'.$topdn, $o);
$enrol->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
- $enrol->sync_enrolments(new null_progress_trace());
+ $enrol->sync_enrolments(new \null_progress_trace());
$this->assertEquals(12, $DB->count_records('user_enrolments'));
$this->assertEquals(9, $DB->count_records('role_assignments'));
$this->assertEquals(5, $DB->count_records('course'));
@@ -307,7 +303,7 @@ class enrol_ldap_testcase extends advanced_testcase {
$o['memberUid'] = array('user1', 'user2', 'user3');
ldap_add($connection, 'cn='.$o['cn'].',ou=students,'.$topdn, $o);
- $enrol->sync_enrolments(new null_progress_trace());
+ $enrol->sync_enrolments(new \null_progress_trace());
$this->assertEquals(12, $DB->count_records('user_enrolments'));
$this->assertEquals(12, $DB->count_records('role_assignments'));
$this->assertEquals(5, $DB->count_records('course'));
@@ -323,7 +319,7 @@ class enrol_ldap_testcase extends advanced_testcase {
ldap_add($connection, 'cn='.$o['cn'].',ou=students,'.$topdn, $o);
$enrol->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
- $enrol->sync_enrolments(new null_progress_trace());
+ $enrol->sync_enrolments(new \null_progress_trace());
$this->assertEquals(9, $DB->count_records('user_enrolments'));
$this->assertEquals(9, $DB->count_records('role_assignments'));
$this->assertEquals(5, $DB->count_records('course'));
@@ -437,7 +433,7 @@ class enrol_ldap_testcase extends advanced_testcase {
public function assertIsEnrolled($courseid, $userid, $roleid, $status=null) {
global $DB;
- $context = context_course::instance($courseid);
+ $context = \context_course::instance($courseid);
$instance = $DB->get_record('enrol', array('courseid'=>$courseid, 'enrol'=>'ldap'));
$this->assertNotEmpty($instance);
$ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid));
@@ -453,7 +449,7 @@ class enrol_ldap_testcase extends advanced_testcase {
}
public function assertIsNotEnrolled($courseid, $userid) {
- $context = context_course::instance($courseid);
+ $context = \context_course::instance($courseid);
$this->assertFalse(is_enrolled($context, $userid));
}
@@ -515,7 +511,7 @@ class enrol_ldap_testcase extends advanced_testcase {
$instance = enrol_get_plugin('ldap');
// Use reflection to sneak a look at the plugin.
- $rc = new ReflectionClass('enrol_ldap_plugin');
+ $rc = new \ReflectionClass('enrol_ldap_plugin');
$rcp = $rc->getProperty('userobjectclass');
$rcp->setAccessible(true);
diff --git a/enrol/lti/tests/data_connector_test.php b/enrol/lti/tests/data_connector_test.php
index 48cb7f0e483..d2e812fecd4 100644
--- a/enrol/lti/tests/data_connector_test.php
+++ b/enrol/lti/tests/data_connector_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Test the helper functionality.
- *
- * @package enrol_lti
- * @copyright 2016 Jun Pataleta
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace enrol_lti;
use enrol_lti\data_connector;
use IMSGlobal\LTI\ToolProvider\ConsumerNonce;
@@ -33,8 +27,6 @@ use IMSGlobal\LTI\ToolProvider\ToolProvider;
use IMSGlobal\LTI\ToolProvider\ToolProxy;
use IMSGlobal\LTI\ToolProvider\User;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Test the data_connector class.
*
@@ -42,7 +34,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2016 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class enrol_lti_data_connector_testcase extends advanced_testcase {
+class data_connector_test extends \advanced_testcase {
/**
* Test set up.
@@ -1145,7 +1137,7 @@ class enrol_lti_data_connector_testcase extends advanced_testcase {
$generator = $this->getDataGenerator();
// Create two tools belonging to the same course.
$course1 = $generator->create_course();
- $data = new stdClass();
+ $data = new \stdClass();
$data->courseid = $course1->id;
$tool = $generator->create_lti_tool($data);
$tool2 = $generator->create_lti_tool($data);
diff --git a/enrol/lti/tests/sync_members_test.php b/enrol/lti/tests/sync_members_test.php
index ad33d6840c2..1bf3d585d6c 100644
--- a/enrol/lti/tests/sync_members_test.php
+++ b/enrol/lti/tests/sync_members_test.php
@@ -22,10 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-use enrol_lti\data_connector;
-use enrol_lti\helper;
+namespace enrol_lti;
+
use enrol_lti\task\sync_members;
-use enrol_lti\tool_provider;
use IMSGlobal\LTI\ToolProvider\Context;
use IMSGlobal\LTI\ToolProvider\ResourceLink;
use IMSGlobal\LTI\ToolProvider\ToolConsumer;
@@ -40,11 +39,11 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2016 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class sync_members_testcase extends advanced_testcase {
+class sync_members_test extends \advanced_testcase {
/** @var dummy_sync_members_task $task */
protected $task;
- /** @var stdClass $tool The published tool. */
+ /** @var \stdClass $tool The published tool. */
protected $tool;
/** @var User[] $members */
@@ -367,12 +366,12 @@ class dummy_sync_members_task extends sync_members {
/**
* Exposes sync_members::sync_member_information()
*
- * @param stdClass $tool
+ * @param \stdClass $tool
* @param ToolConsumer $consumer
* @param User[] $members
* @return array
*/
- public function sync_member_information(stdClass $tool, ToolConsumer $consumer, $members) {
+ public function sync_member_information(\stdClass $tool, ToolConsumer $consumer, $members) {
$result = parent::sync_member_information($tool, $consumer, $members);
return $result;
}
@@ -390,10 +389,10 @@ class dummy_sync_members_task extends sync_members {
/**
* Exposes sync_members::sync_unenrol()
*
- * @param stdClass $tool
+ * @param \stdClass $tool
* @return int
*/
- public function sync_unenrol(stdClass $tool) {
+ public function sync_unenrol(\stdClass $tool) {
$count = parent::sync_unenrol($tool);
return $count;
}
diff --git a/enrol/lti/tests/tool_provider_test.php b/enrol/lti/tests/tool_provider_test.php
index 5055926d5e2..50073da97a2 100644
--- a/enrol/lti/tests/tool_provider_test.php
+++ b/enrol/lti/tests/tool_provider_test.php
@@ -22,10 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace enrol_lti;
+
use core\session\manager;
-use enrol_lti\data_connector;
-use enrol_lti\helper;
-use enrol_lti\tool_provider;
use IMSGlobal\LTI\HTTPMessage;
use IMSGlobal\LTI\ToolProvider\ResourceLink;
use IMSGlobal\LTI\ToolProvider\ToolConsumer;
@@ -41,10 +40,10 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2016 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_provider_testcase extends advanced_testcase {
+class tool_provider_test extends \advanced_testcase {
/**
- * @var stdClass $tool The LTI tool.
+ * @var \stdClass $tool The LTI tool.
*/
protected $tool;
@@ -62,7 +61,7 @@ class tool_provider_testcase extends advanced_testcase {
// Set this user as the admin.
$this->setAdminUser();
- $data = new stdClass();
+ $data = new \stdClass();
$data->enrolstartdate = time();
$data->secret = 'secret';
$toolrecord = $this->getDataGenerator()->create_lti_tool($data);
@@ -524,7 +523,7 @@ class tool_provider_testcase extends advanced_testcase {
* Builds a dummy tool provider object.
*
* @param string $secret Consumer secret.
- * @param array|stdClass $proxy Tool proxy data.
+ * @param array|\stdClass $proxy Tool proxy data.
* @param null $resourcelinksettings Key-value array for resource link settings.
* @return dummy_tool_provider
*/
diff --git a/enrol/paypal/tests/paypal_test.php b/enrol/paypal/tests/paypal_test.php
index 0fcefe58f71..b576f06e49c 100644
--- a/enrol/paypal/tests/paypal_test.php
+++ b/enrol/paypal/tests/paypal_test.php
@@ -14,19 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace enrol_paypal;
+
/**
* paypal enrolment plugin tests.
*
* @package enrol_paypal
- * @category phpunit
+ * @category test
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-
-class enrol_paypal_testcase extends advanced_testcase {
+class paypal_test extends \advanced_testcase {
protected function enable_plugin() {
$enabled = enrol_get_plugins(true);
@@ -56,7 +54,7 @@ class enrol_paypal_testcase extends advanced_testcase {
$paypalplugin = enrol_get_plugin('paypal');
// Just make sure the sync does not throw any errors when nothing to do.
- $paypalplugin->sync(new null_progress_trace());
+ $paypalplugin->sync(new \null_progress_trace());
}
public function test_expired() {
@@ -70,7 +68,7 @@ class enrol_paypal_testcase extends advanced_testcase {
$this->assertNotEmpty($manualplugin);
$now = time();
- $trace = new null_progress_trace();
+ $trace = new \null_progress_trace();
$this->enable_plugin();
@@ -90,8 +88,8 @@ class enrol_paypal_testcase extends advanced_testcase {
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
- $context1 = context_course::instance($course1->id);
- $context2 = context_course::instance($course2->id);
+ $context1 = \context_course::instance($course1->id);
+ $context2 = \context_course::instance($course2->id);
$data = array('roleid'=>$studentrole->id, 'courseid'=>$course1->id);
$id = $paypalplugin->add_instance($course1, $data);
@@ -200,7 +198,7 @@ class enrol_paypal_testcase extends advanced_testcase {
$generator->enrol_user($student->id, $course->id, 'student', $pluginname);
require_once($CFG->dirroot . '/enrol/locallib.php');
- $manager = new course_enrolment_manager($PAGE, $course);
+ $manager = new \course_enrolment_manager($PAGE, $course);
$userenrolments = $manager->get_user_enrolments($student->id);
$this->assertCount(1, $userenrolments);
diff --git a/enrol/self/tests/self_test.php b/enrol/self/tests/self_test.php
index b6b0e21acf5..99deb277c24 100644
--- a/enrol/self/tests/self_test.php
+++ b/enrol/self/tests/self_test.php
@@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace enrol_self;
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+require_once($CFG->dirroot.'/enrol/self/lib.php');
+require_once($CFG->dirroot.'/enrol/self/locallib.php');
+
/**
* Self enrolment plugin tests.
*
@@ -22,14 +30,7 @@
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->dirroot.'/enrol/self/lib.php');
-require_once($CFG->dirroot.'/enrol/self/locallib.php');
-
-class enrol_self_testcase extends advanced_testcase {
+class self_test extends \advanced_testcase {
public function test_basics() {
$this->assertTrue(enrol_is_enabled('self'));
@@ -44,7 +45,7 @@ class enrol_self_testcase extends advanced_testcase {
$selfplugin = enrol_get_plugin('self');
- $trace = new null_progress_trace();
+ $trace = new \null_progress_trace();
// Just make sure the sync does not throw any errors when nothing to do.
$selfplugin->sync($trace, null);
@@ -61,7 +62,7 @@ class enrol_self_testcase extends advanced_testcase {
$now = time();
- $trace = new progress_trace_buffer(new text_progress_trace(), false);
+ $trace = new \progress_trace_buffer(new \text_progress_trace(), false);
// Prepare some data.
@@ -83,9 +84,9 @@ class enrol_self_testcase extends advanced_testcase {
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$course3 = $this->getDataGenerator()->create_course();
- $context1 = context_course::instance($course1->id);
- $context2 = context_course::instance($course2->id);
- $context3 = context_course::instance($course3->id);
+ $context1 = \context_course::instance($course1->id);
+ $context2 = \context_course::instance($course2->id);
+ $context3 = \context_course::instance($course3->id);
$this->assertEquals(3, $DB->count_records('enrol', array('enrol'=>'self')));
$instance1 = $DB->get_record('enrol', array('courseid'=>$course1->id, 'enrol'=>'self'), '*', MUST_EXIST);
@@ -175,7 +176,7 @@ class enrol_self_testcase extends advanced_testcase {
$now = time();
- $trace = new null_progress_trace();
+ $trace = new \null_progress_trace();
// Prepare some data.
@@ -194,9 +195,9 @@ class enrol_self_testcase extends advanced_testcase {
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$course3 = $this->getDataGenerator()->create_course();
- $context1 = context_course::instance($course1->id);
- $context2 = context_course::instance($course2->id);
- $context3 = context_course::instance($course3->id);
+ $context1 = \context_course::instance($course1->id);
+ $context2 = \context_course::instance($course2->id);
+ $context3 = \context_course::instance($course3->id);
$this->assertEquals(3, $DB->count_records('enrol', array('enrol'=>'self')));
$instance1 = $DB->get_record('enrol', array('courseid'=>$course1->id, 'enrol'=>'self'), '*', MUST_EXIST);
@@ -294,7 +295,7 @@ class enrol_self_testcase extends advanced_testcase {
$now = time();
$admin = get_admin();
- $trace = new null_progress_trace();
+ $trace = new \null_progress_trace();
// Note: hopefully nobody executes the unit tests the last second before midnight...
@@ -677,10 +678,10 @@ class enrol_self_testcase extends advanced_testcase {
$user2 = $this->getDataGenerator()->create_user(['lastname' => 'Victoria']);
$user3 = $this->getDataGenerator()->create_user(['lastname' => 'Burch']);
$user4 = $this->getDataGenerator()->create_user(['lastname' => 'Cartman']);
- $noreplyuser = core_user::get_noreply_user();
+ $noreplyuser = \core_user::get_noreply_user();
$course1 = $this->getDataGenerator()->create_course();
- $context = context_course::instance($course1->id);
+ $context = \context_course::instance($course1->id);
// Get editing teacher role.
$editingteacherrole = $DB->get_record('role', ['shortname' => 'editingteacher']);
@@ -778,7 +779,7 @@ class enrol_self_testcase extends advanced_testcase {
// Login as the teacher.
$this->setUser($teacher);
require_once($CFG->dirroot . '/enrol/locallib.php');
- $manager = new course_enrolment_manager($PAGE, $course);
+ $manager = new \course_enrolment_manager($PAGE, $course);
$userenrolments = $manager->get_user_enrolments($student->id);
$this->assertCount(1, $userenrolments);
diff --git a/enrol/tests/course_enrolment_manager_test.php b/enrol/tests/course_enrolment_manager_test.php
index 488866aa60e..ce8d6a97f49 100644
--- a/enrol/tests/course_enrolment_manager_test.php
+++ b/enrol/tests/course_enrolment_manager_test.php
@@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_enrol;
+
+use course_enrolment_manager;
+
/**
* Test course_enrolment_manager parts.
*
@@ -22,19 +26,7 @@
* @copyright 2016 Ruslan Kabalin, Lancaster University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-
-/**
- * Test course_enrolment_manager parts.
- *
- * @package core
- * @category test
- * @copyright 2016 Ruslan Kabalin, Lancaster University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class core_course_enrolment_manager_testcase extends advanced_testcase {
+class course_enrolment_manager_test extends \advanced_testcase {
/**
* The course context used in tests.
* @var stdClass
@@ -260,7 +252,7 @@ class core_course_enrolment_manager_testcase extends advanced_testcase {
*
* @return stdClass Test user
*/
- protected function setup_for_user_identity_tests(): stdClass {
+ protected function setup_for_user_identity_tests(): \stdClass {
// Configure extra fields to include one normal user field and one profile field, and
// set the values for a new test user.
$generator = $this->getDataGenerator();
diff --git a/enrol/tests/role_external_test.php b/enrol/tests/role_external_test.php
index 64b63f37793..9ad70aa34ac 100644
--- a/enrol/tests/role_external_test.php
+++ b/enrol/tests/role_external_test.php
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_enrol;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -25,12 +27,12 @@ require_once($CFG->dirroot . '/enrol/externallib.php');
* Role external PHPunit tests
*
* @package core_enrol
- * @category external
+ * @category test
* @copyright 2012 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.4
*/
-class core_enrol_role_external_testcase extends externallib_advanced_testcase {
+class role_external_test extends \externallib_advanced_testcase {
/**
* Tests set up
@@ -51,20 +53,20 @@ class core_enrol_role_external_testcase extends externallib_advanced_testcase {
$course = self::getDataGenerator()->create_course();
// Set the required capabilities by the external function.
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$roleid = $this->assignUserCapability('moodle/role:assign', $context->id);
$this->assignUserCapability('moodle/course:view', $context->id, $roleid);
// Add manager role to $USER.
// So $USER is allowed to assign 'manager', 'editingteacher', 'teacher' and 'student'.
- role_assign(1, $USER->id, context_system::instance()->id);
+ role_assign(1, $USER->id, \context_system::instance()->id);
// Check the teacher role has not been assigned to $USER.
$users = get_role_users(3, $context);
$this->assertEquals(count($users), 0);
// Call the external function. Assign teacher role to $USER with contextid.
- core_role_external::assign_roles(array(
+ \core_role_external::assign_roles(array(
array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id)));
// Check the role has been assigned.
@@ -77,7 +79,7 @@ class core_enrol_role_external_testcase extends externallib_advanced_testcase {
$this->assertEquals(count($users), 0);
// Call the external function. Assign teacher role to $USER.
- core_role_external::assign_roles(array(
+ \core_role_external::assign_roles(array(
array('roleid' => 3, 'userid' => $USER->id, 'contextlevel' => "course", 'instanceid' => $course->id)));
$users = get_role_users(3, $context);
$this->assertEquals(count($users), 1);
@@ -85,7 +87,7 @@ class core_enrol_role_external_testcase extends externallib_advanced_testcase {
// Call without required capability.
$this->unassignUserCapability('moodle/role:assign', $context->id, $roleid);
$this->expectException('moodle_exception');
- $categories = core_role_external::assign_roles(
+ $categories = \core_role_external::assign_roles(
array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id));
}
@@ -100,13 +102,13 @@ class core_enrol_role_external_testcase extends externallib_advanced_testcase {
$course = self::getDataGenerator()->create_course();
// Set the required capabilities by the external function.
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$roleid = $this->assignUserCapability('moodle/role:assign', $context->id);
$this->assignUserCapability('moodle/course:view', $context->id, $roleid);
// Add manager role to $USER.
// So $USER is allowed to assign 'manager', 'editingteacher', 'teacher' and 'student'.
- role_assign(1, $USER->id, context_system::instance()->id);
+ role_assign(1, $USER->id, \context_system::instance()->id);
// Add teacher role to $USER on course context.
role_assign(3, $USER->id, $context->id);
@@ -116,7 +118,7 @@ class core_enrol_role_external_testcase extends externallib_advanced_testcase {
$this->assertEquals(count($users), 1);
// Call the external function. Unassign teacher role using contextid.
- core_role_external::unassign_roles(array(
+ \core_role_external::unassign_roles(array(
array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id)));
// Check the role has been unassigned on course context.
@@ -129,7 +131,7 @@ class core_enrol_role_external_testcase extends externallib_advanced_testcase {
$this->assertEquals(count($users), 1);
// Call the external function. Unassign teacher role using context level and instanceid.
- core_role_external::unassign_roles(array(
+ \core_role_external::unassign_roles(array(
array('roleid' => 3, 'userid' => $USER->id, 'contextlevel' => "course", 'instanceid' => $course->id)));
// Check the role has been unassigned on course context.
@@ -139,7 +141,7 @@ class core_enrol_role_external_testcase extends externallib_advanced_testcase {
// Call without required capability.
$this->unassignUserCapability('moodle/role:assign', $context->id, $roleid);
$this->expectException('moodle_exception');
- $categories = core_role_external::unassign_roles(
+ $categories = \core_role_external::unassign_roles(
array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id));
}
}
diff --git a/favourites/tests/component_favourite_service_test.php b/favourites/tests/component_favourite_service_test.php
index 42f9b32f687..a6b3092a255 100644
--- a/favourites/tests/component_favourite_service_test.php
+++ b/favourites/tests/component_favourite_service_test.php
@@ -14,24 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_favourites;
+
+use core_favourites\local\entity\favourite;
+
/**
- * Testing the service layer within core_favourites.
+ * Test class covering the component_favourite_service within the service layer of favourites.
*
* @package core_favourites
* @category test
* @copyright 2019 Jake Dallimore
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-use \core_favourites\local\entity\favourite;
-defined('MOODLE_INTERNAL') || die();
-
-/**
- * Test class covering the component_favourite_service within the service layer of favourites.
- *
- * @copyright 2019 Jake Dallimore
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class component_favourite_service_testcase extends advanced_testcase {
+class component_favourite_service_test extends \advanced_testcase {
public function setUp(): void {
$this->resetAfterTest();
@@ -45,8 +40,8 @@ class component_favourite_service_testcase extends advanced_testcase {
$user2context = \context_user::instance($user2->id);
$course1 = self::getDataGenerator()->create_course();
$course2 = self::getDataGenerator()->create_course();
- $course1context = context_course::instance($course1->id);
- $course2context = context_course::instance($course2->id);
+ $course1context = \context_course::instance($course1->id);
+ $course2context = \context_course::instance($course2->id);
return [$user1context, $user2context, $course1context, $course2context];
}
@@ -253,10 +248,10 @@ class component_favourite_service_testcase extends advanced_testcase {
$fav6 = $user2service->create_favourite('core_course', 'whatnow', $course1context->instanceid, $course1context);
// Favourite the courses again, but this time in another context.
- $fav7 = $user1service->create_favourite('core_course', 'course', $course1context->instanceid, context_system::instance());
- $fav8 = $user2service->create_favourite('core_course', 'course', $course1context->instanceid, context_system::instance());
- $fav9 = $user1service->create_favourite('core_course', 'course', $course2context->instanceid, context_system::instance());
- $fav10 = $user2service->create_favourite('core_course', 'course', $course2context->instanceid, context_system::instance());
+ $fav7 = $user1service->create_favourite('core_course', 'course', $course1context->instanceid, \context_system::instance());
+ $fav8 = $user2service->create_favourite('core_course', 'course', $course1context->instanceid, \context_system::instance());
+ $fav9 = $user1service->create_favourite('core_course', 'course', $course2context->instanceid, \context_system::instance());
+ $fav10 = $user2service->create_favourite('core_course', 'course', $course2context->instanceid, \context_system::instance());
// Get a component_favourite_service to perform the type based deletion.
$service = new \core_favourites\local\service\component_favourite_service('core_course', $repo);
diff --git a/favourites/tests/repository_test.php b/favourites/tests/repository_test.php
index d06868a379e..1488096b4c9 100644
--- a/favourites/tests/repository_test.php
+++ b/favourites/tests/repository_test.php
@@ -14,27 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_favourites;
+
+use core_favourites\local\repository\favourite_repository;
+use core_favourites\local\entity\favourite;
+
/**
- * Testing the repository objects within core_favourites.
+ * Test class covering the favourite_repository.
*
* @package core_favourites
* @category test
* @copyright 2018 Jake Dallimore
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-use \core_favourites\local\repository\favourite_repository;
-use \core_favourites\local\entity\favourite;
-
-/**
- * Test class covering the favourite_repository.
- *
- * @copyright 2018 Jake Dallimore
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class favourite_repository_testcase extends advanced_testcase {
+class repository_test extends \advanced_testcase {
public function setUp(): void {
$this->resetAfterTest();
@@ -48,8 +41,8 @@ class favourite_repository_testcase extends advanced_testcase {
$user2context = \context_user::instance($user2->id);
$course1 = self::getDataGenerator()->create_course();
$course2 = self::getDataGenerator()->create_course();
- $course1context = context_course::instance($course1->id);
- $course2context = context_course::instance($course2->id);
+ $course1context = \context_course::instance($course1->id);
+ $course2context = \context_course::instance($course2->id);
return [$user1context, $user2context, $course1context, $course2context];
}
@@ -200,7 +193,7 @@ class favourite_repository_testcase extends advanced_testcase {
// Try to get a favourite we know doesn't exist.
// We expect an exception in this case.
- $this->expectException(dml_exception::class);
+ $this->expectException(\dml_exception::class);
$favouritesrepo->find(0);
}
diff --git a/favourites/tests/user_favourite_service_test.php b/favourites/tests/user_favourite_service_test.php
index c7bd392a373..580ba3b8910 100644
--- a/favourites/tests/user_favourite_service_test.php
+++ b/favourites/tests/user_favourite_service_test.php
@@ -14,24 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_favourites;
+
+use core_favourites\local\entity\favourite;
+
/**
- * Testing the service layer within core_favourites.
+ * Test class covering the user_favourite_service within the service layer of favourites.
*
* @package core_favourites
* @category test
* @copyright 2018 Jake Dallimore
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-use \core_favourites\local\entity\favourite;
-defined('MOODLE_INTERNAL') || die();
-
-/**
- * Test class covering the user_favourite_service within the service layer of favourites.
- *
- * @copyright 2018 Jake Dallimore
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class user_favourite_service_testcase extends advanced_testcase {
+class user_favourite_service_test extends \advanced_testcase {
public function setUp(): void {
$this->resetAfterTest();
@@ -45,8 +40,8 @@ class user_favourite_service_testcase extends advanced_testcase {
$user2context = \context_user::instance($user2->id);
$course1 = self::getDataGenerator()->create_course();
$course2 = self::getDataGenerator()->create_course();
- $course1context = context_course::instance($course1->id);
- $course2context = context_course::instance($course2->id);
+ $course1context = \context_course::instance($course1->id);
+ $course2context = \context_course::instance($course2->id);
return [$user1context, $user2context, $course1context, $course2context];
}
diff --git a/files/converter/unoconv/tests/converter_test.php b/files/converter/unoconv/tests/converter_test.php
index 37808fd2d1f..90df8298b55 100644
--- a/files/converter/unoconv/tests/converter_test.php
+++ b/files/converter/unoconv/tests/converter_test.php
@@ -14,24 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Test unoconv functionality.
- *
- * @package core
- * @copyright 2016 Damyon Wiese
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace fileconverter_unoconv;
/**
* A set of tests for some of the unoconv functionality within Moodle.
*
- * @package core
+ * @package fileconverter_unoconv
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class fileconverter_unoconv_converter_testcase extends advanced_testcase {
+class converter_test extends \advanced_testcase {
/**
* Helper to skip tests which _require_ unoconv.
@@ -70,7 +62,7 @@ class fileconverter_unoconv_converter_testcase extends advanced_testcase {
// Mock the file to be converted.
$filerecord = [
- 'contextid' => context_system::instance()->id,
+ 'contextid' => \context_system::instance()->id,
'component' => 'test',
'filearea' => 'unittest',
'itemid' => 0,
diff --git a/files/tests/conversion_test.php b/files/tests/conversion_test.php
index c92ad0f4cb0..07b1f2669ca 100644
--- a/files/tests/conversion_test.php
+++ b/files/tests/conversion_test.php
@@ -14,19 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-
-/**
- * PHPUnit tests for conversion API.
- *
- * @package core_files
- * @copyright 2017 Andrew nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-use core_files\conversion;
+namespace core_files;
/**
* PHPUnit tests for conversion persistent.
@@ -35,7 +23,7 @@ use core_files\conversion;
* @copyright 2017 Andrew nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_files_conversion_testcase extends advanced_testcase {
+class conversion_test extends \advanced_testcase {
/**
* Helper to create a stored file object with the given supplied content.
@@ -47,7 +35,7 @@ class core_files_conversion_testcase extends advanced_testcase {
*/
protected function create_stored_file($filecontent = 'content', $filename = 'testfile.txt', $filerecord = []) {
$filerecord = array_merge([
- 'contextid' => context_system::instance()->id,
+ 'contextid' => \context_system::instance()->id,
'component' => 'core',
'filearea' => 'unittest',
'itemid' => 0,