- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace mod_forum;
+
+use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -34,7 +30,7 @@ require_once(__DIR__ . '/generator_trait.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \mod_forum\local\vaults\post
*/
-class mod_forum_vaults_post_testcase extends advanced_testcase {
+class vaults_post_test extends \advanced_testcase {
// Make use of the test generator trait.
use mod_forum_tests_generator_trait;
@@ -333,10 +329,10 @@ class mod_forum_vaults_post_testcase extends advanced_testcase {
[$discussion2, $post5] = $this->helper_post_to_forum($forum, $user);
$entityfactory = \mod_forum\local\container::get_entity_factory();
- $post1 = $entityfactory->get_post_from_stdclass($post1);
- $post2 = $entityfactory->get_post_from_stdclass($post2);
- $post3 = $entityfactory->get_post_from_stdclass($post3);
- $post4 = $entityfactory->get_post_from_stdclass($post4);
+ $post1 = $entityfactory->get_post_from_stdClass($post1);
+ $post2 = $entityfactory->get_post_from_stdClass($post2);
+ $post3 = $entityfactory->get_post_from_stdClass($post3);
+ $post4 = $entityfactory->get_post_from_stdClass($post4);
$entities = $this->vault->get_replies_to_post($user, $post1, false);
$this->assertCount(3, $entities);
@@ -393,15 +389,15 @@ class mod_forum_vaults_post_testcase extends advanced_testcase {
$pcaaa = $this->helper_reply_to_post($pcaa, $teacher, ['privatereplyto' => $otherstudent->id]);
$entityfactory = \mod_forum\local\container::get_entity_factory();
- $ep = $entityfactory->get_post_from_stdclass($p);
- $epa = $entityfactory->get_post_from_stdclass($pa);
- $epaa = $entityfactory->get_post_from_stdclass($paa);
- $epab = $entityfactory->get_post_from_stdclass($pab);
- $epb = $entityfactory->get_post_from_stdclass($pb);
- $epc = $entityfactory->get_post_from_stdclass($pc);
- $epca = $entityfactory->get_post_from_stdclass($pca);
- $epcaa = $entityfactory->get_post_from_stdclass($pcaa);
- $epcaaa = $entityfactory->get_post_from_stdclass($pcaaa);
+ $ep = $entityfactory->get_post_from_stdClass($p);
+ $epa = $entityfactory->get_post_from_stdClass($pa);
+ $epaa = $entityfactory->get_post_from_stdClass($paa);
+ $epab = $entityfactory->get_post_from_stdClass($pab);
+ $epb = $entityfactory->get_post_from_stdClass($pb);
+ $epc = $entityfactory->get_post_from_stdClass($pc);
+ $epca = $entityfactory->get_post_from_stdClass($pca);
+ $epcaa = $entityfactory->get_post_from_stdClass($pcaa);
+ $epcaaa = $entityfactory->get_post_from_stdClass($pcaaa);
// As `student`, you should see all public posts, plus all private replies intended for you.
$entities = $this->vault->get_replies_to_post($student, $ep, false);
@@ -1000,7 +996,7 @@ class mod_forum_vaults_post_testcase extends advanced_testcase {
[$discussion1, $post1] = $this->helper_post_to_forum($forum, $user);
- $date = new DateTime('2019-07-05');
+ $date = new \DateTime('2019-07-05');
$post2 = $this->helper_reply_to_post($post1, $user, ['created' => $date->getTimestamp()]);
$post3 = $this->helper_reply_to_post($post1, $user, ['created' => $date->getTimestamp()]);
$date->modify('+1 month');
@@ -1010,7 +1006,7 @@ class mod_forum_vaults_post_testcase extends advanced_testcase {
[$discussion2, $post4] = $this->helper_post_to_forum($forum, $user);
- $datefilter = new DateTime('2019-07-01');
+ $datefilter = new \DateTime('2019-07-01');
$filters = ['from' => $datefilter->getTimestamp()];
$entities = $this->vault->get_from_filters($user, $filters, false);
$this->assertCount(7, $entities);
diff --git a/mod/glossary/tests/concept_cache_test.php b/mod/glossary/tests/concept_cache_test.php
index 197e4cd90e6..010f066fee4 100644
--- a/mod/glossary/tests/concept_cache_test.php
+++ b/mod/glossary/tests/concept_cache_test.php
@@ -14,14 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Concept fetching and caching tests.
- *
- * @package mod_glossary
- * @category test
- * @copyright 2014 Petr Skoda
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace mod_glossary;
/**
* Concept fetching and caching tests.
@@ -31,7 +24,7 @@
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_glossary_concept_cache_testcase extends advanced_testcase {
+class concept_cache_test extends \advanced_testcase {
/**
* Test convect fetching.
*/
@@ -174,7 +167,7 @@ class mod_glossary_concept_cache_testcase extends advanced_testcase {
$this->assertCount(4, $concepts1[0]);
$this->assertCount(4, $concepts1[1]);
$this->setUser($user);
- course_modinfo::clear_instance_cache();
+ \course_modinfo::clear_instance_cache();
\mod_glossary\local\concept_cache::reset_caches();
$concepts1 = \mod_glossary\local\concept_cache::get_concepts($course1->id);
$this->assertCount(3, $concepts1[0]);
diff --git a/mod/lesson/tests/numeric_helper_test.php b/mod/lesson/tests/numeric_helper_test.php
index 48ba9eb0f84..a0ea02a24b9 100644
--- a/mod/lesson/tests/numeric_helper_test.php
+++ b/mod/lesson/tests/numeric_helper_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 mod_lesson;
+
+use mod_lesson\local\numeric\helper;
+
/**
- * Unit tests for page types classes
+ * This class contains the test cases for the numeric helper functions
*
* @package mod_lesson
* @category test
* @copyright 2020 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-use mod_lesson\local\numeric\helper;
-
-/**
- * This class contains the test cases for the numeric helper functions
- *
- * @copyright 2020 Peter Dias
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- */
-class mod_lesson_numeric_type_helper_test extends advanced_testcase {
+class numeric_helper_test extends \advanced_testcase {
/**
* Test the lesson_unformat_numeric_value function.
*
diff --git a/mod/lesson/tests/pagetypes_test.php b/mod/lesson/tests/pagetypes_test.php
index 28eab4cb70e..5fe3a0db371 100644
--- a/mod/lesson/tests/pagetypes_test.php
+++ b/mod/lesson/tests/pagetypes_test.php
@@ -14,15 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for page types classes
- *
- * @package mod_lesson
- * @category test
- * @copyright 2015 Jean-Michel Vedrine
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- */
+namespace mod_lesson;
+use lesson_page_type_essay;
defined('MOODLE_INTERNAL') || die();
@@ -34,16 +28,18 @@ require_once($CFG->dirroot . '/mod/lesson/pagetypes/essay.php');
/**
* This class contains the test cases for some of the functions in the lesson essay page type class.
*
+ * @package mod_lesson
+ * @category test
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
-class mod_lesson_essay_page_type_test extends advanced_testcase {
+class pagetypes_test extends \advanced_testcase {
public function test_lesson_essay_extract_useranswer() {
// Test that reponseformat is added when not present.
$answer = 'O:8:"stdClass":6:{s:4:"sent";i:1;s:6:"graded";i:1;s:5:"score";s:1:"1";'
. 's:6:"answer";s:64:"This is my answer with bold and italics
";'
. 's:12:"answerformat";s:1:"1";s:8:"response";s:10:"Well done!";}';
- $userresponse = new stdClass;
+ $userresponse = new \stdClass;
$userresponse->sent = 1;
$userresponse->graded = 1;
$userresponse->score = 1;
@@ -57,7 +53,7 @@ class mod_lesson_essay_page_type_test extends advanced_testcase {
$answer = 'O:8:"stdClass":7:{s:4:"sent";i:0;s:6:"graded";i:1;s:5:"score";s:1:"0";'
. 's:6:"answer";s:64:"This is my answer with bold and italics
";'
. 's:12:"answerformat";s:1:"1";s:8:"response";s:10:"Well done!";s:14:"responseformat";s:1:"2";}';
- $userresponse = new stdClass;
+ $userresponse = new \stdClass;
$userresponse->sent = 0;
$userresponse->graded = 1;
$userresponse->score = 0;
diff --git a/mod/lti/service/gradebookservices/tests/gradebookservices_test.php b/mod/lti/service/gradebookservices/tests/gradebookservices_test.php
index 765a67b51ba..b1d297be889 100644
--- a/mod/lti/service/gradebookservices/tests/gradebookservices_test.php
+++ b/mod/lti/service/gradebookservices/tests/gradebookservices_test.php
@@ -14,21 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for mod_lti gradebookservices
- * @package ltiservice_gradebookservices
- * @category external
- * @copyright 2020 Claude Vervoort
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-use ltiservice_gradebookservices\local\service\gradebookservices;
+namespace ltiservice_gradebookservices;
-defined('MOODLE_INTERNAL') || die();
+use ltiservice_gradebookservices\local\service\gradebookservices;
/**
* Unit tests for lti gradebookservices.
+ *
+ * @package ltiservice_gradebookservices
+ * @category test
+ * @copyright 2020 Claude Vervoort
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_lti_gradebookservices_testcase extends advanced_testcase {
+class gradebookservices_test extends \advanced_testcase {
/**
* Test saving a graded LTI with resource and tag info (as a result of
@@ -278,15 +276,15 @@ class mod_lti_gradebookservices_testcase extends advanced_testcase {
* Creates a new LTI Tool Type.
*/
private function create_type() {
- $type = new stdClass();
+ $type = new \stdClass();
$type->state = LTI_TOOL_STATE_CONFIGURED;
$type->name = "Test tool";
$type->description = "Example description";
$type->clientid = "Test client ID";
$type->baseurl = $this->getExternalTestFileUrl('/test.html');
- $config = new stdClass();
+ $config = new \stdClass();
$config->ltiservice_gradesynchronization = 2;
return lti_add_type($type, $config);
}
-}
\ No newline at end of file
+}
diff --git a/mod/lti/service/gradebookservices/tests/task_cleanup_test.php b/mod/lti/service/gradebookservices/tests/task/cleanup_test.php
similarity index 84%
rename from mod/lti/service/gradebookservices/tests/task_cleanup_test.php
rename to mod/lti/service/gradebookservices/tests/task/cleanup_test.php
index 489aff04c6e..16564b40325 100644
--- a/mod/lti/service/gradebookservices/tests/task_cleanup_test.php
+++ b/mod/lti/service/gradebookservices/tests/task/cleanup_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 cleaning up the gradebook services task.
- *
- * @package ltiservice_gradebookservices
- * @category test
- * @copyright 2018 Mark Nelson
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace ltiservice_gradebookservices\task;
/**
* Tests cleaning up the gradebook services task.
@@ -33,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2018 Mark Nelson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testcase {
+class cleanup_test extends \advanced_testcase {
/**
* Test set up.
@@ -71,7 +62,7 @@ class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testca
$gradeitem2 = $DB->get_record('grade_items', $conditions);
// Insert these into the 'ltiservice_gradebookservices' table.
- $data = new stdClass();
+ $data = new \stdClass();
$data->gradeitemid = $gradeitem->id;
$data->courseid = $course->id;
$DB->insert_record('ltiservice_gradebookservices', $data);
@@ -79,7 +70,7 @@ class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testca
$data->gradeitemid = $gradeitem2->id;
$DB->insert_record('ltiservice_gradebookservices', $data);
- $task = new \ltiservice_gradebookservices\task\cleanup_task();
+ $task = new cleanup_task();
$task->execute();
// Check they both still exist.
@@ -89,7 +80,7 @@ class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testca
course_delete_module($lti->cmid);
// Run the task again.
- $task = new \ltiservice_gradebookservices\task\cleanup_task();
+ $task = new cleanup_task();
$task->execute();
// Check only the second grade item exists.
@@ -116,17 +107,17 @@ class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testca
'courseid' => $course->id,
'itemtype' => 'manual'
];
- $gradeitem = new grade_item($params);
+ $gradeitem = new \grade_item($params);
$gradeitem->insert();
// Insert it into the 'ltiservice_gradebookservices' table.
- $data = new stdClass();
+ $data = new \stdClass();
$data->gradeitemid = $gradeitem->id;
$data->courseid = $course->id;
$DB->insert_record('ltiservice_gradebookservices', $data);
// Run the task.
- $task = new \ltiservice_gradebookservices\task\cleanup_task();
+ $task = new cleanup_task();
$task->execute();
// Check it still exist.
@@ -136,7 +127,7 @@ class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testca
$gradeitem->delete();
// Run the task again.
- $task = new \ltiservice_gradebookservices\task\cleanup_task();
+ $task = new cleanup_task();
$task->execute();
// Check it has been removed.
diff --git a/mod/lti/tests/event/unknown_service_api_called_test.php b/mod/lti/tests/event/unknown_service_api_called_test.php
index 0198d2d8fd5..ec87886d986 100644
--- a/mod/lti/tests/event/unknown_service_api_called_test.php
+++ b/mod/lti/tests/event/unknown_service_api_called_test.php
@@ -14,17 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unknown service API called event tests
- *
- * @package mod_lti
- * @copyright Copyright (c) 2012 Moodlerooms Inc. (http://www.moodlerooms.com)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-use mod_lti\event\unknown_service_api_called;
+namespace mod_lti\event;
/**
* Unknown service API called event tests
@@ -33,7 +23,7 @@ use mod_lti\event\unknown_service_api_called;
* @copyright Copyright (c) 2012 Moodlerooms Inc. (http://www.moodlerooms.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_lti_event_unknown_service_api_called_test extends advanced_testcase {
+class unknown_service_api_called_test extends \advanced_testcase {
/*
* Ensure create event works.
*/
@@ -47,7 +37,7 @@ class mod_lti_event_unknown_service_api_called_test extends advanced_testcase {
*/
public function test_event_context() {
$event = unknown_service_api_called::create();
- $this->assertEquals(context_system::instance(), $event->get_context());
+ $this->assertEquals(\context_system::instance(), $event->get_context());
}
/*
diff --git a/mod/lti/tests/external/get_tool_types_and_proxies_count_test.php b/mod/lti/tests/external/get_tool_types_and_proxies_count_test.php
index 4c0cf18160a..41b308bb753 100644
--- a/mod/lti/tests/external/get_tool_types_and_proxies_count_test.php
+++ b/mod/lti/tests/external/get_tool_types_and_proxies_count_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 mod_lti\external;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -28,7 +30,7 @@ require_once($CFG->dirroot . '/mod/lti/tests/mod_lti_testcase.php');
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_lti_get_tool_types_and_proxies_count_testcase extends mod_lti_testcase {
+class get_tool_types_and_proxies_count_test extends \mod_lti_testcase {
/**
* This method runs before every test.
@@ -48,7 +50,7 @@ class mod_lti_get_tool_types_and_proxies_count_testcase extends mod_lti_testcase
}
$data = \mod_lti\external\get_tool_types_and_proxies_count::execute(0, false);
- $data = external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
+ $data = \external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
$this->assertEquals(20, $data['count']);
}
@@ -58,7 +60,7 @@ class mod_lti_get_tool_types_and_proxies_count_testcase extends mod_lti_testcase
*/
public function test_mod_lti_get_tool_types_and_proxies_count_with_no_tools_configured() {
$data = \mod_lti\external\get_tool_types_and_proxies_count::execute(0, false);
- $data = external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
+ $data = \external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
$this->assertEquals(0, $data['count']);
}
diff --git a/mod/lti/tests/external/get_tool_types_and_proxies_test.php b/mod/lti/tests/external/get_tool_types_and_proxies_test.php
index 319b3222699..f38068fe82a 100644
--- a/mod/lti/tests/external/get_tool_types_and_proxies_test.php
+++ b/mod/lti/tests/external/get_tool_types_and_proxies_test.php
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-use mod_lti\external\get_tool_types_and_proxies;
+namespace mod_lti\external;
defined('MOODLE_INTERNAL') || die();
@@ -30,7 +30,7 @@ require_once($CFG->dirroot . '/mod/lti/tests/mod_lti_testcase.php');
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_lti_get_tool_types_and_proxies_testcase extends mod_lti_testcase {
+class get_tool_types_and_proxies_test extends \mod_lti_testcase {
/**
* This method runs before every test.
@@ -48,7 +48,7 @@ class mod_lti_get_tool_types_and_proxies_testcase extends mod_lti_testcase {
$this->generate_tool_type(1, $proxy->id);
$data = get_tool_types_and_proxies::execute(0, false, 50, 0);
- $data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
+ $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(1, $data['types']);
$type = $data['types'][0];
@@ -71,7 +71,7 @@ class mod_lti_get_tool_types_and_proxies_testcase extends mod_lti_testcase {
}
$data = get_tool_types_and_proxies::execute(0, false, 5, 0);
- $data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
+ $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(2, $data['types']);
$this->assertCount(3, $data['proxies']);
@@ -89,7 +89,7 @@ class mod_lti_get_tool_types_and_proxies_testcase extends mod_lti_testcase {
}
$data = get_tool_types_and_proxies::execute(0, false, 5, 10);
- $data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
+ $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(2, $data['types']);
$this->assertCount(0, $data['proxies']);
@@ -107,7 +107,7 @@ class mod_lti_get_tool_types_and_proxies_testcase extends mod_lti_testcase {
}
$data = get_tool_types_and_proxies::execute(0, false, 0, 0);
- $data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
+ $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(10, $data['types']);
$this->assertCount(10, $data['proxies']);
diff --git a/mod/lti/tests/service_exception_handler_test.php b/mod/lti/tests/service_exception_handler_test.php
index 50e257f7ee0..28ad8b9b791 100644
--- a/mod/lti/tests/service_exception_handler_test.php
+++ b/mod/lti/tests/service_exception_handler_test.php
@@ -14,17 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tests Exception handler for LTI services
- *
- * @package mod_lti
- * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-use mod_lti\service_exception_handler;
-
-defined('MOODLE_INTERNAL') || die();
+namespace mod_lti;
/**
* Tests Exception handler for LTI services
@@ -33,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_lti_service_exception_handler_testcase extends advanced_testcase {
+class service_exception_handler_test extends \advanced_testcase {
/**
* Testing service error handling.
*/
@@ -41,7 +31,7 @@ class mod_lti_service_exception_handler_testcase extends advanced_testcase {
$handler = new service_exception_handler(false);
$handler->set_message_id('123');
$handler->set_message_type('testRequest');
- $handler->handle(new Exception('Error happened'));
+ $handler->handle(new \Exception('Error happened'));
$this->expectOutputRegex('/imsx_codeMajor>failure/');
$this->expectOutputRegex('/imsx_description>Error happened/');
@@ -55,7 +45,7 @@ class mod_lti_service_exception_handler_testcase extends advanced_testcase {
*/
public function test_handle_early_error() {
$handler = new service_exception_handler(false);
- $handler->handle(new Exception('Error happened'));
+ $handler->handle(new \Exception('Error happened'));
$this->expectOutputRegex('/imsx_codeMajor>failure/');
$this->expectOutputRegex('/imsx_description>Error happened/');
@@ -75,11 +65,11 @@ class mod_lti_service_exception_handler_testcase extends advanced_testcase {
$handler = new service_exception_handler(true);
ob_start();
- $handler->handle(new Exception('Error happened'));
+ $handler->handle(new \Exception('Error happened'));
ob_end_clean();
$this->assertTrue(is_dir($CFG->dataroot.'/temp/mod_lti'));
$files = glob($CFG->dataroot.'/temp/mod_lti/mod*');
$this->assertEquals(1, count($files));
}
-}
\ No newline at end of file
+}
diff --git a/mod/lti/tests/servicelib_test.php b/mod/lti/tests/servicelib_test.php
index 286fd63fe6e..a20fbc8184e 100644
--- a/mod/lti/tests/servicelib_test.php
+++ b/mod/lti/tests/servicelib_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 servicelib.php
- *
- * @package mod_lti
- * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace mod_lti;
defined('MOODLE_INTERNAL') || die();
@@ -35,7 +29,7 @@ require_once($CFG->dirroot.'/mod/lti/servicelib.php');
* @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_lti_servicelib_testcase extends basic_testcase {
+class servicelib_test extends \basic_testcase {
/**
* Test that lti_parse_message_id never fails with good and bad XML.
*
@@ -112,4 +106,4 @@ XML;
array('', $noidentifier),
);
}
-}
\ No newline at end of file
+}
diff --git a/mod/lti/tests/task_clean_access_tokens_test.php b/mod/lti/tests/task/clean_access_tokens_test.php
similarity index 82%
rename from mod/lti/tests/task_clean_access_tokens_test.php
rename to mod/lti/tests/task/clean_access_tokens_test.php
index df063ce7f9a..ccc1a08c1a0 100644
--- a/mod/lti/tests/task_clean_access_tokens_test.php
+++ b/mod/lti/tests/task/clean_access_tokens_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 cleaning up the access tokens task.
- *
- * @package mod_lti
- * @category test
- * @copyright 2019 Mark Nelson
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace mod_lti\task;
/**
* Tests cleaning up the access tokens task.
@@ -33,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2019 Mark Nelson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_lti_clean_access_tokens_testcase extends advanced_testcase {
+class clean_access_tokens_test extends \advanced_testcase {
/**
* Test set up.
@@ -53,7 +44,7 @@ class mod_lti_clean_access_tokens_testcase extends advanced_testcase {
$time = time();
// Create an expired access token.
- $token = new stdClass();
+ $token = new \stdClass();
$token->typeid = 1;
$token->scope = 'scope';
$token->token = 'token';
@@ -69,7 +60,7 @@ class mod_lti_clean_access_tokens_testcase extends advanced_testcase {
$t2id = $DB->insert_record('lti_access_tokens', $token);
// Run the task.
- $task = new \mod_lti\task\clean_access_tokens();
+ $task = new clean_access_tokens();
$task->execute();
// Check there is only one token now.
diff --git a/mod/scorm/tests/formatduration_test.php b/mod/scorm/tests/formatduration_test.php
index 503d865ea90..606a346d0de 100644
--- a/mod/scorm/tests/formatduration_test.php
+++ b/mod/scorm/tests/formatduration_test.php
@@ -14,23 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-defined('MOODLE_INTERNAL') || die;
+namespace mod_scorm;
-/*
- * Unit tests for scorm_formatduration function from locallib.php
- *
- * @package mod_scorm
- * @category phpunit
- * @copyright 2009 Dan Marsden
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+defined('MOODLE_INTERNAL') || die;
// Make sure the code being tested is accessible.
global $CFG;
require_once($CFG->dirroot . '/mod/scorm/locallib.php'); // Include the code to test.
-
-class mod_scorm_formatduration_testcase extends basic_testcase {
+/**
+ * Unit tests for scorm_formatduration function from locallib.php
+ *
+ * @package mod_scorm
+ * @category test
+ * @copyright 2009 Dan Marsden
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class formatduration_test extends \basic_testcase {
public function test_scorm2004_format() {
$stryears = get_string('years');
$strmonths = trim(get_string('nummonths'));
diff --git a/mod/scorm/tests/validatepackage_test.php b/mod/scorm/tests/validatepackage_test.php
index a27840060fd..69bb4e723c3 100644
--- a/mod/scorm/tests/validatepackage_test.php
+++ b/mod/scorm/tests/validatepackage_test.php
@@ -14,29 +14,22 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for the mod_quiz_display_options class.
- *
- * @package mod_scorm
- * @category phpunit
- * @copyright 2013 Dan Marsden
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
+namespace mod_scorm;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/scorm/locallib.php');
-
/**
* Unit tests for {@link mod_scorm}.
*
+ * @package mod_scorm
+ * @category test
* @copyright 2013 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_scorm_validatepackage_testcase extends advanced_testcase {
+class validatepackage_test extends \advanced_testcase {
/**
* Convenience to take a fixture test file and create a stored_file.
@@ -45,7 +38,7 @@ class mod_scorm_validatepackage_testcase extends advanced_testcase {
* @return stored_file
*/
protected function create_stored_file_from_path($filepath) {
- $syscontext = context_system::instance();
+ $syscontext = \context_system::instance();
$filerecord = array(
'contextid' => $syscontext->id,
'component' => 'mod_scorm',
@@ -66,17 +59,17 @@ class mod_scorm_validatepackage_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$filename = "validscorm.zip";
- $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
+ $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN);
$errors = scorm_validate_package($file);
$this->assertEmpty($errors);
$filename = "validaicc.zip";
- $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
+ $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN);
$errors = scorm_validate_package($file);
$this->assertEmpty($errors);
$filename = "invalid.zip";
- $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
+ $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN);
$errors = scorm_validate_package($file);
$this->assertArrayHasKey('packagefile', $errors);
if (isset($errors['packagefile'])) {
@@ -84,7 +77,7 @@ class mod_scorm_validatepackage_testcase extends advanced_testcase {
}
$filename = "badscorm.zip";
- $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
+ $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN);
$errors = scorm_validate_package($file);
$this->assertArrayHasKey('packagefile', $errors);
if (isset($errors['packagefile'])) {
diff --git a/mod/wiki/tests/wikiparser_test.php b/mod/wiki/tests/wikiparser_test.php
index ed757ad9185..3ce41fd87a9 100644
--- a/mod/wiki/tests/wikiparser_test.php
+++ b/mod/wiki/tests/wikiparser_test.php
@@ -8,17 +8,26 @@
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with Moodle. If not, see .
+// along with Moodle. If not, see .
+
+namespace mod_wiki;
+
+use wiki_parser_proxy;
+
+defined('MOODLE_INTERNAL') || die;
+
+global $CFG;
+require_once($CFG->dirroot . '/mod/wiki/parser/parser.php');
/**
* Unit tests for the wiki parser
*
* @package mod_wiki
- * @category phpunit
+ * @category test
* @copyright 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
@@ -30,14 +39,7 @@
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die;
-
-global $CFG;
-require_once($CFG->dirroot . '/mod/wiki/parser/parser.php');
-
-
-class mod_wiki_wikiparser_test extends basic_testcase {
+class wikiparser_test extends \basic_testcase {
/**
* URL inside the clickable text of some link should not be turned into a new link via the url_tag_rule.
diff --git a/mod/workshop/allocation/random/tests/allocator_test.php b/mod/workshop/allocation/random/tests/allocator_test.php
index ebbb2e58391..b8d3914e0f6 100644
--- a/mod/workshop/allocation/random/tests/allocator_test.php
+++ b/mod/workshop/allocation/random/tests/allocator_test.php
@@ -18,11 +18,16 @@
* Unit tests for Random allocation
*
* @package workshopallocation_random
- * @category phpunit
+ * @category test
* @copyright 2009 David Mudrak
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace workshopallocation_random;
+
+use workshop;
+use workshop_random_allocator;
+
defined('MOODLE_INTERNAL') || die();
// Include the code to test
@@ -30,8 +35,15 @@ global $CFG;
require_once($CFG->dirroot . '/mod/workshop/locallib.php');
require_once($CFG->dirroot . '/mod/workshop/allocation/random/lib.php');
-
-class workshopallocation_random_testcase extends advanced_testcase {
+/**
+ * Unit tests for Random allocation
+ *
+ * @package workshopallocation_random
+ * @category test
+ * @copyright 2009 David Mudrak
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class allocator_test extends \advanced_testcase {
/** workshop instance emulation */
protected $workshop;
@@ -63,8 +75,8 @@ class workshopallocation_random_testcase extends advanced_testcase {
public function test_self_allocation_equal_user_groups() {
// fixture setup
- $authors = array(0 => array_fill_keys(array(4, 6, 10), new stdclass()));
- $reviewers = array(0 => array_fill_keys(array(4, 6, 10), new stdclass()));
+ $authors = array(0 => array_fill_keys(array(4, 6, 10), new \stdClass()));
+ $reviewers = array(0 => array_fill_keys(array(4, 6, 10), new \stdClass()));
// exercise SUT
$newallocations = $this->allocator->self_allocation($authors, $reviewers);
// verify
@@ -73,8 +85,8 @@ class workshopallocation_random_testcase extends advanced_testcase {
public function test_self_allocation_different_user_groups() {
// fixture setup
- $authors = array(0 => array_fill_keys(array(1, 4, 5, 10, 13), new stdclass()));
- $reviewers = array(0 => array_fill_keys(array(4, 7, 10), new stdclass()));
+ $authors = array(0 => array_fill_keys(array(1, 4, 5, 10, 13), new \stdClass()));
+ $reviewers = array(0 => array_fill_keys(array(4, 7, 10), new \stdClass()));
// exercise SUT
$newallocations = $this->allocator->self_allocation($authors, $reviewers);
// verify
@@ -83,8 +95,8 @@ class workshopallocation_random_testcase extends advanced_testcase {
public function test_self_allocation_skip_existing() {
// fixture setup
- $authors = array(0 => array_fill_keys(array(3, 4, 10), new stdclass()));
- $reviewers = array(0 => array_fill_keys(array(3, 4, 10), new stdclass()));
+ $authors = array(0 => array_fill_keys(array(3, 4, 10), new \stdClass()));
+ $reviewers = array(0 => array_fill_keys(array(3, 4, 10), new \stdClass()));
$assessments = array(23 => (object)array('authorid' => 3, 'reviewerid' => 3));
// exercise SUT
$newallocations = $this->allocator->self_allocation($authors, $reviewers, $assessments);
@@ -121,7 +133,7 @@ class workshopallocation_random_testcase extends advanced_testcase {
87 => (object)array('id' => 121, 'authorid' => 3),
);
// exercise SUT
- $this->expectException(moodle_exception::class);
+ $this->expectException(\moodle_exception::class);
$submissions = $this->allocator->index_submissions_by_authors($submissions);
}
diff --git a/mod/workshop/tests/cron_task_test.php b/mod/workshop/tests/task/cron_task_test.php
similarity index 93%
rename from mod/workshop/tests/cron_task_test.php
rename to mod/workshop/tests/task/cron_task_test.php
index 04fd0c3fad4..2de236b8e87 100644
--- a/mod/workshop/tests/cron_task_test.php
+++ b/mod/workshop/tests/task/cron_task_test.php
@@ -14,14 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Provides the {@link mod_workshop_cron_task_testcase} class.
- *
- * @package mod_workshop
- * @category test
- * @copyright 2019 David Mudrák
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace mod_workshop\task;
+
+use workshop;
defined('MOODLE_INTERNAL') || die();
@@ -32,10 +27,12 @@ require_once($CFG->dirroot.'/mod/workshop/lib.php');
/**
* Test the functionality provided by the {@link mod_workshop\task\cron_task} scheduled task.
*
+ * @package mod_workshop
+ * @category test
* @copyright 2019 David Mudrák
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_workshop_cron_task_testcase extends advanced_testcase {
+class cron_task_test extends \advanced_testcase {
/**
* Test that the phase is automatically switched after the submissions deadline.
diff --git a/privacy/tests/collection_test.php b/privacy/tests/collection_test.php
index 069867042c3..1a1c81025a2 100644
--- a/privacy/tests/collection_test.php
+++ b/privacy/tests/collection_test.php
@@ -14,30 +14,25 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Collection unit tests.
- *
- * @package core_privacy
- * @category test
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_privacy;
defined('MOODLE_INTERNAL') || die();
global $CFG;
-use \core_privacy\local\metadata\collection;
-use \core_privacy\local\metadata\types;
+use core_privacy\local\metadata\collection;
+use core_privacy\local\metadata\types;
/**
* Tests for the \core_privacy API's collection functionality.
*
+ * @package core_privacy
+ * @category test
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\collection
*/
-class core_privacy_metadata_collection extends advanced_testcase {
+class collection_test extends \advanced_testcase {
/**
* Test that adding an unknown type causes the type to be added to the collection.
diff --git a/privacy/tests/legacy_polyfill_test.php b/privacy/tests/legacy_polyfill_test.php
index 05f83fdb955..4305e435183 100644
--- a/privacy/tests/legacy_polyfill_test.php
+++ b/privacy/tests/legacy_polyfill_test.php
@@ -15,31 +15,35 @@
// along with Moodle. If not, see .
/**
- * Unit tests for the privacy legacy polyfill.
+ * Unit tests for the Privacy API's legacy_polyfill.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @coversDefaultClass \core_privacy\local\legacy_polyfill
*/
+namespace core_privacy;
+
+use core_privacy\local\metadata\collection;
+use core_privacy\local\request\contextlist;
+use core_privacy\local\request\approved_contextlist;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
-use \core_privacy\local\metadata\collection;
-use \core_privacy\local\request\contextlist;
-use \core_privacy\local\request\approved_contextlist;
-
/**
- * Tests for the \core_privacy API's types\user_preference functionality.
* Unit tests for the Privacy API's legacy_polyfill.
*
+ * @package core_privacy
+ * @category test
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\legacy_polyfill
*/
-class core_privacy_legacy_polyfill_test extends advanced_testcase {
+class legacy_polyfill_test extends \advanced_testcase {
/**
* Test that the null_provider polyfill works and that the static _get_reason can be
* successfully called.
diff --git a/privacy/tests/types_database_table_test.php b/privacy/tests/types_database_table_test.php
index 0c262889ba7..9d46af57f61 100644
--- a/privacy/tests/types_database_table_test.php
+++ b/privacy/tests/types_database_table_test.php
@@ -14,29 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Type unit tests for the Database Table.
- *
- * @package core_privacy
- * @category test
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_privacy;
+
+use core_privacy\local\metadata\types\database_table;
defined('MOODLE_INTERNAL') || die();
global $CFG;
-use \core_privacy\local\metadata\types\database_table;
-
/**
* Tests for the \core_privacy API's types\database_table functionality.
*
+ * @package core_privacy
+ * @category test
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\types\database_table
*/
-class core_privacy_metadata_types_database_table extends advanced_testcase {
+class types_database_table_test extends \advanced_testcase {
/**
* Ensure that warnings are thrown if string identifiers contain invalid characters.
diff --git a/privacy/tests/types_external_location_test.php b/privacy/tests/types_external_location_test.php
index 051265625e7..87a39072777 100644
--- a/privacy/tests/types_external_location_test.php
+++ b/privacy/tests/types_external_location_test.php
@@ -14,29 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Type unit tests for the External Location.
- *
- * @package core_privacy
- * @category test
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_privacy;
defined('MOODLE_INTERNAL') || die();
global $CFG;
-use \core_privacy\local\metadata\types\external_location;
+use core_privacy\local\metadata\types\external_location;
/**
* Tests for the \core_privacy API's types\external_location functionality.
*
+ * @package core_privacy
+ * @category test
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\types\external_location
*/
-class core_privacy_metadata_types_external_location extends advanced_testcase {
+class types_external_location_test extends \advanced_testcase {
/**
* Ensure that warnings are thrown if string identifiers contain invalid characters.
diff --git a/privacy/tests/types_plugintype_link_test.php b/privacy/tests/types_plugintype_link_test.php
index 41243620a8d..187c5f3b49a 100644
--- a/privacy/tests/types_plugintype_link_test.php
+++ b/privacy/tests/types_plugintype_link_test.php
@@ -14,29 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_privacy;
+
+use core_privacy\local\metadata\types\plugintype_link;
+
/**
- * Types unit tests for the Plugintype Link.
+ * Tests for the \core_privacy API's types\plugintype_link functionality.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-use \core_privacy\local\metadata\types\plugintype_link;
-
-/**
- * Tests for the \core_privacy API's types\plugintype_link functionality.
- *
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\types\plugintype_link
*/
-class core_privacy_metadata_types_plugintype_link extends advanced_testcase {
+class types_plugintype_link_test extends \advanced_testcase {
/**
* Ensure that warnings are thrown if string identifiers contain invalid characters.
diff --git a/privacy/tests/types_subsystem_link_test.php b/privacy/tests/types_subsystem_link_test.php
index 8aa03b407a2..53cc24586e3 100644
--- a/privacy/tests/types_subsystem_link_test.php
+++ b/privacy/tests/types_subsystem_link_test.php
@@ -14,29 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_privacy;
+
+use core_privacy\local\metadata\types\subsystem_link;
+
/**
- * Types unit tests for the Subsystem Link.
+ * Tests for the \core_privacy API's types\subsystem_link functionality.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-use \core_privacy\local\metadata\types\subsystem_link;
-
-/**
- * Tests for the \core_privacy API's types\subsystem_link functionality.
- *
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\types\subsystem_link
*/
-class core_privacy_metadata_types_subsystem_link extends advanced_testcase {
+class types_subsystem_link_test extends \advanced_testcase {
/**
* Ensure that warnings are thrown if string identifiers contain invalid characters.
diff --git a/privacy/tests/types_user_preference_test.php b/privacy/tests/types_user_preference_test.php
index 0e4206cda9e..3e2dd30e452 100644
--- a/privacy/tests/types_user_preference_test.php
+++ b/privacy/tests/types_user_preference_test.php
@@ -14,29 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_privacy;
+
+use core_privacy\local\metadata\types\user_preference;
+
/**
- * Types unit tests for the Subsystem Link.
+ * Tests for the \core_privacy API's types\user_preference functionality.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
-use \core_privacy\local\metadata\types\user_preference;
-
-/**
- * Tests for the \core_privacy API's types\user_preference functionality.
- *
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\types\user_preference
*/
-class core_privacy_metadata_types_user_preference extends advanced_testcase {
+class types_user_preference_test extends \advanced_testcase {
/**
* Ensure that warnings are thrown if string identifiers contain invalid characters.
diff --git a/rating/tests/rating_test.php b/rating/tests/rating_test.php
index 896a8bfcc4c..f60107dc865 100644
--- a/rating/tests/rating_test.php
+++ b/rating/tests/rating_test.php
@@ -17,12 +17,16 @@
/**
* Unit tests for rating/lib.php
*
- * @package core_ratings
- * @category phpunit
+ * @package core_rating
+ * @category test
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace core_rating;
+
+use rating_manager;
+
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff.
@@ -32,8 +36,13 @@ require_once($CFG->dirroot . '/rating/lib.php');
/**
* Unit test case for all the rating/lib.php requiring DB mockup & manipulation
+ *
+ * @package core_rating
+ * @category test
+ * @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_rating_testcase extends advanced_testcase {
+class rating_test extends \advanced_testcase {
protected $syscontext;
protected $neededcaps = array('view', 'viewall', 'viewany', 'rate');
@@ -55,7 +64,7 @@ class core_rating_testcase extends advanced_testcase {
global $DB;
// We load 3 items. Each is rated twice. For simplicity itemid == user id of the item owner.
- $ctxid = context_system::instance()->id;
+ $ctxid = \context_system::instance()->id;
$ratings = array(
// User 1's items. Average == 2.
array('contextid' => $ctxid,
@@ -136,7 +145,7 @@ class core_rating_testcase extends advanced_testcase {
// Prepare the default options.
$defaultoptions = array (
- 'context' => context_system::instance(),
+ 'context' => \context_system::instance(),
'component' => 'mod_forum',
'ratingarea' => 'post',
'scaleid' => 10,
@@ -345,7 +354,7 @@ class core_rating_testcase extends advanced_testcase {
* @dataProvider get_aggregate_string_provider
*/
public function test_get_aggregate_string($method, $aggregate, $isnumeric, $scaleitems, $expectation) {
- $options = new stdClass();
+ $options = new \stdClass();
$options->aggregate = $aggregate;
$options->context = null;
$options->component = null;
@@ -354,13 +363,13 @@ class core_rating_testcase extends advanced_testcase {
$options->scaleid = null;
$options->userid = null;
- $options->settings = new stdClass();
+ $options->settings = new \stdClass();
$options->settings->aggregationmethod = $method;
- $options->settings->scale = new stdClass();
+ $options->settings->scale = new \stdClass();
$options->settings->scale->isnumeric = $isnumeric;
$options->settings->scale->scaleitems = $scaleitems;
- $rating = new rating($options);
+ $rating = new \rating($options);
$this->assertEquals($expectation, $rating->get_aggregate_string());
}
}
diff --git a/repository/contentbank/tests/browser_test.php b/repository/contentbank/tests/browser_test.php
index 036dfe94917..b7e6cafe0d5 100644
--- a/repository/contentbank/tests/browser_test.php
+++ b/repository/contentbank/tests/browser_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Content bank repository browser unit tests.
- *
- * @package repository_contentbank
- * @copyright 2020 Mihail Geshoski
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace repository_contentbank;
defined('MOODLE_INTERNAL') || die();
@@ -35,7 +29,7 @@ require_once("$CFG->dirroot/repository/lib.php");
* @copyright 2020 Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class repository_contentbank_browser_testcase extends advanced_testcase {
+class browser_test extends \advanced_testcase {
/**
* Test get_content() in the system context with users that have capability to access/view content bank content
diff --git a/repository/nextcloud/tests/access_controlled_link_manager_test.php b/repository/nextcloud/tests/access_controlled_link_manager_test.php
index 78a98cf049a..6be9edc1f19 100644
--- a/repository/nextcloud/tests/access_controlled_link_manager_test.php
+++ b/repository/nextcloud/tests/access_controlled_link_manager_test.php
@@ -14,15 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This file contains tests for the repository_nextcloud class.
- *
- * @package repository_nextcloud
- * @copyright 2017 Project seminar (Learnweb, University of Münster)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace repository_nextcloud;
-use core\oauth2\system_account;
+use testable_access_controlled_link_manager;
defined('MOODLE_INTERNAL') || die();
@@ -32,11 +26,13 @@ require_once($CFG->dirroot . '/repository/nextcloud/tests/fixtures/testable_acce
/**
* Class repository_nextcloud_testcase
+ *
+ * @package repository_nextcloud
* @group repository_nextcloud
* @copyright 2017 Project seminar (Learnweb, University of Münster)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class repository_nextcloud_access_controlled_link_manager_testcase extends advanced_testcase {
+class access_controlled_link_manager_test extends \advanced_testcase {
/** @var null|testable_access_controlled_link_manager a malleable variant of the access_controlled_link_manager. */
public $linkmanager = null;
@@ -64,24 +60,24 @@ class repository_nextcloud_access_controlled_link_manager_testcase extends advan
$generator->test_create_endpoints($this->issuer->get('id'));
// Mock clients.
- $this->ocsmockclient = $this->getMockBuilder(repository_nextcloud\ocs_client::class
+ $this->ocsmockclient = $this->getMockBuilder(ocs_client::class
)->disableOriginalConstructor()->disableOriginalClone()->getMock();
$this->oauthsystemmock = $this->getMockBuilder(\core\oauth2\client::class
)->disableOriginalConstructor()->disableOriginalClone()->getMock();
$systemwebdavclient = $this->getMockBuilder(\webdav_client::class
)->disableOriginalConstructor()->disableOriginalClone()->getMock();
- $systemocsclient = $systemocsclient = $this->getMockBuilder(repository_nextcloud\ocs_client::class
+ $systemocsclient = $systemocsclient = $this->getMockBuilder(ocs_client::class
)->disableOriginalConstructor()->disableOriginalClone()->getMock();
// Pseudo system account user.
$this->systemaccountusername = 'pseudouser';
- $record = new stdClass();
+ $record = new \stdClass();
$record->issuerid = $this->issuer->get('id');
$record->refreshtoken = 'pseudotoken';
$record->grantedscopes = 'scopes';
$record->email = '';
$record->username = $this->systemaccountusername;
- $systemaccount = new system_account(0, $record);
+ $systemaccount = new \core\oauth2\system_account(0, $record);
$systemaccount->create();
$this->linkmanager = new testable_access_controlled_link_manager($this->ocsmockclient,
@@ -220,7 +216,7 @@ XML;
*/
protected function set_up_mocks_for_create_folder_path($returnisdir, $returnestedcontext, $callmkcol = false,
$returnmkcol = 201) {
- $mockcontext = $this->createMock(context_module::class);
+ $mockcontext = $this->createMock(\context_module::class);
$mockclient = $this->getMockBuilder(\webdav_client::class
)->disableOriginalConstructor()->disableOriginalClone()->getMock();
$parsedwebdavurl = parse_url($this->issuer->get_endpoint_url('webdav'));
@@ -345,7 +341,7 @@ XML;
'path' => '/Kernsystem/Kursbereich Miscellaneous/Kurs Example Course/Datei zet/mod_resource/content/0/picture.png',
'reshares' => true
];
- $reference = new stdClass();
+ $reference = new \stdClass();
$reference->link = "/Kernsystem/Kursbereich Miscellaneous/Kurs Example Course/Datei zet/mod_resource/content/0/picture.png";
$reference->name = "f\u00fcrdennis.png";
$reference->usesystem = true;
@@ -435,7 +431,7 @@ XML;
*/
public function test_create_system_dav() {
// Initialize mock and params.
- $fakeaccesstoken = new stdClass();
+ $fakeaccesstoken = new \stdClass();
$fakeaccesstoken->token = "fake access token";
// Use `atLeastOnce` instead of `exactly(2)` because it is only called a second time on dev systems that allow http://.
$this->oauthsystemmock->expects($this->atLeastOnce())->method('get_accesstoken')->willReturn($fakeaccesstoken);
@@ -453,7 +449,7 @@ XML;
$this->delete_endpoints('webdav_endpoint');
// Creates a new one which requires different ports.
try {
- $endpoint = new stdClass();
+ $endpoint = new \stdClass();
$endpoint->name = "webdav_endpoint";
$endpoint->url = 'http://www.default.test/webdav/index.php';
$endpoint->issuerid = $this->issuer->get('id');
@@ -587,7 +583,7 @@ XML;
* @return ReflectionProperty the resulting reflection property.
*/
protected function set_private_property($value, $propertyname, $class) {
- $refclient = new ReflectionClass($class);
+ $refclient = new \ReflectionClass($class);
$private = $refclient->getProperty($propertyname);
$private->setAccessible(true);
$private->setValue($class, $value);
@@ -601,7 +597,7 @@ XML;
* @return mixed the resulting value.
*/
protected function get_private_property($propertyname, $class) {
- $refclient = new ReflectionClass($class);
+ $refclient = new \ReflectionClass($class);
$private = $refclient->getProperty($propertyname);
$private->setAccessible(true);
$property = $private->getValue($private);
@@ -626,7 +622,7 @@ XML;
return;
}
foreach ($arrayofids as $id) {
- core\oauth2\api::delete_endpoint($id);
+ \core\oauth2\api::delete_endpoint($id);
}
}
diff --git a/repository/nextcloud/tests/ocs_test.php b/repository/nextcloud/tests/ocs_test.php
index a22747ce1e8..8982b8fe419 100644
--- a/repository/nextcloud/tests/ocs_test.php
+++ b/repository/nextcloud/tests/ocs_test.php
@@ -14,23 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This file contains tests for the repository_nextcloud class.
- *
- * @package repository_nextcloud
- * @copyright 2017 Jan Dageförde (Learnweb, University of Münster)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace repository_nextcloud;
/**
* Class repository_nextcloud_ocs_testcase
+ *
+ * @package repository_nextcloud
* @group repository_nextcloud
* @copyright 2017 Jan Dageförde (Learnweb, University of Münster)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class repository_nextcloud_ocs_testcase extends advanced_testcase {
+class ocs_test extends \advanced_testcase {
/**
* @var \core\oauth2\issuer
@@ -58,7 +52,7 @@ class repository_nextcloud_ocs_testcase extends advanced_testcase {
$mock = $this->createMock(\core\oauth2\client::class);
$mock->expects($this->once())->method('get_issuer')->willReturn($this->issuer);
- $client = new \repository_nextcloud\ocs_client($mock);
+ $client = new ocs_client($mock);
$functions = $client->get_api_functions();
// Assert that relevant (and used) functions are actually present.
diff --git a/repository/tests/repositorylib_test.php b/repository/tests/repositorylib_test.php
index 523287da7af..10416016bcd 100644
--- a/repository/tests/repositorylib_test.php
+++ b/repository/tests/repositorylib_test.php
@@ -14,21 +14,26 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Repository API unit tests
- *
- * @package repository
- * @category phpunit
- * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_repository;
+
+use repository;
+use repository_exception;
+use repository_type;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once("$CFG->dirroot/repository/lib.php");
-class core_repositorylib_testcase extends advanced_testcase {
+/**
+ * Repository API unit tests
+ *
+ * @package core_repository
+ * @category test
+ * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class repositorylib_test extends \advanced_testcase {
/**
* Installing repository tests
@@ -40,7 +45,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$this->resetAfterTest(true);
- $syscontext = context_system::instance();
+ $syscontext = \context_system::instance();
$repositorypluginname = 'dropbox';
// override repository permission
$capability = 'repository/' . $repositorypluginname . ':view';
@@ -68,7 +73,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$fs = get_file_storage();
$draftitemid = null;
- $context = context_user::instance($USER->id);
+ $context = \context_user::instance($USER->id);
file_prepare_draft_area($draftitemid, $context->id, 'phpunit', 'test_get_unused_filename', 1);
$dummy = array(
@@ -122,7 +127,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$fs = get_file_storage();
$draftitemid = file_get_unused_draft_itemid();
- $context = context_user::instance($USER->id);
+ $context = \context_user::instance($USER->id);
$dummy = array(
'contextid' => $context->id,
@@ -163,7 +168,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$fs = get_file_storage();
$draftitemid = file_get_unused_draft_itemid();
- $context = context_user::instance($USER->id);
+ $context = \context_user::instance($USER->id);
$dummy = [
'contextid' => $context->id,
@@ -211,9 +216,9 @@ class core_repositorylib_testcase extends advanced_testcase {
public function test_can_be_edited_by_user() {
$this->resetAfterTest(true);
- $syscontext = context_system::instance();
+ $syscontext = \context_system::instance();
$course = $this->getDataGenerator()->create_course();
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
$roleid = create_role('A role', 'arole', 'A role', '');
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
@@ -268,7 +273,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Instance on a user level.
$otheruser = $this->getDataGenerator()->create_user();
- $otherusercontext = context_user::instance($otheruser->id);
+ $otherusercontext = \context_user::instance($otheruser->id);
role_assign($roleid, $user->id, $syscontext->id);
assign_capability('repository/flickr_public:view', CAP_ALLOW, $roleid, $syscontext, true);
accesslib_clear_all_caches_for_unit_testing();
@@ -280,7 +285,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$this->assertFalse($userrepo->can_be_edited_by_user());
// Editing my own instance.
- $usercontext = context_user::instance($user->id);
+ $usercontext = \context_user::instance($user->id);
$record = array('contextid' => $usercontext->id);
$repoid = $this->getDataGenerator()->create_repository('flickr_public', $record)->id;
$userrepo = repository::get_repository_by_id($repoid, $syscontext);
@@ -291,32 +296,32 @@ class core_repositorylib_testcase extends advanced_testcase {
public function test_check_capability() {
$this->resetAfterTest(true);
- $syscontext = context_system::instance();
+ $syscontext = \context_system::instance();
$course1 = $this->getDataGenerator()->create_course();
- $course1context = context_course::instance($course1->id);
+ $course1context = \context_course::instance($course1->id);
$course2 = $this->getDataGenerator()->create_course();
- $course2context = context_course::instance($course2->id);
+ $course2context = \context_course::instance($course2->id);
- $forumdata = new stdClass();
+ $forumdata = new \stdClass();
$forumdata->course = $course1->id;
$forumc1 = $this->getDataGenerator()->create_module('forum', $forumdata);
- $forumc1context = context_module::instance($forumc1->cmid);
+ $forumc1context = \context_module::instance($forumc1->cmid);
$forumdata->course = $course2->id;
$forumc2 = $this->getDataGenerator()->create_module('forum', $forumdata);
- $forumc2context = context_module::instance($forumc2->cmid);
+ $forumc2context = \context_module::instance($forumc2->cmid);
- $blockdata = new stdClass();
+ $blockdata = new \stdClass();
$blockdata->parentcontextid = $course1context->id;
$blockc1 = $this->getDataGenerator()->create_block('online_users', $blockdata);
- $blockc1context = context_block::instance($blockc1->id);
+ $blockc1context = \context_block::instance($blockc1->id);
$blockdata->parentcontextid = $course2context->id;
$blockc2 = $this->getDataGenerator()->create_block('online_users', $blockdata);
- $blockc2context = context_block::instance($blockc2->id);
+ $blockc2context = \context_block::instance($blockc2->id);
$user1 = $this->getDataGenerator()->create_user();
- $user1context = context_user::instance($user1->id);
+ $user1context = \context_user::instance($user1->id);
$user2 = $this->getDataGenerator()->create_user();
- $user2context = context_user::instance($user2->id);
+ $user2context = \context_user::instance($user2->id);
// New role prohibiting Flickr Public access.
$roleid = create_role('No Flickr Public', 'noflickrpublic', 'No Flickr Public', '');
@@ -349,7 +354,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$this->assertTrue($caughtexception);
// Instance on a course level.
- $record = new stdClass();
+ $record = new \stdClass();
$record->contextid = $course1context->id;
$courserepoid = $this->getDataGenerator()->create_repository('flickr_public', $record)->id;
@@ -438,7 +443,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Instance on a user level.
// Instance on a course level.
- $record = new stdClass();
+ $record = new \stdClass();
$record->contextid = $user1context->id;
$user1repoid = $this->getDataGenerator()->create_repository('flickr_public', $record)->id;
$record->contextid = $user2context->id;
@@ -478,7 +483,7 @@ class core_repositorylib_testcase extends advanced_testcase {
accesslib_clear_all_caches_for_unit_testing();
// Check that a user can view SOME repositories when logged in as someone else.
- $params = new stdClass();
+ $params = new \stdClass();
$params->name = 'Dropbox';
$params->dropbox_issuerid = '2';
$privaterepoid = $this->getDataGenerator()->create_repository('dropbox')->id;
@@ -522,8 +527,8 @@ class core_repositorylib_testcase extends advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->create_repository_type('flickr_public');
$this->getDataGenerator()->create_repository_type('filesystem');
- $coursecontext = context_course::instance($course->id);
- $usercontext = context_user::instance($user->id);
+ $coursecontext = \context_course::instance($course->id);
+ $usercontext = \context_user::instance($user->id);
// Creating course instances.
$repo = $this->getDataGenerator()->create_repository('flickr_public', array('contextid' => $coursecontext->id));
@@ -561,7 +566,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Checking deletion upon course context deletion.
$course = $this->getDataGenerator()->create_course();
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
$repo = $this->getDataGenerator()->create_repository('flickr_public', array('contextid' => $coursecontext->id));
$courserepo = repository::get_repository_by_id($repo->id, $coursecontext);
$this->assertEquals(1, $DB->count_records('repository_instances', array('contextid' => $coursecontext->id)));
@@ -570,7 +575,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Checking deletion upon user context deletion.
$user = $this->getDataGenerator()->create_user();
- $usercontext = context_user::instance($user->id);
+ $usercontext = \context_user::instance($user->id);
$repo = $this->getDataGenerator()->create_repository('flickr_public', array('contextid' => $usercontext->id));
$userrepo = repository::get_repository_by_id($repo->id, $usercontext);
$this->assertEquals(1, $DB->count_records('repository_instances', array('contextid' => $usercontext->id)));
@@ -579,7 +584,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Checking deletion upon course deletion.
$course = $this->getDataGenerator()->create_course();
- $coursecontext = context_course::instance($course->id);
+ $coursecontext = \context_course::instance($course->id);
$repo = $this->getDataGenerator()->create_repository('flickr_public', array('contextid' => $coursecontext->id));
$courserepo = repository::get_repository_by_id($repo->id, $coursecontext);
$this->assertEquals(1, $DB->count_records('repository_instances', array('contextid' => $coursecontext->id)));
@@ -588,7 +593,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Checking deletion upon user deletion.
$user = $this->getDataGenerator()->create_user();
- $usercontext = context_user::instance($user->id);
+ $usercontext = \context_user::instance($user->id);
$repo = $this->getDataGenerator()->create_repository('flickr_public', array('contextid' => $usercontext->id));
$userrepo = repository::get_repository_by_id($repo->id, $usercontext);
$this->assertEquals(1, $DB->count_records('repository_instances', array('contextid' => $usercontext->id)));
@@ -606,7 +611,7 @@ class core_repositorylib_testcase extends advanced_testcase {
global $USER;
$filerecord = [];
- $filerecord['contextid'] = context_user::instance($USER->id)->id;
+ $filerecord['contextid'] = \context_user::instance($USER->id)->id;
$filerecord['component'] = 'user';
$filerecord['filearea'] = 'private';
$filerecord['itemid'] = 0;
@@ -629,7 +634,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$this->create_user_private_file('/ftexts/', 'file3.txt');
// Listing without filters returns 4 records (2 files and 2 directories).
- $repo = repository::get_repository_by_id($repoid, context_system::instance());
+ $repo = repository::get_repository_by_id($repoid, \context_system::instance());
$this->assertCount(4, $repo->get_listing()['list']);
// Listing with filters returns 3 records (1 files and 2 directories).
diff --git a/search/tests/area_category_test.php b/search/tests/area_category_test.php
index c0558688dae..814f3fd3e14 100644
--- a/search/tests/area_category_test.php
+++ b/search/tests/area_category_test.php
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_search;
/**
* Area category unit tests.
*
@@ -21,17 +22,7 @@
* @copyright 2018 Dmitrii Metelkin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-/**
- * Area category unit tests.
- *
- * @package core_search
- * @copyright 2018 Dmitrii Metelkin
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class search_area_category_testcase extends advanced_testcase {
+class area_category_test extends \advanced_testcase {
/**
* A helper function to get a mocked search area.
@@ -65,7 +56,7 @@ class search_area_category_testcase extends advanced_testcase {
$areas[] = null;
$areas[] = [$this->get_mocked_area('area2')];
$areas[] = $this;
- $areas[] = new stdClass();
+ $areas[] = new \stdClass();
$areas[] = $this->get_mocked_area('area3');
$areas[] = $this->get_mocked_area('area4');
diff --git a/search/tests/base_activity_test.php b/search/tests/base_activity_test.php
index d74ddead2fb..544b7c1f3bf 100644
--- a/search/tests/base_activity_test.php
+++ b/search/tests/base_activity_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Search engine base unit tests.
- *
- * @package core_search
- * @copyright 2017 Matt Porritt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_search;
defined('MOODLE_INTERNAL') || die();
@@ -35,7 +29,7 @@ require_once($CFG->dirroot . '/search/tests/fixtures/mock_search_area.php');
* @copyright 2017 Matt Porritt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class search_base_activity_testcase extends advanced_testcase {
+class base_activity_test extends \advanced_testcase {
/**
* @var \core_search::manager
*/
@@ -63,7 +57,7 @@ class search_base_activity_testcase extends advanced_testcase {
set_config('enableglobalsearch', true);
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
- $search = testable_core_search::instance();
+ $search = \testable_core_search::instance();
$this->generator = self::getDataGenerator()->get_plugin_generator('core_search');
$this->generator->setup();
@@ -153,7 +147,7 @@ class search_base_activity_testcase extends advanced_testcase {
// Construct the search document.
$rec = new \stdClass();
$rec->courseid = $course->id;
- $area = new core_mocksearch\search\mock_search_area();
+ $area = new \core_mocksearch\search\mock_search_area();
$record = $this->generator->create_record($rec);
$document = $area->get_document($record);
@@ -186,7 +180,7 @@ class search_base_activity_testcase extends advanced_testcase {
global $USER, $DB;
// Get all the forums to index (no restriction).
- $area = new mod_forum\search\activity();
+ $area = new \mod_forum\search\activity();
$results = self::recordset_to_indexed_array($area->get_document_recordset());
// Should return all forums.
@@ -211,7 +205,7 @@ class search_base_activity_testcase extends advanced_testcase {
// Now use context restrictions. First, the whole site (no change).
$results = self::recordset_to_indexed_array($area->get_document_recordset(
- 0, context_system::instance()));
+ 0, \context_system::instance()));
$this->assertEquals($allids, self::records_to_ids($results));
// Course 1 only.
@@ -249,13 +243,13 @@ class search_base_activity_testcase extends advanced_testcase {
// Find an arbitrary block on the system to get a block context.
$blockid = array_values($DB->get_records('block_instances', null, 'id', 'id', 0, 1))[0]->id;
- $blockcontext = context_block::instance($blockid);
+ $blockcontext = \context_block::instance($blockid);
// Block context (cannot return anything, so always null).
$this->assertNull($area->get_document_recordset(0, $blockcontext));
// User context (cannot return anything, so always null).
- $usercontext = context_user::instance($USER->id);
+ $usercontext = \context_user::instance($USER->id);
$this->assertNull($area->get_document_recordset(0, $usercontext));
}
@@ -265,7 +259,7 @@ class search_base_activity_testcase extends advanced_testcase {
* @param moodle_recordset $rs Recordset to convert
* @return array Array indexed by number (0, 1, 2, ...)
*/
- protected static function recordset_to_indexed_array(moodle_recordset $rs) {
+ protected static function recordset_to_indexed_array(\moodle_recordset $rs) {
$results = [];
foreach ($rs as $rec) {
$results[] = $rec;
@@ -292,11 +286,11 @@ class search_base_activity_testcase extends advanced_testcase {
* Tests the get_doc_url function.
*/
public function test_get_doc_url() {
- $area = new mod_forum\search\activity();
+ $area = new \mod_forum\search\activity();
$results = self::recordset_to_indexed_array($area->get_document_recordset());
for ($i = 0; $i < 4; $i++) {
- $this->assertEquals(new moodle_url('/mod/forum/view.php',
+ $this->assertEquals(new \moodle_url('/mod/forum/view.php',
['id' => $this->forums[$i + 1]->cmid]),
$area->get_doc_url($area->get_document($results[$i])));
}
@@ -321,7 +315,7 @@ class search_base_activity_testcase extends advanced_testcase {
set_coursemodule_visible($this->forums[3]->cmid, 0);
// Call check access on all the first three.
- $area = new mod_forum\search\activity();
+ $area = new \mod_forum\search\activity();
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $area->check_access(
$this->forums[1]->id));
$this->assertEquals(\core_search\manager::ACCESS_DELETED, $area->check_access(
diff --git a/search/tests/base_block_test.php b/search/tests/base_block_test.php
index e6f345870c1..c802fb28777 100644
--- a/search/tests/base_block_test.php
+++ b/search/tests/base_block_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 base_block class.
- *
- * @package core_search
- * @copyright 2017 The Open University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_search;
defined('MOODLE_INTERNAL') || die();
@@ -34,7 +28,7 @@ require_once(__DIR__ . '/fixtures/mock_block_area.php');
* @copyright 2017 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class base_block_testcase extends advanced_testcase {
+class base_block_test extends \advanced_testcase {
/**
* Tests getting the name out of the class name.
*/
@@ -136,7 +130,7 @@ class base_block_testcase extends advanced_testcase {
\context_block::instance($block9id);
// Get all the blocks.
- $area = new block_mockblock\search\area();
+ $area = new \block_mockblock\search\area();
$results = self::recordset_to_indexed_array($area->get_document_recordset());
// Only blocks 1, 3, 6, 7, 8, 9 should be returned. Check all the fields for the first two.
@@ -171,7 +165,7 @@ class base_block_testcase extends advanced_testcase {
// Now use context restrictions. First, the whole site (no change).
$results = self::recordset_to_indexed_array($area->get_document_recordset(
- 0, context_system::instance()));
+ 0, \context_system::instance()));
$this->assertEquals([$block1id, $block3id, $block6id, $block7id, $block8id, $block9id],
self::records_to_ids($results));
@@ -197,7 +191,7 @@ class base_block_testcase extends advanced_testcase {
$this->assertEquals([$block3id], self::records_to_ids($results));
// User context (no results).
- $usercontext = context_user::instance($USER->id);
+ $usercontext = \context_user::instance($USER->id);
$results = self::recordset_to_indexed_array($area->get_document_recordset(
0, $usercontext));
$this->assertCount(0, $results);
@@ -225,7 +219,7 @@ class base_block_testcase extends advanced_testcase {
* @param moodle_recordset $rs Recordset to convert
* @return array Array indexed by number (0, 1, 2, ...)
*/
- protected static function recordset_to_indexed_array(moodle_recordset $rs) {
+ protected static function recordset_to_indexed_array(\moodle_recordset $rs) {
$results = [];
foreach ($rs as $rec) {
$results[] = $rec;
@@ -271,9 +265,9 @@ class base_block_testcase extends advanced_testcase {
$blockid = $DB->insert_record('block_instances', $instance);
// Get document URL.
- $area = new block_mockblock\search\area();
+ $area = new \block_mockblock\search\area();
$doc = $this->get_doc($course->id, $blockid);
- $expected = new moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $blockid);
+ $expected = new \moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $blockid);
$this->assertEquals($expected, $area->get_doc_url($doc));
$this->assertEquals($expected, $area->get_context_url($doc));
@@ -286,7 +280,7 @@ class base_block_testcase extends advanced_testcase {
// Get document URL.
$doc2 = $this->get_doc($course->id, $block2id);
- $expected = new moodle_url('/', ['redirect' => 0], 'inst' . $block2id);
+ $expected = new \moodle_url('/', ['redirect' => 0], 'inst' . $block2id);
$this->assertEquals($expected, $area->get_doc_url($doc2));
$this->assertEquals($expected, $area->get_context_url($doc2));
@@ -302,7 +296,7 @@ class base_block_testcase extends advanced_testcase {
$doc3 = $this->get_doc($course->id, $block3id);
$this->assertDebuggingCalledCount(2, [$debugmessage, $debugmessage]);
- $expected = new moodle_url('/mod/page/view.php', ['id' => $page->cmid], 'inst' . $block3id);
+ $expected = new \moodle_url('/mod/page/view.php', ['id' => $page->cmid], 'inst' . $block3id);
$this->assertEquals($expected, $area->get_doc_url($doc3));
$this->assertDebuggingCalled($debugmessage);
$this->assertEquals($expected, $area->get_context_url($doc3));
@@ -315,7 +309,7 @@ class base_block_testcase extends advanced_testcase {
// Get document URL.
$doc = $this->get_doc($course->id, $block4id);
- $expected = new moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $block4id);
+ $expected = new \moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $block4id);
$this->assertEquals($expected, $area->get_doc_url($doc));
$this->assertEquals($expected, $area->get_context_url($doc));
@@ -325,7 +319,7 @@ class base_block_testcase extends advanced_testcase {
// Get document URL.
$doc = $this->get_doc($course->id, $block5id);
- $expected = new moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $block5id);
+ $expected = new \moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $block5id);
$this->assertEquals($expected, $area->get_doc_url($doc));
$this->assertEquals($expected, $area->get_context_url($doc));
}
@@ -353,7 +347,7 @@ class base_block_testcase extends advanced_testcase {
$blockid = $DB->insert_record('block_instances', $instance);
// Check access for block that exists.
- $area = new block_mockblock\search\area();
+ $area = new \block_mockblock\search\area();
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $area->check_access($blockid));
// Check access for nonexistent block.
@@ -420,7 +414,7 @@ class base_block_testcase extends advanced_testcase {
\context_block::instance($blockid4);
// Check list of contexts.
- $area = new block_mockblock\search\area();
+ $area = new \block_mockblock\search\area();
$contexts = iterator_to_array($area->get_contexts_to_reindex(), false);
$expected = [
$context2,
@@ -438,8 +432,8 @@ class base_block_testcase extends advanced_testcase {
* @return \core_search\document Document object
*/
protected function get_doc($courseid, $blockinstanceid) {
- $engine = testable_core_search::instance()->get_engine();
- $area = new block_mockblock\search\area();
+ $engine = \testable_core_search::instance()->get_engine();
+ $area = new \block_mockblock\search\area();
$docdata = ['id' => $blockinstanceid, 'courseid' => $courseid,
'areaid' => $area->get_area_id(), 'itemid' => 0];
return $engine->to_document($area, $docdata);
diff --git a/search/tests/document_icon_test.php b/search/tests/document_icon_test.php
index 917a2394267..7fbb837f1b7 100644
--- a/search/tests/document_icon_test.php
+++ b/search/tests/document_icon_test.php
@@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Document icon unit tests.
- *
- * @package core_search
- * @copyright 2018 Dmitrii Metelkin
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_search;
/**
* Document icon unit tests.
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2018 Dmitrii Metelkin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class search_document_icon_testcase extends advanced_testcase {
+class document_icon_test extends \advanced_testcase {
/**
* Test that default component gets returned correctly.
*/
diff --git a/search/tests/document_test.php b/search/tests/document_test.php
index dcf45e87d4e..b7acda2ac4d 100644
--- a/search/tests/document_test.php
+++ b/search/tests/document_test.php
@@ -27,12 +27,12 @@ use stdClass;
* Unit tests for search document.
*
* @package core_search
- * @category phpunit
+ * @category test
* @copyright 2016 Eric Merrill {@link http://www.merrilldigital.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_search\document
*/
-class document_test extends advanced_testcase {
+class document_test extends \advanced_testcase {
/**
* Setup to ensure that fixtures are loaded.
@@ -53,7 +53,7 @@ class document_test extends advanced_testcase {
set_config('enableglobalsearch', true);
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
- $search = testable_core_search::instance();
+ $search = \testable_core_search::instance();
$this->generator = self::getDataGenerator()->get_plugin_generator('core_search');
$this->generator->setup();
diff --git a/search/tests/top_result_test.php b/search/tests/top_result_test.php
index 3ac6fd96e73..9fda6cf16c7 100644
--- a/search/tests/top_result_test.php
+++ b/search/tests/top_result_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 top results
- *
- * @package core_search
- * @author Nathan Nguyen
- * @copyright Catalyst IT
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_search;
defined('MOODLE_INTERNAL') || die();
@@ -37,7 +30,7 @@ require_once(__DIR__ . '/fixtures/mock_search_area.php');
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class search_top_result_testcase extends advanced_testcase {
+class top_result_test extends \advanced_testcase {
/** @var stdClass course 1 */
protected $course1;
@@ -61,7 +54,7 @@ class search_top_result_testcase extends advanced_testcase {
$this->setAdminUser();
// Search engine.
- $this->search = testable_core_search::instance(new \search_simpledb\engine());
+ $this->search = \testable_core_search::instance(new \search_simpledb\engine());
// Set default configurations.
set_config('searchallavailablecourses', 1);
diff --git a/tag/tests/taglib_test.php b/tag/tests/taglib_test.php
index bad9b14c242..91a4681c593 100644
--- a/tag/tests/taglib_test.php
+++ b/tag/tests/taglib_test.php
@@ -14,6 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+namespace core_tag;
+
+use core_tag_area;
+use core_tag_collection;
+use core_tag_tag;
+
/**
* Tag related unit tests.
*
@@ -22,12 +28,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 core_tag_taglib_testcase extends advanced_testcase {
+class taglib_test extends \advanced_testcase {
/**
* Test set up.
@@ -81,7 +82,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
// Create the tag and tag instance we are going to delete.
- core_tag_tag::add_item_tag('core', 'course', $course->id, context_course::instance($course->id), 'A random tag');
+ core_tag_tag::add_item_tag('core', 'course', $course->id, \context_course::instance($course->id), 'A random tag');
$this->assertEquals(1, $DB->count_records('tag'));
$this->assertEquals(1, $DB->count_records('tag_instance'));
@@ -117,27 +118,27 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Create a tag (ordering should start at 1).
$ti1 = core_tag_tag::add_item_tag('core', 'course', $course1->id,
- context_course::instance($course1->id), 'A random tag for course 1');
+ \context_course::instance($course1->id), 'A random tag for course 1');
$this->assertEquals(1, $DB->get_field('tag_instance', 'ordering', ['id' => $ti1]));
// Create another tag with a common component, itemtype and itemid (should increase the ordering by 1).
$ti2 = core_tag_tag::add_item_tag('core', 'course', $course1->id,
- context_course::instance($course1->id), 'Another random tag for course 1');
+ \context_course::instance($course1->id), 'Another random tag for course 1');
$this->assertEquals(2, $DB->get_field('tag_instance', 'ordering', ['id' => $ti2]));
// Create a new tag with the same component and itemtype, but different itemid (should start counting from 1 again).
$ti3 = core_tag_tag::add_item_tag('core', 'course', $course2->id,
- context_course::instance($course2->id), 'A random tag for course 2');
+ \context_course::instance($course2->id), 'A random tag for course 2');
$this->assertEquals(1, $DB->get_field('tag_instance', 'ordering', ['id' => $ti3]));
// Create a new tag with a different itemtype (should start counting from 1 again).
$ti4 = core_tag_tag::add_item_tag('core', 'user', $user1->id,
- context_user::instance($user1->id), 'A random tag for user 1');
+ \context_user::instance($user1->id), 'A random tag for user 1');
$this->assertEquals(1, $DB->get_field('tag_instance', 'ordering', ['id' => $ti4]));
// Create a new tag with a different component (should start counting from 1 again).
$ti5 = core_tag_tag::add_item_tag('mod_book', 'book_chapters', $chapter1id,
- context_module::instance($book1->cmid), 'A random tag for a book chapter');
+ \context_module::instance($book1->cmid), 'A random tag for a book chapter');
$this->assertEquals(1, $DB->get_field('tag_instance', 'ordering', ['id' => $ti5]));
}
@@ -146,7 +147,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
* This function was deprecated in 3.1
*/
public function test_tag_assign() {
- $this->expectException('coding_exception');
+ $this->expectException(\coding_exception::class);
$this->expectExceptionMessage('tag_assign() can not be used anymore. Please use core_tag_tag::set_item_tags() ' .
'or core_tag_tag::add_item_tag() instead.');
tag_assign();
@@ -168,7 +169,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Create a course to tag.
$course = $this->getDataGenerator()->create_course();
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
// Test clean up instances with tags that no longer exist.
$tags = array();
@@ -199,7 +200,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Test clean up with users that have been deleted.
// Create a tag for this course.
foreach ($users as $user) {
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
core_tag_tag::set_item_tags('core', 'user', $user->id, $context, array($tags[0]->rawname));
}
$usertags = $DB->count_records('tag_instance', array('itemtype' => 'user'));
@@ -226,11 +227,11 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Test clean up where a post has been removed.
// Create default post.
- $post = new stdClass();
+ $post = new \stdClass();
$post->userid = $users[1]->id;
$post->content = 'test post content text';
$post->id = $DB->insert_record('post', $post);
- $context = context_system::instance();
+ $context = \context_system::instance();
core_tag_tag::set_item_tags('core', 'post', $post->id, $context, array($tags[0]->rawname));
// Add another one with a fake post id to be removed.
@@ -255,7 +256,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Setup.
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
// Create some tag instances.
for ($i = 0; $i < 10; $i++) {
@@ -281,9 +282,9 @@ class core_tag_taglib_testcase extends advanced_testcase {
public function test_set_item_tags_with_invalid_userid(): void {
$user = $this->getDataGenerator()->create_user();
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
$this->expectExceptionMessage('Related tags can not have tag instance userid');
- core_tag_tag::set_item_tags('core', 'tag', 1, context_system::instance(), ['all', 'night', 'long'], $user->id);
+ core_tag_tag::set_item_tags('core', 'tag', 1, \context_system::instance(), ['all', 'night', 'long'], $user->id);
}
/**
@@ -306,13 +307,12 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Several records have both 'cat' and 'cats' tags attached to them.
// This will make those tags automatically correlated.
// Same with 'dog', 'dogs' and 'puppy.
- core_tag_tag::set_item_tags('core', 'user', $user1->id, context_user::instance($user1->id), array('cat', 'cats'));
- core_tag_tag::set_item_tags('core', 'user', $user2->id, context_user::instance($user2->id), array('cat', 'cats', 'kitten'));
- core_tag_tag::set_item_tags('core', 'user', $user3->id, context_user::instance($user3->id), array('cat', 'cats'));
- core_tag_tag::set_item_tags('core', 'user', $user4->id, context_user::instance($user4->id), array('dog', 'dogs', 'puppy'));
- core_tag_tag::set_item_tags('core', 'user', $user5->id, context_user::instance($user5->id), array('dog', 'dogs', 'puppy'));
- core_tag_tag::set_item_tags('core', 'user', $user6->id, context_user::instance($user6->id), array('dog', 'dogs', 'puppy'));
-
+ core_tag_tag::set_item_tags('core', 'user', $user1->id, \context_user::instance($user1->id), array('cat', 'cats'));
+ core_tag_tag::set_item_tags('core', 'user', $user2->id, \context_user::instance($user2->id), array('cat', 'cats', 'kitten'));
+ core_tag_tag::set_item_tags('core', 'user', $user3->id, \context_user::instance($user3->id), array('cat', 'cats'));
+ core_tag_tag::set_item_tags('core', 'user', $user4->id, \context_user::instance($user4->id), array('dog', 'dogs', 'puppy'));
+ core_tag_tag::set_item_tags('core', 'user', $user5->id, \context_user::instance($user5->id), array('dog', 'dogs', 'puppy'));
+ core_tag_tag::set_item_tags('core', 'user', $user6->id, \context_user::instance($user6->id), array('dog', 'dogs', 'puppy'));
$tags = core_tag_tag::get_by_name_bulk(core_tag_collection::get_default(),
array('cat', 'cats', 'dog', 'dogs', 'kitten', 'puppy'), '*');
@@ -435,7 +435,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$defaultcoll = core_tag_collection::get_default();
// Setting tags will create non-standard tags 'cat', 'dog' and 'fish'.
- core_tag_tag::set_item_tags('core', 'user', $user->id, context_user::instance($user->id), array('cat', 'dog', 'fish'));
+ core_tag_tag::set_item_tags('core', 'user', $user->id, \context_user::instance($user->id), array('cat', 'dog', 'fish'));
$this->assertTrue($DB->record_exists('tag', array('name' => 'cat')));
$this->assertTrue($DB->record_exists('tag', array('name' => 'dog')));
@@ -466,7 +466,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$this->assertFalse($DB->record_exists('tag', array('name' => 'cat')));
// Assign tag to non-existing record. Make sure tag was created in the DB.
- core_tag_tag::set_item_tags('core', 'course', 1231231, context_system::instance(), array('bird'));
+ core_tag_tag::set_item_tags('core', 'course', 1231231, \context_system::instance(), array('bird'));
$this->assertTrue($DB->record_exists('tag', array('name' => 'bird')));
$task->cleanup();
@@ -476,7 +476,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Now we have a tag instance pointing on 'sometag' tag.
$user = $this->getDataGenerator()->create_user();
- core_tag_tag::set_item_tags('core', 'user', $user->id, context_user::instance($user->id), array('sometag'));
+ core_tag_tag::set_item_tags('core', 'user', $user->id, \context_user::instance($user->id), array('sometag'));
$sometag = core_tag_tag::get_by_name($defaultcoll, 'sometag');
$this->assertTrue($DB->record_exists('tag_instance', array('tagid' => $sometag->id)));
@@ -509,7 +509,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Create a course to tag.
$course = $this->getDataGenerator()->create_course();
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$initialtagscount = $DB->count_records('tag');
@@ -654,14 +654,14 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid2 = core_tag_collection::create(array('name' => 'newcoll'))->id;
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $blogpost = new blog_entry(null, array('subject' => 'test'), null);
- $states = blog_entry::get_applicable_publish_states();
+ $blogpost = new \blog_entry(null, array('subject' => 'test'), null);
+ $states = \blog_entry::get_applicable_publish_states();
$blogpost->publishstate = reset($states);
$blogpost->add();
- core_tag_tag::set_item_tags('core', 'user', $user1->id, context_user::instance($user1->id),
+ core_tag_tag::set_item_tags('core', 'user', $user1->id, \context_user::instance($user1->id),
array('Tag1', 'Tag2'));
- core_tag_tag::set_item_tags('core', 'user', $user2->id, context_user::instance($user2->id),
+ core_tag_tag::set_item_tags('core', 'user', $user2->id, \context_user::instance($user2->id),
array('Tag2', 'Tag3'));
$this->getDataGenerator()->create_tag(array('rawname' => 'Tag4',
'tagcollid' => $collid1, 'isstandard' => 1));
@@ -697,7 +697,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
global $DB;
list($collid1, $collid2, $user1, $user2, $blogpost) = $this->prepare_move_tags();
- core_tag_tag::set_item_tags('core', 'post', $blogpost->id, context_system::instance(),
+ core_tag_tag::set_item_tags('core', 'post', $blogpost->id, \context_system::instance(),
array('Tag1', 'Tag3'));
// Move 'user' area from collection 1 to collection 2, make sure tag Tag2 was moved and tags Tag1 and Tag3 were duplicated.
@@ -727,7 +727,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tagareablog = $DB->get_record('tag_area', array('itemtype' => 'post', 'component' => 'core'));
core_tag_area::update($tagareablog, array('tagcollid' => $collid2));
- core_tag_tag::set_item_tags('core', 'post', $blogpost->id, context_system::instance(),
+ core_tag_tag::set_item_tags('core', 'post', $blogpost->id, \context_system::instance(),
array('TAG1', 'Tag3'));
// Move 'user' area from collection 1 to collection 2,
@@ -761,7 +761,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tagareablog = $DB->get_record('tag_area', array('itemtype' => 'post', 'component' => 'core'));
core_tag_area::update($tagareablog, array('tagcollid' => $collid2));
- core_tag_tag::set_item_tags('core', 'post', $blogpost->id, context_system::instance(),
+ core_tag_tag::set_item_tags('core', 'post', $blogpost->id, \context_system::instance(),
array('TAG1', 'Tag3'));
// Move 'user' area from collection 1 to collection 2, make sure tags were moved completely.
@@ -838,7 +838,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
* This function was deprecated in 3.1
*/
public function test_normalize() {
- $this->expectException('coding_exception');
+ $this->expectException(\coding_exception::class);
$this->expectExceptionMessage('tag_normalize() can not be used anymore. Please use ' .
'core_tag_tag::normalize().');
tag_normalize();
@@ -900,7 +900,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
);
$collid = core_tag_collection::get_default();
- $context = context_system::instance();
+ $context = \context_system::instance();
foreach ($initialtags as $id => $taglist) {
core_tag_tag::set_item_tags('core', 'course', $id + 10, $context, $initialtags[$id]);
}
@@ -931,7 +931,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
*/
public function test_combine_tags_with_related() {
$collid = core_tag_collection::get_default();
- $context = context_system::instance();
+ $context = \context_system::instance();
core_tag_tag::set_item_tags('core', 'course', 10, $context, array('Cat', 'Cats', 'Dog'));
core_tag_tag::get_by_name($collid, 'Cat', '*')->set_related_tags(array('Kitty'));
core_tag_tag::get_by_name($collid, 'Cats', '*')->set_related_tags(array('Cat', 'Kitten', 'Kitty'));
@@ -975,7 +975,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Add tag that does not have any correlations.
$user7 = $this->getDataGenerator()->create_user();
- core_tag_tag::set_item_tags('core', 'user', $user7->id, context_user::instance($user7->id), array('hippo'));
+ core_tag_tag::set_item_tags('core', 'user', $user7->id, \context_user::instance($user7->id), array('hippo'));
$tags['hippo'] = core_tag_tag::get_by_name(core_tag_collection::get_default(), 'hippo', '*');
// Combine tag 'cat' into 'hippo'. Now 'hippo' should have the same correlations 'cat' used to have and also
@@ -1001,7 +1001,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
@@ -1019,7 +1019,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
core_tag_tag::set_item_tags($component, $itemtype, $user->id, $context, $tagnames);
@@ -1048,7 +1048,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
core_tag_tag::set_item_tags($component, $itemtype, $user->id, $context, array_slice($tagnames, 0, 2));
@@ -1080,9 +1080,9 @@ class core_tag_taglib_testcase extends advanced_testcase {
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
- $context3 = context_user::instance($user3->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
+ $context3 = \context_user::instance($user3->id);
$component = 'core';
$itemtype = 'user';
@@ -1118,7 +1118,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
global $CFG;
$user1 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
+ $context1 = \context_user::instance($user1->id);
$component = 'core';
$itemtype = 'user';
$itemids = [$user1->id];
@@ -1137,7 +1137,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
*/
public function test_get_items_tags_empty_itemids() {
$user1 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
+ $context1 = \context_user::instance($user1->id);
$component = 'core';
$itemtype = 'user';
@@ -1195,8 +1195,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemids = [$user1->id, $user2->id, $user3->id];
@@ -1237,7 +1237,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user1->id);
+ $context = \context_user::instance($user1->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1279,8 +1279,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1318,8 +1318,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1368,8 +1368,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1420,8 +1420,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1464,8 +1464,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1505,7 +1505,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
*/
public function test_delete_instances_as_record_empty_set() {
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1528,7 +1528,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1553,7 +1553,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1576,7 +1576,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1598,7 +1598,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
*/
public function test_delete_instances_by_id_empty_set() {
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1621,7 +1621,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1645,7 +1645,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1668,7 +1668,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1696,7 +1696,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype1 = 'user';
$itemtype2 = 'course';
@@ -1726,7 +1726,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
- $context = context_user::instance($user->id);
+ $context = \context_user::instance($user->id);
$component = 'core';
$itemtype1 = 'user';
$itemtype2 = 'course';
@@ -1760,8 +1760,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype1 = 'user';
$itemtype2 = 'course';
@@ -1796,8 +1796,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype1 = 'user';
$itemtype2 = 'course';
@@ -1841,8 +1841,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1869,8 +1869,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1901,9 +1901,9 @@ class core_tag_taglib_testcase extends advanced_testcase {
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
- $context3 = context_user::instance($user3->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
+ $context3 = \context_user::instance($user3->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1941,8 +1941,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
- $context1 = context_user::instance($user1->id);
- $context2 = context_user::instance($user2->id);
+ $context1 = \context_user::instance($user1->id);
+ $context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
diff --git a/user/tests/editlib_test.php b/user/tests/editlib_test.php
index 0b71e393dbd..37b3a30ee1a 100644
--- a/user/tests/editlib_test.php
+++ b/user/tests/editlib_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 user/editlib.php.
- *
- * @package core_user
- * @category phpunit
- * @copyright 2013 Adrian Greeve
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_user;
defined('MOODLE_INTERNAL') || die();
@@ -32,11 +25,11 @@ require_once($CFG->dirroot.'/user/editlib.php');
* Unit tests for user editlib api.
*
* @package core_user
- * @category phpunit
+ * @category test
* @copyright 2013 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_user_editlib_testcase extends advanced_testcase {
+class editlib_test extends \advanced_testcase {
/**
* Test that the required fields are returned in the correct order.
@@ -44,7 +37,7 @@ class core_user_editlib_testcase extends advanced_testcase {
function test_useredit_get_required_name_fields() {
global $CFG;
// Back up config settings for restore later.
- $originalcfg = new stdClass();
+ $originalcfg = new \stdClass();
$originalcfg->fullnamedisplay = $CFG->fullnamedisplay;
$CFG->fullnamedisplay = 'language';
@@ -70,7 +63,7 @@ class core_user_editlib_testcase extends advanced_testcase {
function test_useredit_get_enabled_name_fields() {
global $CFG;
// Back up config settings for restore later.
- $originalcfg = new stdClass();
+ $originalcfg = new \stdClass();
$originalcfg->fullnamedisplay = $CFG->fullnamedisplay;
$CFG->fullnamedisplay = 'language';
@@ -96,7 +89,7 @@ class core_user_editlib_testcase extends advanced_testcase {
function test_useredit_get_disabled_name_fields() {
global $CFG;
// Back up config settings for restore later.
- $originalcfg = new stdClass();
+ $originalcfg = new \stdClass();
$originalcfg->fullnamedisplay = $CFG->fullnamedisplay;
$CFG->fullnamedisplay = 'language';
diff --git a/user/tests/group_non_members_selector_test.php b/user/tests/group_non_members_selector_test.php
index a4837f88fa4..46e07a01e7b 100644
--- a/user/tests/group_non_members_selector_test.php
+++ b/user/tests/group_non_members_selector_test.php
@@ -14,14 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for {@link group_non_members_selector} class.
- *
- * @package core_user
- * @category test
- * @copyright 2019 Huong Nguyen
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_user;
+
+use group_non_members_selector;
defined('MOODLE_INTERNAL') || die();
@@ -36,7 +31,7 @@ require_once($CFG->dirroot . '/user/selector/lib.php');
* @copyright 2019 Huong Nguyen
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_group_non_members_selector_testcase extends advanced_testcase {
+class group_non_members_selector_test extends \advanced_testcase {
/**
* Test find_users that only return group non members
diff --git a/user/tests/myprofile_test.php b/user/tests/myprofile_test.php
index 5315c3e21cd..b7bd3761a99 100644
--- a/user/tests/myprofile_test.php
+++ b/user/tests/myprofile_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 core_user\output\myprofile
- *
- * @package core_user
- * @category test
- * @copyright 2015 onwards Ankit Agarwal
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5)
- */
+namespace core_user;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -35,20 +28,20 @@ require_once($CFG->dirroot . "/user/tests/fixtures/myprofile_fixtures.php");
* @copyright 2015 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5)
*/
-class core_user_myprofile_testcase extends advanced_testcase {
+class myprofile_test extends \advanced_testcase {
/**
* Test node::__construct().
*/
public function test_node__construct() {
$node = new \core_user\output\myprofile\node('parentcat', 'nodename',
- 'nodetitle', 'after', 'www.google.com', 'description', new pix_icon('i/course', ''), 'class1 class2');
+ 'nodetitle', 'after', 'www.google.com', 'description', new \pix_icon('i/course', ''), 'class1 class2');
$this->assertSame('parentcat', $node->parentcat);
$this->assertSame('nodename', $node->name);
$this->assertSame('nodetitle', $node->title);
$this->assertSame('after', $node->after);
- $url = new moodle_url('www.google.com');
+ $url = new \moodle_url('www.google.com');
$this->assertEquals($url, $node->url);
- $this->assertEquals(new pix_icon('i/course', ''), $node->icon);
+ $this->assertEquals(new \pix_icon('i/course', ''), $node->icon);
$this->assertSame('class1 class2', $node->classes);
}
@@ -100,7 +93,7 @@ class core_user_myprofile_testcase extends advanced_testcase {
$category->add_node($node2);
$category->add_node($node1);
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
$category->validate_after_order();
}
@@ -117,7 +110,7 @@ class core_user_myprofile_testcase extends advanced_testcase {
$category->add_node($node2);
$category->add_node($node1);
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
$category->validate_after_order();
}
@@ -213,7 +206,7 @@ class core_user_myprofile_testcase extends advanced_testcase {
// Add a node with invalid 'after' and make sure an exception is thrown.
$node7 = new \core_user\output\myprofile\node('category', 'node7', 'nodetitle', 'noderandom');
$category->add_node($node7);
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
$category->sort_nodes();
}
@@ -269,7 +262,7 @@ class core_user_myprofile_testcase extends advanced_testcase {
$this->assertEquals($node1, $node);
// Can't add node with same name.
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
$tree->add_node($node1);
}
@@ -285,7 +278,7 @@ class core_user_myprofile_testcase extends advanced_testcase {
$this->assertEquals($category1, $category);
// Can't add node with same name.
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
$tree->add_category($category1);
}
@@ -372,7 +365,7 @@ class core_user_myprofile_testcase extends advanced_testcase {
$this->assertEquals($category6, $category);
// Can't add category with same name.
- $this->expectException(coding_exception::class);
+ $this->expectException(\coding_exception::class);
$tree->add_category($category1);
}
}
diff --git a/user/tests/profilelib_test.php b/user/tests/profilelib_test.php
index a49dc6bae81..dc0978ce789 100644
--- a/user/tests/profilelib_test.php
+++ b/user/tests/profilelib_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 user/profile/lib.php.
- *
- * @package core_user
- * @copyright 2014 The Open University
- * @licensehttp://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
+namespace core_user;
/**
* Unit tests for user/profile/lib.php.
@@ -33,7 +23,7 @@ global $CFG;
* @copyright 2014 The Open University
* @licensehttp://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_user_profilelib_testcase extends advanced_testcase {
+class profilelib_test extends \advanced_testcase {
/**
* Tests profile_get_custom_fields function and checks it is consistent
* with profile_user_record.
@@ -111,9 +101,9 @@ class core_user_profilelib_testcase extends advanced_testcase {
// Course without sections.
$course = $this->getDataGenerator()->create_course();
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$user = $this->getDataGenerator()->create_user();
- $usercontext = context_user::instance($user->id);
+ $usercontext = \context_user::instance($user->id);
$this->setUser($user);
diff --git a/user/tests/userlib_test.php b/user/tests/userlib_test.php
index c024be9fa45..e0f50b0a8cb 100644
--- a/user/tests/userlib_test.php
+++ b/user/tests/userlib_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 user/lib.php.
- *
- * @package core_user
- * @category phpunit
- * @copyright 2013 Rajesh Taneja
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_user;
defined('MOODLE_INTERNAL') || die();
@@ -32,11 +25,11 @@ require_once($CFG->dirroot.'/user/lib.php');
* Unit tests for user lib api.
*
* @package core_user
- * @category phpunit
+ * @category test
* @copyright 2013 Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_userliblib_testcase extends advanced_testcase {
+class userlib_test extends \advanced_testcase {
/**
* Test user_get_user_details_courses
*/
@@ -51,7 +44,7 @@ class core_userliblib_testcase extends advanced_testcase {
$user3 = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
- $coursecontext = context_course::instance($course1->id);
+ $coursecontext = \context_course::instance($course1->id);
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
$this->getDataGenerator()->enrol_user($user2->id, $course1->id);
@@ -167,7 +160,7 @@ class core_userliblib_testcase extends advanced_testcase {
$this->assertSame($user->id, $event->objectid);
$this->assertSame('user_updated', $event->get_legacy_eventname());
$this->assertEventLegacyData($dbuser, $event);
- $this->assertEquals(context_user::instance($user->id), $event->get_context());
+ $this->assertEquals(\context_user::instance($user->id), $event->get_context());
$expectedlogdata = array(SITEID, 'user', 'update', 'view.php?id='.$user->id, '');
$this->assertEventLegacyLogData($expectedlogdata, $event);
@@ -261,7 +254,7 @@ class core_userliblib_testcase extends advanced_testcase {
$this->assertInstanceOf('\core\event\user_created', $event);
$this->assertEquals($user['id'], $event->objectid);
$this->assertEquals('user_created', $event->get_legacy_eventname());
- $this->assertEquals(context_user::instance($user['id']), $event->get_context());
+ $this->assertEquals(\context_user::instance($user['id']), $event->get_context());
$this->assertEventLegacyData($dbuser, $event);
$expectedlogdata = array(SITEID, 'user', 'add', '/view.php?id='.$event->objectid, fullname($dbuser));
$this->assertEventLegacyLogData($expectedlogdata, $event);
@@ -318,7 +311,7 @@ class core_userliblib_testcase extends advanced_testcase {
'username' => 'newuser',
], false, false);
- $user = core_user::get_user($userid);
+ $user = \core_user::get_user($userid);
$this->assertEquals($CFG->calendartype, $user->calendartype);
$this->assertEquals($CFG->defaultpreference_maildisplay, $user->maildisplay);
$this->assertEquals($CFG->defaultpreference_mailformat, $user->mailformat);
@@ -582,7 +575,7 @@ class core_userliblib_testcase extends advanced_testcase {
// Course without sections.
$course = $this->getDataGenerator()->create_course();
- $context = context_course::instance($course->id);
+ $context = \context_course::instance($course->id);
$this->setAdminUser();
@@ -650,9 +643,9 @@ class core_userliblib_testcase extends advanced_testcase {
// Create two courses.
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
- $coursecontext = context_course::instance($course2->id);
+ $coursecontext = \context_course::instance($course2->id);
// Prepare another course with separate groups and groupmodeforce set to true.
- $record = new stdClass();
+ $record = new \stdClass();
$record->groupmode = 1;
$record->groupmodeforce = 1;
$course3 = $this->getDataGenerator()->create_course($record);
@@ -719,7 +712,7 @@ class core_userliblib_testcase extends advanced_testcase {
// Test the user:viewalldetails cap check using the course creator role which, by default, can't see student profiles.
$this->setUser($user7);
$this->assertFalse(user_can_view_profile($user4));
- assign_capability('moodle/user:viewalldetails', CAP_ALLOW, $coursecreatorrole->id, context_system::instance()->id, true);
+ assign_capability('moodle/user:viewalldetails', CAP_ALLOW, $coursecreatorrole->id, \context_system::instance()->id, true);
reload_all_capabilities();
$this->assertTrue(user_can_view_profile($user4));
unassign_capability('moodle/user:viewalldetails', $coursecreatorrole->id, $coursecontext->id);
@@ -741,7 +734,7 @@ class core_userliblib_testcase extends advanced_testcase {
// Even with cap, still guests should not be allowed in.
$guestrole = $DB->get_records_menu('role', array('shortname' => 'guest'), 'id', 'archetype, id');
- assign_capability('moodle/user:viewdetails', CAP_ALLOW, $guestrole['guest'], context_system::instance()->id, true);
+ assign_capability('moodle/user:viewdetails', CAP_ALLOW, $guestrole['guest'], \context_system::instance()->id, true);
reload_all_capabilities();
foreach ($users as $user) {
$this->assertFalse(user_can_view_profile($user));
@@ -775,18 +768,18 @@ class core_userliblib_testcase extends advanced_testcase {
$this->getDataGenerator()->role_assign($managerrole->id, $user9->id);
// Make sure viewalldetails and viewdetails are overridden to 'prevent' (i.e. can be overridden at a lower context).
- $systemcontext = context_system::instance();
+ $systemcontext = \context_system::instance();
assign_capability('moodle/user:viewdetails', CAP_PREVENT, $managerrole->id, $systemcontext, true);
assign_capability('moodle/user:viewalldetails', CAP_PREVENT, $managerrole->id, $systemcontext, true);
// And override these to 'Allow' in a specific course.
- $course4context = context_course::instance($course4->id);
+ $course4context = \context_course::instance($course4->id);
assign_capability('moodle/user:viewalldetails', CAP_ALLOW, $managerrole->id, $course4context, true);
assign_capability('moodle/user:viewdetails', CAP_ALLOW, $managerrole->id, $course4context, true);
// The manager now shouldn't have viewdetails in the system or user context.
$this->setUser($user9);
- $user1context = context_user::instance($user1->id);
+ $user1context = \context_user::instance($user1->id);
$this->assertFalse(has_capability('moodle/user:viewdetails', $systemcontext));
$this->assertFalse(has_capability('moodle/user:viewdetails', $user1context));
@@ -811,7 +804,7 @@ class core_userliblib_testcase extends advanced_testcase {
$studentfullname = fullname($student);
$course1 = $this->getDataGenerator()->create_course();
- $coursecontext = context_course::instance($course1->id);
+ $coursecontext = \context_course::instance($course1->id);
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($teacher->id, $course1->id);
diff --git a/user/tests/userroleseditable_test.php b/user/tests/userroleseditable_test.php
index 4224fae0057..04f75e25410 100644
--- a/user/tests/userroleseditable_test.php
+++ b/user/tests/userroleseditable_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 user/lib.php.
- *
- * @package core_user
- * @copyright 2017 Damyon Wiese
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+namespace core_user;
/**
* Unit tests for user roles editable class.
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class userroleseditable_testcase extends advanced_testcase {
+class userroleseditable_test extends \advanced_testcase {
/**
* Test user roles editable.
*/
@@ -45,7 +37,7 @@ class userroleseditable_testcase extends advanced_testcase {
$user2 = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
- $coursecontext = context_course::instance($course1->id);
+ $coursecontext = \context_course::instance($course1->id);
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
diff --git a/user/tests/userselector_test.php b/user/tests/userselector_test.php
index fcb39b1ca86..2cdf60d7714 100644
--- a/user/tests/userselector_test.php
+++ b/user/tests/userselector_test.php
@@ -14,14 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Provides {@link core_user_selector_testcase} class.
- *
- * @package core_user
- * @category test
- * @copyright 2018 David Mudrák
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace core_user;
+
+use testable_user_selector;
defined('MOODLE_INTERNAL') || die();
@@ -32,10 +27,12 @@ require_once($CFG->dirroot.'/user/tests/fixtures/testable_user_selector.php');
/**
* Tests for the implementation of {@link user_selector_base} class.
*
+ * @package core_user
+ * @category test
* @copyright 2018 David Mudrák
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_user_selector_testcase extends advanced_testcase {
+class userselector_test extends \advanced_testcase {
/**
* Setup the environment for the tests.
@@ -46,14 +43,14 @@ class core_user_selector_testcase extends advanced_testcase {
$CFG->showuseridentity = 'idnumber,country,city';
$CFG->hiddenuserfields = 'country,city';
- $env = new stdClass();
+ $env = new \stdClass();
$env->student = $this->getDataGenerator()->create_user();
$env->teacher = $this->getDataGenerator()->create_user();
$env->manager = $this->getDataGenerator()->create_user();
$env->course = $this->getDataGenerator()->create_course();
- $env->coursecontext = context_course::instance($env->course->id);
+ $env->coursecontext = \context_course::instance($env->course->id);
$env->teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
$env->studentrole = $DB->get_record('role', array('shortname' => 'student'));
diff --git a/webservice/rest/tests/server_test.php b/webservice/rest/tests/server_test.php
index 354fc6048f4..04724a8cea8 100644
--- a/webservice/rest/tests/server_test.php
+++ b/webservice/rest/tests/server_test.php
@@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Rest server tests.
- *
- * @package webservice_rest
- * @copyright 2016 Frédéric Massart - FMCorz.net
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace webservice_rest;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -35,7 +29,7 @@ require_once($CFG->dirroot . '/webservice/rest/locallib.php');
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class webservice_rest_server_testcase extends advanced_testcase {
+class server_test extends \advanced_testcase {
/**
* Data provider for test_xmlize.
@@ -44,13 +38,13 @@ class webservice_rest_server_testcase extends advanced_testcase {
public function xmlize_provider() {
$data = [];
$data[] = [null, null, ''];
- $data[] = [new external_value(PARAM_BOOL), false, "0\n"];
- $data[] = [new external_value(PARAM_BOOL), true, "1\n"];
- $data[] = [new external_value(PARAM_ALPHA), null, "\n"];
- $data[] = [new external_value(PARAM_ALPHA), 'a', "a\n"];
- $data[] = [new external_value(PARAM_INT), 123, "123\n"];
+ $data[] = [new \external_value(PARAM_BOOL), false, "0\n"];
+ $data[] = [new \external_value(PARAM_BOOL), true, "1\n"];
+ $data[] = [new \external_value(PARAM_ALPHA), null, "\n"];
+ $data[] = [new \external_value(PARAM_ALPHA), 'a', "a\n"];
+ $data[] = [new \external_value(PARAM_INT), 123, "123\n"];
$data[] = [
- new external_multiple_structure(new external_value(PARAM_INT)),
+ new \external_multiple_structure(new \external_value(PARAM_INT)),
[1, 2, 3],
"\n" .
"1\n" .
@@ -59,7 +53,7 @@ class webservice_rest_server_testcase extends advanced_testcase {
"\n"
];
$data[] = [ // Multiple structure with null value.
- new external_multiple_structure(new external_value(PARAM_ALPHA)),
+ new \external_multiple_structure(new \external_value(PARAM_ALPHA)),
['A', null, 'C'],
"\n" .
"A\n" .
@@ -68,16 +62,16 @@ class webservice_rest_server_testcase extends advanced_testcase {
"\n"
];
$data[] = [ // Multiple structure without values.
- new external_multiple_structure(new external_value(PARAM_ALPHA)),
+ new \external_multiple_structure(new \external_value(PARAM_ALPHA)),
[],
"\n" .
"\n"
];
$data[] = [
- new external_single_structure([
- 'one' => new external_value(PARAM_INT),
- 'two' => new external_value(PARAM_INT),
- 'three' => new external_value(PARAM_INT),
+ new \external_single_structure([
+ 'one' => new \external_value(PARAM_INT),
+ 'two' => new \external_value(PARAM_INT),
+ 'three' => new \external_value(PARAM_INT),
]),
['one' => 1, 'two' => 2, 'three' => 3],
"\n" .
@@ -87,10 +81,10 @@ class webservice_rest_server_testcase extends advanced_testcase {
"\n"
];
$data[] = [ // Single structure with null value.
- new external_single_structure([
- 'one' => new external_value(PARAM_INT),
- 'two' => new external_value(PARAM_INT),
- 'three' => new external_value(PARAM_INT),
+ new \external_single_structure([
+ 'one' => new \external_value(PARAM_INT),
+ 'two' => new \external_value(PARAM_INT),
+ 'three' => new \external_value(PARAM_INT),
]),
['one' => 1, 'two' => null, 'three' => 3],
"\n" .
@@ -100,10 +94,10 @@ class webservice_rest_server_testcase extends advanced_testcase {
"\n"
];
$data[] = [ // Single structure missing keys.
- new external_single_structure([
- 'one' => new external_value(PARAM_INT),
- 'two' => new external_value(PARAM_INT),
- 'three' => new external_value(PARAM_INT),
+ new \external_single_structure([
+ 'one' => new \external_value(PARAM_INT),
+ 'two' => new \external_value(PARAM_INT),
+ 'three' => new \external_value(PARAM_INT),
]),
['two' => null, 'three' => 3],
"\n" .
@@ -113,19 +107,19 @@ class webservice_rest_server_testcase extends advanced_testcase {
"\n"
];
$data[] = [ // Nested structure.
- new external_single_structure([
- 'one' => new external_multiple_structure(
- new external_value(PARAM_INT)
+ new \external_single_structure([
+ 'one' => new \external_multiple_structure(
+ new \external_value(PARAM_INT)
),
- 'two' => new external_multiple_structure(
- new external_single_structure([
- 'firstname' => new external_value(PARAM_RAW),
- 'lastname' => new external_value(PARAM_RAW),
+ 'two' => new \external_multiple_structure(
+ new \external_single_structure([
+ 'firstname' => new \external_value(PARAM_RAW),
+ 'lastname' => new \external_value(PARAM_RAW),
])
),
- 'three' => new external_single_structure([
- 'firstname' => new external_value(PARAM_RAW),
- 'lastname' => new external_value(PARAM_RAW),
+ 'three' => new \external_single_structure([
+ 'firstname' => new \external_value(PARAM_RAW),
+ 'lastname' => new \external_value(PARAM_RAW),
]),
]),
[
@@ -159,19 +153,19 @@ class webservice_rest_server_testcase extends advanced_testcase {
"\n"
];
$data[] = [ // Nested structure with missing keys.
- new external_single_structure([
- 'one' => new external_multiple_structure(
- new external_value(PARAM_INT)
+ new \external_single_structure([
+ 'one' => new \external_multiple_structure(
+ new \external_value(PARAM_INT)
),
- 'two' => new external_multiple_structure(
- new external_single_structure([
- 'firstname' => new external_value(PARAM_RAW),
- 'lastname' => new external_value(PARAM_RAW),
+ 'two' => new \external_multiple_structure(
+ new \external_single_structure([
+ 'firstname' => new \external_value(PARAM_RAW),
+ 'lastname' => new \external_value(PARAM_RAW),
])
),
- 'three' => new external_single_structure([
- 'firstname' => new external_value(PARAM_RAW),
- 'lastname' => new external_value(PARAM_RAW),
+ 'three' => new \external_single_structure([
+ 'firstname' => new \external_value(PARAM_RAW),
+ 'lastname' => new \external_value(PARAM_RAW),
]),
]),
[
@@ -209,7 +203,7 @@ class webservice_rest_server_testcase extends advanced_testcase {
* @param mixed $expected The expected output.
*/
public function test_xmlize($description, $value, $expected) {
- $method = new ReflectionMethod('webservice_rest_server', 'xmlize_result');
+ $method = new \ReflectionMethod('webservice_rest_server', 'xmlize_result');
$method->setAccessible(true);
$this->assertEquals($expected, $method->invoke(null, $value, $description));
}