From d8ea630f24b6e5affccd0ee8e8cfd5235f08fae9 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sat, 2 Apr 2022 21:34:46 +0200 Subject: [PATCH] MDL-74413 phpunit: Move more tests to use correct names and namespaces Applied the following changes to various testcase classes: - Namespaced with component[\level2-API] - Moved to level2-API subdirectory when required. - Fixed incorrect use statements with leading backslash. - Remove file phpdoc block - Remove MOODLE_INTERNAL if not needed. - Changed code to point to global scope when needed. - Fix some relative paths and comments here and there. - All them passing individually. - Complete runs passing too. Special mention to: - Moved to the level2 "privacy" namespace: - \mod_assign\privacy\feedback_legacy_polyfill_test - \mod_assign\privacy\submission_legacy_polyfill_test - Moved to the level2 "task" namespace: - \core_message\task\migrate_message_data_test - \ltiservice_gradebookservices\task\cleanup_test - \message_email\task\send_email_test - \mod_lti\task\clean_access_tokens_test - \mod_workshop\task\cron_task_test - Moved to the level2 "event" namespace: - \core_h5p\event\deleted_test - \core_h5p\event\viewed_test - Renamed to a better name: - backup_forum_activity_task_test.php (missing "task") --- .../mathjaxloader/tests/filtermath_test.php | 20 +- grade/grading/form/guide/tests/guide_test.php | 13 +- grade/grading/tests/grading_manager_test.php | 42 ++--- grade/import/csv/tests/load_data_test.php | 73 ++++---- grade/report/singleview/tests/screen_test.php | 27 ++- grade/tests/edittreelib_test.php | 32 ++-- grade/tests/export_test.php | 18 +- grade/tests/importlib_test.php | 44 +++-- grade/tests/querylib_test.php | 20 +- grade/tests/report_graderlib_test.php | 45 ++--- grade/tests/reportuserlib_test.php | 32 ++-- .../deleted_test.php} | 16 +- .../moved_test.php} | 16 +- iplookup/tests/geoip_test.php | 16 +- iplookup/tests/geoplugin_test.php | 19 +- lib/antivirus/clamav/tests/scanner_test.php | 9 +- .../email/tests/event_observers_test.php | 15 +- .../send_email_test.php} | 19 +- .../popup/tests/messaging_cleanup_test.php | 16 +- message/tests/api_test.php | 2 +- message/tests/event/events_test.php | 4 +- message/tests/inbound_test.php | 7 +- message/tests/messagelib_test.php | 23 +-- message/tests/search_received_test.php | 26 +-- message/tests/search_sent_test.php | 20 +- .../migrate_message_data_test.php} | 29 ++- .../feedback/file/tests/importziplib_test.php | 15 +- mod/assign/tests/feedback_test.php | 18 +- .../tests/locallib_participants_test.php | 40 ++-- mod/assign/tests/markerallocation_test.php | 20 +- .../feedback_legacy_polyfill_test.php} | 19 +- .../submission_legacy_polyfill_test.php} | 20 +- mod/chat/tests/format_message_test.php | 10 +- mod/feedback/tests/completion_test.php | 15 +- ...hp => backup_forum_activity_task_test.php} | 13 +- .../tests/builders_exported_posts_test.php | 20 +- mod/forum/tests/entities_author_test.php | 12 +- .../entities_discussion_summary_test.php | 12 +- mod/forum/tests/entities_discussion_test.php | 12 +- mod/forum/tests/entities_forum_test.php | 18 +- ...ties_post_read_receipt_collection_test.php | 12 +- mod/forum/tests/entities_post_test.php | 12 +- mod/forum/tests/entities_sorter_test.php | 12 +- mod/forum/tests/exporters_author_test.php | 25 +-- mod/forum/tests/exporters_discussion_test.php | 16 +- mod/forum/tests/exporters_forum_test.php | 16 +- mod/forum/tests/exporters_post_test.php | 87 ++++----- mod/forum/tests/local_container_test.php | 13 +- mod/forum/tests/mail_group_test.php | 13 +- mod/forum/tests/mail_test.php | 29 +-- mod/forum/tests/maildigest_test.php | 32 ++-- mod/forum/tests/managers_capability_test.php | 106 ++++++----- mod/forum/tests/output_email_test.php | 19 +- mod/forum/tests/private_replies_test.php | 13 +- mod/forum/tests/qanda_test.php | 14 +- mod/forum/tests/subscriptions_test.php | 21 ++- mod/forum/tests/vaults_author_test.php | 18 +- .../tests/vaults_discussion_list_test.php | 21 +-- mod/forum/tests/vaults_discussion_test.php | 20 +- mod/forum/tests/vaults_forum_test.php | 12 +- .../tests/vaults_post_attachment_test.php | 32 ++-- ...ults_post_read_receipt_collection_test.php | 18 +- mod/forum/tests/vaults_post_test.php | 42 ++--- mod/glossary/tests/concept_cache_test.php | 13 +- mod/lesson/tests/numeric_helper_test.php | 20 +- mod/lesson/tests/pagetypes_test.php | 18 +- .../tests/gradebookservices_test.php | 24 ++- .../cleanup_test.php} | 27 +-- .../event/unknown_service_api_called_test.php | 16 +- .../get_tool_types_and_proxies_count_test.php | 8 +- .../get_tool_types_and_proxies_test.php | 12 +- .../tests/service_exception_handler_test.php | 22 +-- mod/lti/tests/servicelib_test.php | 12 +- .../clean_access_tokens_test.php} | 17 +- mod/scorm/tests/formatduration_test.php | 22 +-- mod/scorm/tests/validatepackage_test.php | 25 +-- mod/wiki/tests/wikiparser_test.php | 24 +-- .../random/tests/allocator_test.php | 32 +++- .../tests/{ => task}/cron_task_test.php | 15 +- privacy/tests/collection_test.php | 17 +- privacy/tests/legacy_polyfill_test.php | 18 +- privacy/tests/types_database_table_test.php | 17 +- .../tests/types_external_location_test.php | 15 +- privacy/tests/types_plugintype_link_test.php | 21 +-- privacy/tests/types_subsystem_link_test.php | 21 +-- privacy/tests/types_user_preference_test.php | 21 +-- rating/tests/rating_test.php | 27 ++- repository/contentbank/tests/browser_test.php | 10 +- .../access_controlled_link_manager_test.php | 36 ++-- repository/nextcloud/tests/ocs_test.php | 16 +- repository/tests/repositorylib_test.php | 83 +++++---- search/tests/area_category_test.php | 15 +- search/tests/base_activity_test.php | 30 ++- search/tests/base_block_test.php | 38 ++-- search/tests/document_icon_test.php | 12 +- search/tests/document_test.php | 6 +- search/tests/top_result_test.php | 13 +- tag/tests/taglib_test.php | 172 +++++++++--------- user/tests/editlib_test.php | 19 +- .../tests/group_non_members_selector_test.php | 13 +- user/tests/myprofile_test.php | 29 ++- user/tests/profilelib_test.php | 18 +- user/tests/userlib_test.php | 39 ++-- user/tests/userroleseditable_test.php | 14 +- user/tests/userselector_test.php | 19 +- webservice/rest/tests/server_test.php | 92 +++++----- 106 files changed, 1081 insertions(+), 1507 deletions(-) rename h5p/tests/{event_h5p_deleted_test.php => event/deleted_test.php} (85%) rename h5p/tests/{event_h5p_viewed_test.php => event/moved_test.php} (87%) rename message/output/email/tests/{send_email_task_test.php => task/send_email_test.php} (91%) rename message/tests/{migrate_message_data_task_test.php => task/migrate_message_data_test.php} (95%) rename mod/assign/tests/{privacy_feedback_legacy_polyfill_test.php => privacy/feedback_legacy_polyfill_test.php} (94%) rename mod/assign/tests/{privacy_submission_legacy_polyfill_test.php => privacy/submission_legacy_polyfill_test.php} (94%) rename mod/forum/tests/{backup_forum_activity_test.php => backup_forum_activity_task_test.php} (94%) rename mod/lti/service/gradebookservices/tests/{task_cleanup_test.php => task/cleanup_test.php} (84%) rename mod/lti/tests/{task_clean_access_tokens_test.php => task/clean_access_tokens_test.php} (82%) rename mod/workshop/tests/{ => task}/cron_task_test.php (93%) diff --git a/filter/mathjaxloader/tests/filtermath_test.php b/filter/mathjaxloader/tests/filtermath_test.php index 31bd1ee0677..c84f57e17c5 100644 --- a/filter/mathjaxloader/tests/filtermath_test.php +++ b/filter/mathjaxloader/tests/filtermath_test.php @@ -13,24 +13,24 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Provides the {@link filter_mathjaxloader_filtermath_testcase} class. - * - * @package filter_mathjaxloader - * @category test - * @copyright 2018 Markku Riekkinen - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ + +namespace filter_mathjaxloader; + +use filter_mathjaxloader; + defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot.'/filter/mathjaxloader/filter.php'); + /** * Unit tests for the MathJax loader filter. * + * @package filter_mathjaxloader + * @category test * @copyright 2018 Markku Riekkinen * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class filter_mathjaxloader_filtermath_testcase extends advanced_testcase { +class filtermath_test extends \advanced_testcase { /** * Test the functionality of {@link filter_mathjaxloader::filter()}. @@ -41,7 +41,7 @@ class filter_mathjaxloader_filtermath_testcase extends advanced_testcase { * @dataProvider test_math_filtering_inputs */ public function test_math_filtering($inputtext, $expected) { - $filter = new filter_mathjaxloader(context_system::instance(), []); + $filter = new filter_mathjaxloader(\context_system::instance(), []); $this->assertEquals($expected, $filter->filter($inputtext)); } diff --git a/grade/grading/form/guide/tests/guide_test.php b/grade/grading/form/guide/tests/guide_test.php index 5bf953e41a5..ff25d88c629 100644 --- a/grade/grading/form/guide/tests/guide_test.php +++ b/grade/grading/form/guide/tests/guide_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 Marking Guide grading method. - * - * @package gradingform_guide - * @category test - * @copyright 2015 Nikita Kalinin - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace gradingform_guide; + +use gradingform_controller; defined('MOODLE_INTERNAL') || die(); @@ -37,7 +32,7 @@ require_once($CFG->dirroot . '/grade/grading/form/guide/lib.php'); * @copyright 2015 Nikita Kalinin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class gradingform_guide_testcase extends advanced_testcase { +class guide_test extends \advanced_testcase { /** * Unit test to get draft instance and create new instance. */ diff --git a/grade/grading/tests/grading_manager_test.php b/grade/grading/tests/grading_manager_test.php index 6aa0444642a..e43c8b6af7a 100644 --- a/grade/grading/tests/grading_manager_test.php +++ b/grade/grading/tests/grading_manager_test.php @@ -14,42 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the advanced grading subsystem - * - * @package core_grading - * @category phpunit - * @copyright 2011 David Mudrak - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_grading; + +use grading_manager; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/grade/grading/lib.php'); // Include the code to test - -/** - * Makes protected method accessible for testing purposes - * - * @package core_grading - * @category phpunit - * @copyright 2011 David Mudrak - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class testable_grading_manager extends grading_manager { -} - - /** * Test cases for the grading manager API * * @package core_grading - * @category phpunit + * @category test * @copyright 2011 David Mudrak * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_grade_grading_manager_testcase extends advanced_testcase { +class grading_manager_test extends \advanced_testcase { public function test_basic_instantiation() { $manager1 = get_grading_manager(); @@ -103,7 +85,7 @@ class core_grade_grading_manager_testcase extends advanced_testcase { $this->assertEquals('rubric', $gradingman->get_active_method()); // attempting to set an invalid method - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $gradingman->set_active_method('no_one_should_ever_try_to_implement_a_method_with_this_silly_name'); } @@ -115,27 +97,27 @@ class core_grade_grading_manager_testcase extends advanced_testcase { $UTFfailuremessage = 'A test using UTF-8 characters has failed. Consider updating PHP and PHP\'s PCRE or INTL extensions (MDL-30494)'; $needle = " šašek, \n\n \r a král; \t"; - $tokens = testable_grading_manager::tokenize($needle); + $tokens = grading_manager::tokenize($needle); $this->assertEquals(2, count($tokens), $UTFfailuremessage); $this->assertTrue(in_array('šašek', $tokens), $UTFfailuremessage); $this->assertTrue(in_array('král', $tokens), $UTFfailuremessage); $needle = ' " šašek a král " '; - $tokens = testable_grading_manager::tokenize($needle); + $tokens = grading_manager::tokenize($needle); $this->assertEquals(1, count($tokens)); $this->assertTrue(in_array('šašek a král', $tokens)); $needle = '""'; - $tokens = testable_grading_manager::tokenize($needle); + $tokens = grading_manager::tokenize($needle); $this->assertTrue(empty($tokens)); $needle = '"0"'; - $tokens = testable_grading_manager::tokenize($needle); + $tokens = grading_manager::tokenize($needle); $this->assertEquals(1, count($tokens)); $this->assertTrue(in_array('0', $tokens)); $needle = 'Aha, then who\'s a bad guy here he?'; - $tokens = testable_grading_manager::tokenize($needle); + $tokens = grading_manager::tokenize($needle); $this->assertEquals(8, count($tokens)); $this->assertTrue(in_array('span', $tokens)); // Extracted the tag name $this->assertTrue(in_array('Aha', $tokens)); @@ -144,7 +126,7 @@ class core_grade_grading_manager_testcase extends advanced_testcase { $this->assertTrue(in_array('he', $tokens)); // Removed the trailing ? $needle = 'grammar, "english language"'; - $tokens = testable_grading_manager::tokenize($needle); + $tokens = grading_manager::tokenize($needle); $this->assertTrue(in_array('grammar', $tokens)); $this->assertTrue(in_array('english', $tokens)); $this->assertTrue(in_array('language', $tokens)); diff --git a/grade/import/csv/tests/load_data_test.php b/grade/import/csv/tests/load_data_test.php index b49d16e00bd..959e92a4a4d 100644 --- a/grade/import/csv/tests/load_data_test.php +++ b/grade/import/csv/tests/load_data_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 the class in load_data.php - * - * @package gradeimport_csv - * @category phpunit - * @copyright 2014 Adrian Greeve - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace gradeimport_csv; defined('MOODLE_INTERNAL') || die(); @@ -38,7 +31,7 @@ require_once($CFG->libdir . '/grade/tests/fixtures/lib.php'); * @copyright 2014 Adrian Greeve * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class gradeimport_csv_load_data_testcase extends grade_base_testcase { +class load_data_test extends \grade_base_testcase { /** @var string $oktext Text to be imported. This data should have no issues being imported. */ protected $oktext = '"First name",Surname,"ID number",Institution,Department,"Email address","Assignment: Assignment for grape group", "Feedback: Assignment for grape group","Assignment: Second new grade item","Course total" @@ -76,8 +69,8 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat */ protected function csv_load($content) { // Import the csv strings. - $this->iid = csv_import_reader::get_new_iid('grade'); - $this->csvimport = new csv_import_reader($this->iid, 'grade'); + $this->iid = \csv_import_reader::get_new_iid('grade'); + $this->csvimport = new \csv_import_reader($this->iid, 'grade'); $this->csvimport->load_csv_content($content, 'utf8', 'comma'); $this->columns = $this->csvimport->get_columns(); @@ -97,7 +90,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $encoding = 'utf8'; $separator = 'comma'; $previewrows = 5; - $csvpreview = new phpunit_gradeimport_csv_load_data(); + $csvpreview = new \phpunit_gradeimport_csv_load_data(); $csvpreview->load_csv_content($this->oktext, $encoding, $separator, $previewrows); $expecteddata = array(array( @@ -144,7 +137,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $this->assertEquals($csvpreview->get_headers(), $expectedheaders); // Check that errors are being recorded. - $csvpreview = new phpunit_gradeimport_csv_load_data(); + $csvpreview = new \phpunit_gradeimport_csv_load_data(); $csvpreview->load_csv_content($this->badtext, $encoding, $separator, $previewrows); // Columns shouldn't match. $this->assertEquals($csvpreview->get_error(), get_string('csvweirdcolumns', 'error')); @@ -155,8 +148,8 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat */ public function test_fetch_grade_items() { - $gradeitemsarray = grade_item::fetch_all(array('courseid' => $this->courseid)); - $gradeitems = phpunit_gradeimport_csv_load_data::fetch_grade_items($this->courseid); + $gradeitemsarray = \grade_item::fetch_all(array('courseid' => $this->courseid)); + $gradeitems = \phpunit_gradeimport_csv_load_data::fetch_grade_items($this->courseid); // Make sure that each grade item is located in the gradeitemsarray. foreach ($gradeitems as $key => $gradeitem) { @@ -187,13 +180,13 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $user = $this->getDataGenerator()->create_user(); $this->setAdminUser(); - $record = new stdClass(); + $record = new \stdClass(); $record->itemid = 4; $record->newgradeitem = 25; $record->finalgrade = 62.00; $record->feedback = 'Some test feedback'; - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); $testobject->test_insert_grade_record($record, $user->id); $gradeimportvalues = $DB->get_records('grade_import_values'); @@ -201,7 +194,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $key = key($gradeimportvalues); $testarray = array(); - $testarray[$key] = new stdClass(); + $testarray[$key] = new \stdClass(); $testarray[$key]->id = $key; $testarray[$key]->itemid = $record->itemid; $testarray[$key]->newgradeitem = $record->newgradeitem; @@ -228,7 +221,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat // The assignment is item 6. $key = 6; - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); // Key for this assessment. $this->csvimport->init(); @@ -329,7 +322,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat 'label' => 'Field label: ' . $field ]; - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); // Check whether the user exists. If so, then the user id is returned. Otherwise, it returns null. $userid = $testobject->test_check_user_exists($value, $userfields); @@ -367,7 +360,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat public function test_create_feedback() { $testarray = $this->csv_load($this->oktext); - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); // Try to insert some feedback for an assessment. $feedback = $testobject->test_create_feedback($this->courseid, 1, $testarray[0][7]); @@ -383,7 +376,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat public function test_update_grade_item() { $testarray = $this->csv_load($this->oktext); - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); // We're not using scales so no to this option. $verbosescales = 0; @@ -394,7 +387,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $newgrades = $testobject->test_update_grade_item($this->courseid, $map, $key, $verbosescales, $testarray[0][6]); $expectedresult = array(); - $expectedresult[0] = new stdClass(); + $expectedresult[0] = new \stdClass(); $expectedresult[0]->itemid = 1; $expectedresult[0]->finalgrade = $testarray[0][6]; @@ -415,14 +408,14 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat */ public function test_map_user_data_with_value() { // Need to add one of the users into the system. - $user = new stdClass(); + $user = new \stdClass(); $user->firstname = 'Anne'; $user->lastname = 'Able'; $user->email = 'student7@example.com'; $userdetail = $this->getDataGenerator()->create_user($user); $testarray = $this->csv_load($this->oktext); - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); // We're not using scales so no to this option. $verbosescales = 0; @@ -452,7 +445,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $this->courseid, $map[$key], $verbosescales); // Expected result. $resultarray = array(); - $resultarray[0] = new stdClass(); + $resultarray[0] = new \stdClass(); $resultarray[0]->itemid = 1; $resultarray[0]->feedback = $testarray[0][7]; $this->assertEquals($feedback, $resultarray); @@ -470,13 +463,13 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat global $DB; // Need to add one of the users into the system. - $user = new stdClass(); + $user = new \stdClass(); $user->firstname = 'Anne'; $user->lastname = 'Able'; $user->email = 'student7@example.com'; // Insert user 1. $this->getDataGenerator()->create_user($user); - $user = new stdClass(); + $user = new \stdClass(); $user->firstname = 'Bobby'; $user->lastname = 'Bunce'; $user->email = 'student5@example.com'; @@ -489,7 +482,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $verbosescales = 0; // Form data object. - $formdata = new stdClass(); + $formdata = new \stdClass(); $formdata->mapfrom = 5; $formdata->mapto = 'useremail'; $formdata->mapping_0 = 0; @@ -509,7 +502,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $formdata->forceimport = false; // Blam go time. - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); $dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport, $this->courseid, '', '', $verbosescales); // If everything inserted properly then this should be true. @@ -522,13 +515,13 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat public function test_force_import_option () { // Need to add users into the system. - $user = new stdClass(); + $user = new \stdClass(); $user->firstname = 'Anne'; $user->lastname = 'Able'; $user->email = 'student7@example.com'; $user->id_number = 1; $user1 = $this->getDataGenerator()->create_user($user); - $user = new stdClass(); + $user = new \stdClass(); $user->firstname = 'Bobby'; $user->lastname = 'Bunce'; $user->email = 'student5@example.com'; @@ -542,14 +535,14 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat 'gradetype' => GRADE_TYPE_VALUE, 'courseid' => $this->courseid ); - $gradeitem = new grade_item($params, false); + $gradeitem = new \grade_item($params, false); $gradeitemid = $gradeitem->insert(); $importcode = 001; $verbosescales = 0; // Form data object. - $formdata = new stdClass(); + $formdata = new \stdClass(); $formdata->mapfrom = 5; $formdata->mapto = 'useremail'; $formdata->mapping_0 = 0; @@ -572,7 +565,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $exportdate = time(); $newcsvdata = str_replace('{exportdate}', $exportdate, $this->csvtext); $this->csv_load($newcsvdata); - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); $dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport, $this->courseid, '', '', $verbosescales); $this->assertTrue($dataloaded); @@ -584,7 +577,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $pastdate = strtotime('-1 day', time()); $newcsvdata = str_replace('{exportdate}', $pastdate, $this->csvtext); $this->csv_load($newcsvdata); - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); $dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport, $this->courseid, '', '', $verbosescales); $this->assertFalse($dataloaded); @@ -593,7 +586,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat // Test using force import enabled and a date in the past. $formdata->forceimport = true; - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); $dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport, $this->courseid, '', '', $verbosescales); $this->assertTrue($dataloaded); @@ -603,7 +596,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $twoyearsago = strtotime('-2 year', time()); $newcsvdata = str_replace('{exportdate}', $twoyearsago, $this->csvtext); $this->csv_load($newcsvdata); - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); $dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport, $this->courseid, '', '', $verbosescales); $this->assertFalse($dataloaded); @@ -615,7 +608,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $newcsvdata = str_replace('{exportdate}', $baddate, $this->csvtext); $this->csv_load($newcsvdata); $formdata->mapping_6 = $gradeitemid; - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); $dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport, $this->courseid, '', '', $verbosescales); $this->assertFalse($dataloaded); @@ -627,7 +620,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat $oldcsv = str_replace('{exportdate}', $oneyearahead, $this->csvtext); $this->csv_load($oldcsv); $formdata->mapping_6 = $gradeitemid; - $testobject = new phpunit_gradeimport_csv_load_data(); + $testobject = new \phpunit_gradeimport_csv_load_data(); $dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport, $this->courseid, '', '', $verbosescales); $this->assertFalse($dataloaded); diff --git a/grade/report/singleview/tests/screen_test.php b/grade/report/singleview/tests/screen_test.php index eed99219f38..97fc44c12e6 100644 --- a/grade/report/singleview/tests/screen_test.php +++ b/grade/report/singleview/tests/screen_test.php @@ -14,26 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace gradereport_singleview; + +use gradereport_singleview_screen_testable; + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once(__DIR__ . '/fixtures/screen.php'); +require_once($CFG->libdir . '/gradelib.php'); + /** - * Unit tests for gradereport_singleview screen class. + * Tests for screen class. * * @package gradereport_singleview * @category test * @copyright 2014 onwards Simey Lameze * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -global $CFG; -require_once(__DIR__ . '/fixtures/screen.php'); -require_once($CFG->libdir . '/gradelib.php'); - -defined('MOODLE_INTERNAL') || die(); -/** - * Tests for screen class. - * - * Class gradereport_singleview_screen_testcase. - */ -class gradereport_singleview_screen_testcase extends advanced_testcase { +class screen_test extends \advanced_testcase { /** * Test load_users method. @@ -48,7 +47,7 @@ class gradereport_singleview_screen_testcase extends advanced_testcase { // Create a course, users and groups. $course = $this->getDataGenerator()->create_course(); - $coursecontext = context_course::instance($course->id); + $coursecontext = \context_course::instance($course->id); $group = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); $teacher = $this->getDataGenerator()->create_user(); $user1 = $this->getDataGenerator()->create_user(); diff --git a/grade/tests/edittreelib_test.php b/grade/tests/edittreelib_test.php index 93d79836d97..8b011755dd0 100644 --- a/grade/tests/edittreelib_test.php +++ b/grade/tests/edittreelib_test.php @@ -14,25 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for grade/edit/tree/lib.php. - * - * @package core_grades - * @category phpunit - * @author Andrew Davis - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ +namespace core_grades; + +use grade_edit_tree; +use grade_edit_tree_column; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot.'/grade/edit/tree/lib.php'); - /** * Tests grade_edit_tree (deals with the data on the 'Gradebook setup' page in the gradebook) + * + * @package core_grades + * @category test + * @author Andrew Davis + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ -class core_grade_edittreelib_testcase extends advanced_testcase { +class edittreelib_test extends \advanced_testcase { public function test_format_number() { $numinput = array(0, 1, 1.01, '1.010', 1.2345); $numoutput = array(0.0, 1.0, 1.01, 1.01, 1.2345); @@ -52,9 +52,9 @@ class core_grade_edittreelib_testcase extends advanced_testcase { $scale = $this->getDataGenerator()->create_scale(); $course = $this->getDataGenerator()->create_course(); $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id)); - $modulecontext = context_module::instance($assign->cmid); + $modulecontext = \context_module::instance($assign->cmid); // The generator returns a dummy object, lets get the real assign object. - $assign = new assign($modulecontext, false, false); + $assign = new \assign($modulecontext, false, false); $cm = $assign->get_course_module(); // Get range column. @@ -74,7 +74,7 @@ class core_grade_edittreelib_testcase extends advanced_testcase { $instance->instance = $instance->id; $assign->update_instance($instance); - $gradeitem = grade_item::fetch($gradeitemparams); + $gradeitem = \grade_item::fetch($gradeitemparams); $cell = $column->get_item_cell($gradeitem, array()); $this->assertEquals(GRADE_TYPE_VALUE, $gradeitem->gradetype); @@ -87,7 +87,7 @@ class core_grade_edittreelib_testcase extends advanced_testcase { $instance->instance = $instance->id; $assign->update_instance($instance); - $gradeitem = grade_item::fetch($gradeitemparams); + $gradeitem = \grade_item::fetch($gradeitemparams); $cell = $column->get_item_cell($gradeitem, array()); // Make the expected scale text. @@ -113,7 +113,7 @@ class core_grade_edittreelib_testcase extends advanced_testcase { $instance->instance = $instance->id; $assign->update_instance($instance); - $gradeitem = grade_item::fetch($gradeitemparams); + $gradeitem = \grade_item::fetch($gradeitemparams); $cell = $column->get_item_cell($gradeitem, array()); $this->assertEquals(GRADE_TYPE_TEXT, $gradeitem->gradetype); @@ -127,7 +127,7 @@ class core_grade_edittreelib_testcase extends advanced_testcase { $instance->instance = $instance->id; $assign->update_instance($instance); - $gradeitem = grade_item::fetch($gradeitemparams); + $gradeitem = \grade_item::fetch($gradeitemparams); $cell = $column->get_item_cell($gradeitem, array()); $this->assertEquals(GRADE_TYPE_NONE, $gradeitem->gradetype); diff --git a/grade/tests/export_test.php b/grade/tests/export_test.php index b2cc79adb1f..f52c606ea8d 100644 --- a/grade/tests/export_test.php +++ b/grade/tests/export_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 grade/report/lib.php. - * - * @package core_grades - * @category phpunit - * @copyright Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ +namespace core_grades; defined('MOODLE_INTERNAL') || die(); @@ -31,8 +24,13 @@ require_once($CFG->dirroot.'/grade/export/lib.php'); /** * A test class used to test grade_report, the abstract grade report parent class + * + * @package core_grades + * @category test + * @copyright Andrew Nicols + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ -class core_grade_export_test extends advanced_testcase { +class export_test extends \advanced_testcase { /** * Ensure that feedback is correct formatted. Test the default implementation of format_feedback @@ -67,7 +65,7 @@ class core_grade_export_test extends advanced_testcase { $dg = $this->getDataGenerator(); $c1 = $dg->create_course(); $u1 = $dg->create_user(); - $gi1a = new grade_item($dg->create_grade_item(['courseid' => $c1->id]), false); + $gi1a = new \grade_item($dg->create_grade_item(['courseid' => $c1->id]), false); $gi1a->update_final_grade($u1->id, 1, 'test'); $contextid = $gi1a->get_context()->id; $gradeid = $gi1a->id; diff --git a/grade/tests/importlib_test.php b/grade/tests/importlib_test.php index 5fce120cef3..4850ce2b183 100644 --- a/grade/tests/importlib_test.php +++ b/grade/tests/importlib_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 grade/import/lib.php. - * - * @package core_grades - * @category phpunit - * @copyright 2015 Adrian Greeve - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ +namespace core_grades; defined('MOODLE_INTERNAL') || die(); @@ -30,8 +23,13 @@ require_once($CFG->dirroot . '/grade/import/lib.php'); /** * Tests grade_import_lib functions. + * + * @package core_grades + * @category test + * @copyright 2015 Adrian Greeve + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ -class core_grade_import_lib_test extends advanced_testcase { +class importlib_test extends \advanced_testcase { /** * Import grades into 'grade_import_values' table. This is done differently in the various import plugins, @@ -42,7 +40,7 @@ class core_grade_import_lib_test extends advanced_testcase { */ private function import_grades($data) { global $DB, $USER; - $graderecord = new stdClass(); + $graderecord = new \stdClass(); $graderecord->importcode = $data['importcode']; if (isset($data['itemid'])) { $graderecord->itemid = $data['itemid']; @@ -86,9 +84,9 @@ class core_grade_import_lib_test extends advanced_testcase { $course = $this->getDataGenerator()->create_course(); $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id)); $itemname = $assign->name; - $modulecontext = context_module::instance($assign->cmid); + $modulecontext = \context_module::instance($assign->cmid); // The generator returns a dummy object, lets get the real assign object. - $assign = new assign($modulecontext, false, false); + $assign = new \assign($modulecontext, false, false); $cm = $assign->get_course_module(); // Enrol users in the course. @@ -96,7 +94,7 @@ class core_grade_import_lib_test extends advanced_testcase { $this->getDataGenerator()->enrol_user($user2->id, $course->id); // Enter a new grade into an existing grade item. - $gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod')); + $gradeitem = \grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod')); // Keep this value around for a test further down. $originalgrade = 55; @@ -111,14 +109,14 @@ class core_grade_import_lib_test extends advanced_testcase { $this->assertTrue($status); // Get imported grade_grade. - $gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id)); + $gradegrade = \grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id)); $this->assertEquals($originalgrade, $gradegrade->finalgrade); // Overriden field will be a timestamp and will evaluate out to true. $this->assertTrue($gradegrade->is_overridden()); // Create a new grade item and import into that. $importcode = get_new_importcode(); - $record = new stdClass(); + $record = new \stdClass(); $record->itemname = 'New grade item'; $record->importcode = $importcode; $record->importer = $USER->id; @@ -134,18 +132,18 @@ class core_grade_import_lib_test extends advanced_testcase { $status = grade_import_commit($course->id, $importcode, false, false); $this->assertTrue($status); - // Check that we have a new grade_item. - $gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'manual')); + // Check that we have a new \grade_item. + $gradeitem = \grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'manual')); $this->assertEquals($record->itemname, $gradeitem->itemname); // Grades were imported. - $gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id)); + $gradegrade = \grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id)); $this->assertEquals($finalgrade, $gradegrade->finalgrade); // As this is a new item the grade has not been overridden. $this->assertFalse($gradegrade->is_overridden()); // Import feedback only. $importcode = get_new_importcode(); - $gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod')); + $gradeitem = \grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod')); $originalfeedback = 'feedback can be useful'; $this->import_grades(array( @@ -158,14 +156,14 @@ class core_grade_import_lib_test extends advanced_testcase { $status = grade_import_commit($course->id, $importcode, true, false); $this->assertTrue($status); - $gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id)); + $gradegrade = \grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id)); // The final grade should be the same as the first record further up. We are only altering the feedback. $this->assertEquals($originalgrade, $gradegrade->finalgrade); $this->assertTrue($gradegrade->is_overridden()); // Import grades only. $importcode = get_new_importcode(); - $gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod')); + $gradeitem = \grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod')); $finalgrade = 60; $this->import_grades(array( @@ -178,7 +176,7 @@ class core_grade_import_lib_test extends advanced_testcase { $status = grade_import_commit($course->id, $importcode, false, false); $this->assertTrue($status); - $gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id)); + $gradegrade = \grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id)); $this->assertEquals($finalgrade, $gradegrade->finalgrade); // The final feedback should not have changed. $this->assertEquals($originalfeedback, $gradegrade->feedback); @@ -186,7 +184,7 @@ class core_grade_import_lib_test extends advanced_testcase { // Check that printing of import status is correct. $importcode = get_new_importcode(); - $gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod')); + $gradeitem = \grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod')); $this->import_grades(array( 'importcode' => $importcode, diff --git a/grade/tests/querylib_test.php b/grade/tests/querylib_test.php index 28e6cde2caa..28b36a32ce7 100644 --- a/grade/tests/querylib_test.php +++ b/grade/tests/querylib_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 grade quering - * - * @package core_grades - * @category phpunit - * @copyright 2011 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ +namespace core_grades; defined('MOODLE_INTERNAL') || die(); @@ -29,8 +22,15 @@ global $CFG; require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->dirroot.'/grade/querylib.php'); - -class core_grade_querylib_testcase extends advanced_testcase { +/** + * Unit tests for grade quering + * + * @package core_grades + * @category test + * @copyright 2011 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + */ +class querylib_test extends \advanced_testcase { public function test_grade_get_gradable_activities() { $this->resetAfterTest(true); diff --git a/grade/tests/report_graderlib_test.php b/grade/tests/report_graderlib_test.php index 3a3a03174b4..6e5351a276c 100644 --- a/grade/tests/report_graderlib_test.php +++ b/grade/tests/report_graderlib_test.php @@ -14,14 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for grade/report/user/lib.php. - * - * @package core_grades - * @category phpunit - * @copyright 2012 Andrew Davis - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ +namespace core_grades; + +use grade_plugin_return; +use grade_report_grader; defined('MOODLE_INTERNAL') || die(); @@ -31,8 +27,13 @@ require_once($CFG->dirroot.'/grade/report/grader/lib.php'); /** * Tests grade_report_grader (the grader report) + * + * @package core_grades + * @category test + * @copyright 2012 Andrew Davis + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ -class core_grade_report_graderlib_testcase extends advanced_testcase { +class report_graderlib_test extends \advanced_testcase { /** * Tests grade_report_grader::process_data() @@ -57,12 +58,12 @@ class core_grade_report_graderlib_testcase extends advanced_testcase { $forummax = 80; $forum1 = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => $forummax, 'course' => $course->id)); // Switch the stdClass instance for a grade item instance. - $forum1 = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id)); + $forum1 = \grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id)); $report = $this->create_report($course); $testgrade = 60.00; - $data = new stdClass(); + $data = new \stdClass(); $data->id = $course->id; $data->report = 'grader'; $data->timepageload = time(); @@ -74,7 +75,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase { $warnings = $report->process_data($data); $this->assertEquals(count($warnings), 0); - $studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id)); + $studentgrade = \grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id)); $this->assertEquals($studentgrade->finalgrade, $testgrade); // Grade above max. Should be pulled down to max. @@ -84,7 +85,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase { $warnings = $report->process_data($data); $this->assertEquals(count($warnings), 1); - $studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id)); + $studentgrade = \grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id)); $this->assertEquals($studentgrade->finalgrade, $forummax); // Grade below min. Should be pulled up to min. @@ -94,7 +95,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase { $warnings = $report->process_data($data); $this->assertEquals(count($warnings), 1); - $studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id)); + $studentgrade = \grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id)); $this->assertEquals($studentgrade->finalgrade, 0); // Test unlimited grades so we can give a student a grade about max. @@ -105,7 +106,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase { $warnings = $report->process_data($data); $this->assertEquals(count($warnings), 0); - $studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id)); + $studentgrade = \grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id)); $this->assertEquals($studentgrade->finalgrade, $toobig); } @@ -504,7 +505,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase { // Supposing the user cannot view hidden grades, this shouldn't make any difference (due // to a bug, it previously did). - $context = context_course::instance($course->id); + $context = \context_course::instance($course->id); $managerroleid = $DB->get_field('role', 'id', array('shortname' => 'manager')); assign_capability('moodle/grade:viewhidden', CAP_PROHIBIT, $managerroleid, $context->id, true); $this->assertFalse(has_capability('moodle/grade:viewhidden', $context)); @@ -520,16 +521,16 @@ class core_grade_report_graderlib_testcase extends advanced_testcase { private function create_grade_category($course) { static $cnt = 0; $cnt++; - $grade_category = new grade_category(array('courseid' => $course->id, 'fullname' => 'Cat '.$cnt), false); - $grade_category->apply_default_settings(); - $grade_category->apply_forced_settings(); - $grade_category->insert(); - return $grade_category; + $gradecat = new \grade_category(array('courseid' => $course->id, 'fullname' => 'Cat '.$cnt), false); + $gradecat->apply_default_settings(); + $gradecat->apply_forced_settings(); + $gradecat->insert(); + return $gradecat; } private function create_report($course) { - $coursecontext = context_course::instance($course->id); + $coursecontext = \context_course::instance($course->id); $gpr = new grade_plugin_return(array('type' => 'report', 'plugin'=>'grader', 'courseid' => $course->id)); $report = new grade_report_grader($course->id, $gpr, $coursecontext); diff --git a/grade/tests/reportuserlib_test.php b/grade/tests/reportuserlib_test.php index 301b6bdad60..971dce7069c 100644 --- a/grade/tests/reportuserlib_test.php +++ b/grade/tests/reportuserlib_test.php @@ -14,14 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for grade/report/user/lib.php. - * - * @package core_grades - * @category phpunit - * @copyright 2012 Andrew Davis - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - */ +namespace core_grades; + +use grade_plugin_return; +use grade_report_user; defined('MOODLE_INTERNAL') || die(); @@ -29,11 +25,15 @@ global $CFG; require_once($CFG->dirroot.'/grade/lib.php'); require_once($CFG->dirroot.'/grade/report/user/lib.php'); - /** * Tests grade_report_user (the gradebook's user report) + * + * @package core_grades + * @category test + * @copyright 2012 Andrew Davis + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ -class core_grade_reportuserlib_testcase extends advanced_testcase { +class reportuserlib_test extends \advanced_testcase { /** * Tests grade_report_user::inject_rowspans() @@ -52,8 +52,8 @@ class core_grade_reportuserlib_testcase extends advanced_testcase { // Create a course. $course = $this->getDataGenerator()->create_course(); - $coursecategory = grade_category::fetch_course_category($course->id); - $coursecontext = context_course::instance($course->id); + $coursecategory = \grade_category::fetch_course_category($course->id); + $coursecontext = \context_course::instance($course->id); // Create and enrol test users. $student = $this->getDataGenerator()->create_user(array('username' => 'student_sam')); @@ -87,8 +87,8 @@ class core_grade_reportuserlib_testcase extends advanced_testcase { $forum1 = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => 100, 'course' => $course->id)); $forum1cm = get_coursemodule_from_id('forum', $forum1->cmid); - // Switch the stdClass instance for a grade item instance so grade_item::set_parent() is available. - $forum1 = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id)); + // Switch the stdClass instance for a grade item instance so \grade_item::set_parent() is available. + $forum1 = \grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id)); $report = $this->create_report($course, $student, $coursecontext); // Lead column + course + (2 x activity) = 4 @@ -123,11 +123,11 @@ class core_grade_reportuserlib_testcase extends advanced_testcase { set_coursemodule_visible($forum1cm->id, 1); // Create a category and put the forum in it. - $params = new stdClass(); + $params = new \stdClass(); $params->courseid = $course->id; $params->fullname = 'unittestcategory'; $params->parent = $coursecategory->id; - $gradecategory = new grade_category($params, false); + $gradecategory = new \grade_category($params, false); $gradecategory->insert(); $forum1->set_parent($gradecategory->id); diff --git a/h5p/tests/event_h5p_deleted_test.php b/h5p/tests/event/deleted_test.php similarity index 85% rename from h5p/tests/event_h5p_deleted_test.php rename to h5p/tests/event/deleted_test.php index 89d8ca94104..ebd171b041d 100644 --- a/h5p/tests/event_h5p_deleted_test.php +++ b/h5p/tests/event/deleted_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 for h5p deleted event. - * - * @package core_h5p - * @category test - * @copyright 2019 Carlos Escobedo - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 3.8 - */ - -defined('MOODLE_INTERNAL') || die(); +namespace core_h5p\event; use core_h5p\local\library\autoloader; @@ -37,7 +27,7 @@ use core_h5p\local\library\autoloader; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 3.8 */ -class core_h5p_event_h5p_deleted_testcase extends advanced_testcase { +class deleted_test extends \advanced_testcase { /** * Setup test. @@ -74,7 +64,7 @@ class core_h5p_event_h5p_deleted_testcase extends advanced_testcase { // Prepare redirect Events. $sink = $this->redirectEvents(); // Test the event H5P deleted. - $event = \core_h5p\event\h5p_deleted::create($params); + $event = h5p_deleted::create($params); $event->trigger(); $result = $sink->get_events(); $event = reset($result); diff --git a/h5p/tests/event_h5p_viewed_test.php b/h5p/tests/event/moved_test.php similarity index 87% rename from h5p/tests/event_h5p_viewed_test.php rename to h5p/tests/event/moved_test.php index 73eb2644b25..8a3b8f166b0 100644 --- a/h5p/tests/event_h5p_viewed_test.php +++ b/h5p/tests/event/moved_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 for h5p viewed event. - * - * @package core_h5p - * @category test - * @copyright 2019 Carlos Escobedo - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 3.8 - */ - -defined('MOODLE_INTERNAL') || die(); +namespace core_h5p\event; use core_h5p\local\library\autoloader; @@ -37,7 +27,7 @@ use core_h5p\local\library\autoloader; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 3.8 */ -class core_h5p_event_h5p_viewed_testcase extends advanced_testcase { +class moved_test extends \advanced_testcase { /** * Setup test. @@ -83,7 +73,7 @@ class core_h5p_event_h5p_viewed_testcase extends advanced_testcase { // Prepare redirect Events. $sink = $this->redirectEvents(); // Test the event H5P viewed. - $event = \core_h5p\event\h5p_viewed::create($params); + $event = h5p_viewed::create($params); $event->trigger(); $result = $sink->get_events(); $event = reset($result); diff --git a/iplookup/tests/geoip_test.php b/iplookup/tests/geoip_test.php index f4e2cfddea4..b547c186ff1 100644 --- a/iplookup/tests/geoip_test.php +++ b/iplookup/tests/geoip_test.php @@ -14,14 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * GeoIP tests - * - * @package core_iplookup - * @category phpunit - * @copyright 2012 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core; defined('MOODLE_INTERNAL') || die(); @@ -33,8 +26,13 @@ require_once("{$CFG->dirroot}/iplookup/lib.php"); /** * GeoIp data file parsing test. + * + * @package core + * @category test + * @copyright 2012 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_iplookup_geoip_testcase extends advanced_testcase { +class geoip_test extends \advanced_testcase { public function setUp(): void { $this->resetAfterTest(); } diff --git a/iplookup/tests/geoplugin_test.php b/iplookup/tests/geoplugin_test.php index e5589392236..20151cb4a8f 100644 --- a/iplookup/tests/geoplugin_test.php +++ b/iplookup/tests/geoplugin_test.php @@ -14,22 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * GeoIP tests - * - * @package core_iplookup - * @category phpunit - * @copyright 2012 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - +namespace core; /** * GeoIp data file parsing test. + * + * @package core + * @category test + * @copyright 2012 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_iplookup_geoplugin_testcase extends advanced_testcase { +class geoplugin_test extends \advanced_testcase { public function setUp(): void { global $CFG; diff --git a/lib/antivirus/clamav/tests/scanner_test.php b/lib/antivirus/clamav/tests/scanner_test.php index ce082333c69..a2dcb20e298 100644 --- a/lib/antivirus/clamav/tests/scanner_test.php +++ b/lib/antivirus/clamav/tests/scanner_test.php @@ -14,18 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace antivirus_clamav; + /** * Tests for ClamAV antivirus scanner class. * * @package antivirus_clamav - * @category phpunit + * @category test * @copyright 2016 Ruslan Kabalin, Lancaster University. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -class antivirus_clamav_scanner_testcase extends advanced_testcase { +class scanner_test extends \advanced_testcase { /** @var string temporary file used in testing */ protected $tempfile; diff --git a/message/output/email/tests/event_observers_test.php b/message/output/email/tests/event_observers_test.php index c9308cd661c..13f612ee934 100644 --- a/message/output/email/tests/event_observers_test.php +++ b/message/output/email/tests/event_observers_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 the event observers. - * - * @package message_email - * @category test - * @copyright 2019 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace message_email; /** * Class for testing the event observers. @@ -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 message_email_event_observers_task_testcase extends advanced_testcase { +class event_observers_test extends \advanced_testcase { /** * Test the message viewed event observer. @@ -63,7 +54,7 @@ class message_email_event_observers_task_testcase extends advanced_testcase { 'core_group', 'groups', $group1->id, - context_course::instance($course->id)->id + \context_course::instance($course->id)->id ); $message = new \core\message\message(); diff --git a/message/output/email/tests/send_email_task_test.php b/message/output/email/tests/task/send_email_test.php similarity index 91% rename from message/output/email/tests/send_email_task_test.php rename to message/output/email/tests/task/send_email_test.php index 474f3305129..b8a19775156 100644 --- a/message/output/email/tests/send_email_task_test.php +++ b/message/output/email/tests/task/send_email_test.php @@ -14,14 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests the send email task. - * - * @package message_email - * @category test - * @copyright 2018 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace message_email\task; defined('MOODLE_INTERNAL') || die(); @@ -37,7 +30,7 @@ require_once($CFG->dirroot . '/message/tests/messagelib_test.php'); * @copyright 2019 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_message_send_email_task_testcase extends advanced_testcase { +class send_email_test extends \advanced_testcase { /** * Test sending email task. @@ -72,7 +65,7 @@ class core_message_send_email_task_testcase extends advanced_testcase { 'core_group', 'groups', $group1->id, - context_course::instance($course->id)->id + \context_course::instance($course->id)->id ); $conversation2 = \core_message\api::create_conversation( @@ -83,7 +76,7 @@ class core_message_send_email_task_testcase extends advanced_testcase { 'core_group', 'groups', $group2->id, - context_course::instance($course->id)->id + \context_course::instance($course->id)->id ); // Go through each conversation. @@ -115,7 +108,7 @@ class core_message_send_email_task_testcase extends advanced_testcase { // Only 1 email is sent as the messages are included in it at a digest. $sink = $this->redirectEmails(); - $task = new \message_email\task\send_email_task(); + $task = new send_email_task(); $task->execute(); $this->assertEquals(1, $sink->count()); @@ -137,7 +130,7 @@ class core_message_send_email_task_testcase extends advanced_testcase { // Confirm running it again does not send another. $sink = $this->redirectEmails(); - $task = new \message_email\task\send_email_task(); + $task = new send_email_task(); $task->execute(); $this->assertEquals(0, $sink->count()); } diff --git a/message/output/popup/tests/messaging_cleanup_test.php b/message/output/popup/tests/messaging_cleanup_test.php index 6a2f4cb16e7..53c9742cafc 100644 --- a/message/output/popup/tests/messaging_cleanup_test.php +++ b/message/output/popup/tests/messaging_cleanup_test.php @@ -14,18 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Test message popup messaging cleanup task - * - * @package message_popup - * @category test - * @copyright 2020 Paul Holden - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace message_popup; use core\task\messaging_cleanup_task; +use message_popup_test_helper; + +defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/message/output/popup/tests/base.php'); @@ -38,7 +32,7 @@ require_once($CFG->dirroot . '/message/output/popup/tests/base.php'); * @copyright 2020 Paul Holden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class message_popup_messaging_cleanup_testcase extends advanced_testcase { +class messaging_cleanup_test extends \advanced_testcase { // Helper trait for sending fake popup notifications. use message_popup_test_helper; diff --git a/message/tests/api_test.php b/message/tests/api_test.php index 8a1c85ff075..87ef58e0f51 100644 --- a/message/tests/api_test.php +++ b/message/tests/api_test.php @@ -32,7 +32,7 @@ require_once($CFG->dirroot . '/message/tests/messagelib_test.php'); * @copyright 2016 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class api_test extends \core_message_messagelib_testcase { +class api_test extends messagelib_test { public function test_mark_all_read_for_user_touser() { $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1')); diff --git a/message/tests/event/events_test.php b/message/tests/event/events_test.php index cb174093419..bbf1852bdf4 100644 --- a/message/tests/event/events_test.php +++ b/message/tests/event/events_test.php @@ -25,8 +25,6 @@ namespace core_message\event; -use core_message_messagelib_testcase; - defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -41,7 +39,7 @@ require_once($CFG->dirroot . '/message/tests/messagelib_test.php'); * @copyright 2014 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class events_test extends core_message_messagelib_testcase { +class events_test extends \core_message\messagelib_test { /** * Test set up. diff --git a/message/tests/inbound_test.php b/message/tests/inbound_test.php index 6db7eb4ab66..1fe6ed972e3 100644 --- a/message/tests/inbound_test.php +++ b/message/tests/inbound_test.php @@ -22,16 +22,19 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace core_message; + defined('MOODLE_INTERNAL') || die(); require_once(__DIR__ . '/fixtures/inbound_fixtures.php'); /** * Tests for core_message_inbound to test Variable Envelope Return Path functionality. * + * @package core_message * @copyright 2014 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_message_inbound_testcase extends advanced_testcase { +class inbound_test extends \advanced_testcase { /** * Perform setup tasks generic to each test. @@ -67,7 +70,7 @@ class core_message_inbound_testcase extends advanced_testcase { $record->component = $component; $record->enabled = $enabled; $record->id = $DB->insert_record('messageinbound_handlers', $record); - $handler = \core_message_inbound_test_manager::handler_from_record($record); + $handler = core_message_inbound_test_manager::handler_from_record($record); return $handler; } diff --git a/message/tests/messagelib_test.php b/message/tests/messagelib_test.php index 7f4a5362e73..d425a25b68d 100644 --- a/message/tests/messagelib_test.php +++ b/message/tests/messagelib_test.php @@ -14,22 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Test api's in message lib. - * - * @package core_message - * @category test - * @copyright 2014 Rajesh Taneja - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_message; + +use core_message\tests\helper as testhelper; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/message/lib.php'); -use \core_message\tests\helper as testhelper; - /** * Test api's in message lib. * @@ -38,7 +31,7 @@ use \core_message\tests\helper as testhelper; * @copyright 2014 Rajesh Taneja * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_message_messagelib_testcase extends advanced_testcase { +class messagelib_test extends \advanced_testcase { /** @var phpunit_message_sink keep track of messages. */ protected $messagesink = null; @@ -61,8 +54,8 @@ class core_message_messagelib_testcase extends advanced_testcase { * sent from a user to another. We should stop using it once {@link message_send()} will support * transactions. This is not clean at all, this is just used to add rows to the table. * - * @param stdClass $userfrom user object of the one sending the message. - * @param stdClass $userto user object of the one receiving the message. + * @param \stdClass $userfrom user object of the one sending the message. + * @param \stdClass $userto user object of the one receiving the message. * @param string $message message to send. * @param int $notification if the message is a notification. * @param int $time the time the message was sent @@ -76,7 +69,7 @@ class core_message_messagelib_testcase extends advanced_testcase { } if ($notification) { - $record = new stdClass(); + $record = new \stdClass(); $record->useridfrom = $userfrom->id; $record->useridto = $userto->id; $record->subject = 'No subject'; @@ -110,7 +103,7 @@ class core_message_messagelib_testcase extends advanced_testcase { } // Ok, send the message. - $record = new stdClass(); + $record = new \stdClass(); $record->useridfrom = $userfrom->id; $record->conversationid = $conversationid; $record->subject = 'No subject'; diff --git a/message/tests/search_received_test.php b/message/tests/search_received_test.php index 7e59a281eb8..c2fbaf7f92c 100644 --- a/message/tests/search_received_test.php +++ b/message/tests/search_received_test.php @@ -14,13 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * received message global search unit tests. - * - * @package core - * @copyright 2016 Devang Gaur - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_message; defined('MOODLE_INTERNAL') || die(); @@ -30,11 +24,11 @@ require_once($CFG->dirroot . '/search/tests/fixtures/testable_core_search.php'); /** * Provides the unit tests for received messages global search. * - * @package core + * @package core_message * @copyright 2016 Devang Gaur * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class message_received_search_testcase extends advanced_testcase { +class search_received_test extends \advanced_testcase { /** * @var string Area id @@ -52,7 +46,7 @@ class message_received_search_testcase extends advanced_testcase { $this->messagereceivedareaid = \core_search\manager::generate_areaid('core_message', 'message_received'); // 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(); } /** @@ -163,19 +157,19 @@ class message_received_search_testcase extends advanced_testcase { // Test function with null context and system context (same). $rs = $searcharea->get_document_recordset(0, null); - $this->assertEquals(['Test1', 'Test2'], message_sent_search_testcase::recordset_to_subjects($rs)); - $rs = $searcharea->get_document_recordset(0, context_system::instance()); - $this->assertEquals(['Test1', 'Test2'], message_sent_search_testcase::recordset_to_subjects($rs)); + $this->assertEquals(['Test1', 'Test2'], search_sent_test::recordset_to_subjects($rs)); + $rs = $searcharea->get_document_recordset(0, \context_system::instance()); + $this->assertEquals(['Test1', 'Test2'], search_sent_test::recordset_to_subjects($rs)); // Test with user context for each user. $rs = $searcharea->get_document_recordset(0, \context_user::instance($user1->id)); - $this->assertEquals(['Test2'], message_sent_search_testcase::recordset_to_subjects($rs)); + $this->assertEquals(['Test2'], search_sent_test::recordset_to_subjects($rs)); $rs = $searcharea->get_document_recordset(0, \context_user::instance($user2->id)); - $this->assertEquals(['Test1'], message_sent_search_testcase::recordset_to_subjects($rs)); + $this->assertEquals(['Test1'], search_sent_test::recordset_to_subjects($rs)); // Test with a course context (should return null). $this->assertNull($searcharea->get_document_recordset(0, - context_course::instance($SITE->id))); + \context_course::instance($SITE->id))); } /** diff --git a/message/tests/search_sent_test.php b/message/tests/search_sent_test.php index 91a0a6e4668..d81500499f2 100644 --- a/message/tests/search_sent_test.php +++ b/message/tests/search_sent_test.php @@ -14,13 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Sent message global search unit tests. - * - * @package core - * @copyright 2016 Devang Gaur - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_message; defined('MOODLE_INTERNAL') || die(); @@ -30,11 +24,11 @@ require_once($CFG->dirroot . '/search/tests/fixtures/testable_core_search.php'); /** * Provides the unit tests for sent message global search. * - * @package core + * @package core_message * @copyright 2016 Devang Gaur * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class message_sent_search_testcase extends advanced_testcase { +class search_sent_test extends \advanced_testcase { /** * @var string Area id @@ -52,7 +46,7 @@ class message_sent_search_testcase extends advanced_testcase { $this->messagesentareaid = \core_search\manager::generate_areaid('core_message', 'message_sent'); // 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(); } /** @@ -163,7 +157,7 @@ class message_sent_search_testcase extends advanced_testcase { // Test function with null context and system context (same). $rs = $searcharea->get_document_recordset(0, null); $this->assertEquals(['Test1', 'Test2'], self::recordset_to_subjects($rs)); - $rs = $searcharea->get_document_recordset(0, context_system::instance()); + $rs = $searcharea->get_document_recordset(0, \context_system::instance()); $this->assertEquals(['Test1', 'Test2'], self::recordset_to_subjects($rs)); // Test with user context for each user. @@ -174,7 +168,7 @@ class message_sent_search_testcase extends advanced_testcase { // Test with a course context (should return null). $this->assertNull($searcharea->get_document_recordset(0, - context_course::instance($SITE->id))); + \context_course::instance($SITE->id))); } /** @@ -183,7 +177,7 @@ class message_sent_search_testcase extends advanced_testcase { * @param moodle_recordset $rs Recordset to convert (and close) * @return array Array of IDs from records indexed by number (0, 1, 2, ...) */ - public static function recordset_to_subjects(moodle_recordset $rs) { + public static function recordset_to_subjects(\moodle_recordset $rs) { $results = []; foreach ($rs as $rec) { $results[] = $rec->subject; diff --git a/message/tests/migrate_message_data_task_test.php b/message/tests/task/migrate_message_data_test.php similarity index 95% rename from message/tests/migrate_message_data_task_test.php rename to message/tests/task/migrate_message_data_test.php index 704396b669d..15b19de8fc4 100644 --- a/message/tests/migrate_message_data_task_test.php +++ b/message/tests/task/migrate_message_data_test.php @@ -14,14 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests the migrate message data task. - * - * @package core_message - * @category test - * @copyright 2018 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_message\task; defined('MOODLE_INTERNAL') || die(); @@ -37,7 +30,7 @@ require_once($CFG->dirroot . '/message/tests/messagelib_test.php'); * @copyright 2018 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_message_migrate_message_data_task_testcase extends advanced_testcase { +class migrate_message_data_test extends \advanced_testcase { /** * Test set up. @@ -83,18 +76,18 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase $m9 = $this->create_legacy_message_or_notification($user3->id, $user2->id, 9); // Let's delete some messages, not using API here as it does not use the legacy tables. - $messageupdate = new stdClass(); + $messageupdate = new \stdClass(); $messageupdate->id = $m1; $messageupdate->timeusertodeleted = $timedeleted1; $DB->update_record('message_read', $messageupdate); - $messageupdate = new stdClass(); + $messageupdate = new \stdClass(); $messageupdate->id = $m5; $messageupdate->timeuserfromdeleted = $timedeleted2; $DB->update_record('message', $messageupdate); // Now, let's execute the task for user 1. - $task = new \core_message\task\migrate_message_data(); + $task = new migrate_message_data(); $task->set_custom_data( [ 'userid' => $user1->id @@ -214,7 +207,7 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase $this->create_legacy_message_or_notification($user3->id, $user2->id, 9, true); // Now, let's execute the task for user 1. - $task = new \core_message\task\migrate_message_data(); + $task = new migrate_message_data(); $task->set_custom_data( [ 'userid' => $user1->id @@ -281,7 +274,7 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase $this->create_legacy_message_or_notification($user1->id, $user2->id, null, false, null, null); // Now, let's execute the task for user 1. - $task = new \core_message\task\migrate_message_data(); + $task = new migrate_message_data(); $task->set_custom_data( [ 'userid' => $user1->id @@ -309,7 +302,7 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase $this->create_legacy_message_or_notification($user1->id, $user2->id, null, true, null, null); // Now, let's execute the task for user 1. - $task = new \core_message\task\migrate_message_data(); + $task = new migrate_message_data(); $task->set_custom_data( [ 'userid' => $user1->id @@ -336,14 +329,14 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase $m1 = $this->create_legacy_message_or_notification($user1->id, $user1->id, null, false, null, null); // Let's delete the message for the 'user to' and 'user from' which in this case is the same user. - $messageupdate = new stdClass(); + $messageupdate = new \stdClass(); $messageupdate->id = $m1; $messageupdate->timeuserfromdeleted = time(); $messageupdate->timeusertodeleted = time(); $DB->update_record('message', $messageupdate); // Now, let's execute the task for the user. - $task = new \core_message\task\migrate_message_data(); + $task = new migrate_message_data(); $task->set_custom_data( [ 'userid' => $user1->id @@ -409,7 +402,7 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase // Insert into the legacy 'message_popup' table if it is a notification. if ($notification) { - $mp = new stdClass(); + $mp = new \stdClass(); $mp->messageid = $id; $mp->isread = (!is_null($timeread)) ? 1 : 0; diff --git a/mod/assign/feedback/file/tests/importziplib_test.php b/mod/assign/feedback/file/tests/importziplib_test.php index 009579b893b..1c19d71d350 100644 --- a/mod/assign/feedback/file/tests/importziplib_test.php +++ b/mod/assign/feedback/file/tests/importziplib_test.php @@ -22,6 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace assignfeedback_file; + +use mod_assign_test_generator; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -31,10 +35,11 @@ require_once($CFG->dirroot . '/mod/assign/feedback/file/importziplib.php'); /** * Unit tests for importziplib. * + * @package assignfeedback_file * @copyright 2020 Eric Merrill * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class assignfeedback_importziplib_testcase extends advanced_testcase { +class importziplib_test extends \advanced_testcase { // Use the generator helper. use mod_assign_test_generator; @@ -61,7 +66,7 @@ class assignfeedback_importziplib_testcase extends advanced_testcase { $fs = get_file_storage(); // Setup a basic file we will work with. We will keep renaming and repathing it. - $record = new stdClass; + $record = new \stdClass; $record->contextid = $assign->get_context()->id; $record->component = 'assignfeedback_file'; $record->filearea = ASSIGNFEEDBACK_FILE_FILEAREA; @@ -72,7 +77,7 @@ class assignfeedback_importziplib_testcase extends advanced_testcase { $file = $fs->create_file_from_string($record, 'file content'); // The importer we will use. - $importer = new assignfeedback_file_zip_importer(); + $importer = new \assignfeedback_file_zip_importer(); // Setup some variable we use. $user = null; @@ -132,7 +137,7 @@ class assignfeedback_importziplib_testcase extends advanced_testcase { $this->assertTrue($result); $this->assertEquals($participants[$studentid], $user); $this->assertEquals('My_cool_filename.txt', $filename); - $this->assertInstanceOf(assign_submission_file::class, $plugin); + $this->assertInstanceOf(\assign_submission_file::class, $plugin); // Test another good file, with some additional path and underscores. $user = null; @@ -143,6 +148,6 @@ class assignfeedback_importziplib_testcase extends advanced_testcase { $this->assertTrue($result); $this->assertEquals($participants[$studentid], $user); $this->assertEquals('/some_path/My File.txt', $filename); - $this->assertInstanceOf(assign_submission_file::class, $plugin); + $this->assertInstanceOf(\assign_submission_file::class, $plugin); } } diff --git a/mod/assign/tests/feedback_test.php b/mod/assign/tests/feedback_test.php index ec93ffd8501..1196fbcfda7 100644 --- a/mod/assign/tests/feedback_test.php +++ b/mod/assign/tests/feedback_test.php @@ -14,14 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Assign feedback unit tests. - * - * @package mod_assign - * @category test - * @copyright 2019 Ilya Tregubov ilyatregubov@catalyst-au.net - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_assign; + +use assignfeedback_editpdf\document_services; +use assignfeedback_editpdf\combined_document; +use mod_assign_test_generator; defined('MOODLE_INTERNAL') || die(); @@ -29,9 +26,6 @@ global $CFG; require_once($CFG->dirroot . '/mod/assign/locallib.php'); require_once($CFG->dirroot . '/mod/assign/tests/generator.php'); -use \assignfeedback_editpdf\document_services; -use \assignfeedback_editpdf\combined_document; - /** * Provides the unit tests for feedback. * @@ -40,7 +34,7 @@ use \assignfeedback_editpdf\combined_document; * @copyright 2019 Ilya Tregubov ilyatregubov@catalyst-au.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_assign_feedback_testcase extends advanced_testcase { +class feedback_test extends \advanced_testcase { // Use the generator helper. use mod_assign_test_generator; diff --git a/mod/assign/tests/locallib_participants_test.php b/mod/assign/tests/locallib_participants_test.php index 84ee80a1b7e..7656238ac7f 100644 --- a/mod/assign/tests/locallib_participants_test.php +++ b/mod/assign/tests/locallib_participants_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 (some of) mod/assign/locallib.php. - * - * @package mod_assign - * @category phpunit - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_assign; +use mod_assign_test_generator; defined('MOODLE_INTERNAL') || die(); @@ -30,7 +24,15 @@ global $CFG; require_once(__DIR__ . '/../locallib.php'); require_once($CFG->dirroot . '/mod/assign/tests/generator.php'); -class mod_assign_locallib_participants extends advanced_testcase { +/** + * Unit tests for (some of) mod/assign/locallib.php. + * + * @package mod_assign + * @category test + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class locallib_participants_test extends \advanced_testcase { use mod_assign_test_generator; public function test_list_participants_blind_marking() { @@ -61,12 +63,12 @@ class mod_assign_locallib_participants extends advanced_testcase { $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); $instance = $generator->create_instance(['course' => $course->id, 'blindmarking' => 1]); $cm = get_coursemodule_from_instance('assign', $instance->id); - $context = context_module::instance($cm->id); - $assign = new assign($context, $cm, $course); + $context = \context_module::instance($cm->id); + $assign = new \assign($context, $cm, $course); // Allocate IDs now. // We're testing whether the IDs are correct after allocation. - assign::allocate_unique_ids($assign->get_instance()->id); + \assign::allocate_unique_ids($assign->get_instance()->id); $participants = $assign->list_participants(null, false); @@ -79,20 +81,20 @@ class mod_assign_locallib_participants extends advanced_testcase { $keys = array_keys($participants); // Create a grading table, and query the DB This should have the same order. - $table = new assign_grading_table($assign, 10, '', 0, false); + $table = new \assign_grading_table($assign, 10, '', 0, false); $table->setup(); $table->query_db(10); $this->assertEquals($keys, array_keys($table->rawdata)); // Submit a file for the second student. - $data = new stdClass(); + $data = new \stdClass(); $data->onlinetext_editor = array('itemid'=>file_get_unused_draft_itemid(), 'text'=>'Submission text', 'format'=>FORMAT_MOODLE); static::helper_add_submission($assign, $participants[$keys[1]], $data, 'onlinetext'); // Assign has a private cache. The easiest way to clear this is to create a new instance. - $assign = new assign($context, $cm, $course); + $assign = new \assign($context, $cm, $course); $newparticipants = $assign->list_participants(null, false); @@ -109,7 +111,7 @@ class mod_assign_locallib_participants extends advanced_testcase { // Submit for the other student. static::helper_add_submission($assign, $participants[$keys[0]], $data, 'onlinetext'); - $assign = new assign($context, $cm, $course); + $assign = new \assign($context, $cm, $course); $newparticipants = $assign->list_participants(null, false); // The users should still be listed in order of the first submission @@ -129,10 +131,10 @@ class mod_assign_locallib_participants extends advanced_testcase { $this->resetAfterTest(true); // Create a role that will prevent users submitting. $role = self::getDataGenerator()->create_role(); - assign_capability('mod/assign:submit', CAP_PROHIBIT, $role, context_system::instance()); + assign_capability('mod/assign:submit', CAP_PROHIBIT, $role, \context_system::instance()); // Create the test data. $course = self::getDataGenerator()->create_course(); - $coursecontext = context_course::instance($course->id); + $coursecontext = \context_course::instance($course->id); $assign = $this->create_instance($course); self::getDataGenerator()->create_and_enrol($course, 'teacher'); $student1 = self::getDataGenerator()->create_and_enrol($course, 'student'); @@ -164,7 +166,7 @@ class mod_assign_locallib_participants extends advanced_testcase { $submission = $assign->get_user_submission($user->id, true); $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; - $rc = new ReflectionClass('assign'); + $rc = new \ReflectionClass('assign'); $rcm = $rc->getMethod('update_submission'); $rcm->setAccessible(true); $rcm->invokeArgs($assign, [$submission, $user->id, true, false]); diff --git a/mod/assign/tests/markerallocation_test.php b/mod/assign/tests/markerallocation_test.php index 09b5591eab3..41660dc2546 100644 --- a/mod/assign/tests/markerallocation_test.php +++ b/mod/assign/tests/markerallocation_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 (some of) mod/assign/markerallocaion_test.php. - * - * @package mod_assign - * @category test - * @copyright 2017 Andrés Melo - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_assign; defined('MOODLE_INTERNAL') || die(); @@ -30,13 +23,14 @@ require_once($CFG->dirroot . '/lib/accesslib.php'); require_once($CFG->dirroot . '/course/lib.php'); /** - * This class tests some of marker allocation functionality. + * Unit tests for (some of) mod/assign/markerallocaion_test.php. * * @package mod_assign + * @category test * @copyright 2017 Andrés Melo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_assign_markerallocation_testcase extends advanced_testcase { +class markerallocation_test extends \advanced_testcase { /** * Create all the needed elements to test the difference between both functions. @@ -49,7 +43,7 @@ class mod_assign_markerallocation_testcase extends advanced_testcase { $this->course = $this->getDataGenerator()->create_course(); // Setting assing module, markingworkflow and markingallocation set to 1 to enable marker allocation. - $record = new stdClass(); + $record = new \stdClass(); $record->course = $this->course; $modulesettings = array( @@ -122,9 +116,9 @@ class mod_assign_markerallocation_testcase extends advanced_testcase { list($sort, $params) = users_order_by_sql('u'); // Old code, it must return 3 users: teacher1, teacher2 and Manger. - $oldmarkers = get_users_by_capability(context_course::instance($this->course->id), 'mod/assign:grade', '', $sort); + $oldmarkers = get_users_by_capability(\context_course::instance($this->course->id), 'mod/assign:grade', '', $sort); // New code, it must return 2 users: teacher1 and teacher2. - $newmarkers = get_enrolled_users(context_course::instance($this->course->id), 'mod/assign:grade', 0, 'u.*', $sort); + $newmarkers = get_enrolled_users(\context_course::instance($this->course->id), 'mod/assign:grade', 0, 'u.*', $sort); // Test result quantity. $this->assertEquals(count($oldusers), count($oldmarkers)); diff --git a/mod/assign/tests/privacy_feedback_legacy_polyfill_test.php b/mod/assign/tests/privacy/feedback_legacy_polyfill_test.php similarity index 94% rename from mod/assign/tests/privacy_feedback_legacy_polyfill_test.php rename to mod/assign/tests/privacy/feedback_legacy_polyfill_test.php index 94f3ebf0023..3189ba7b1c6 100644 --- a/mod/assign/tests/privacy_feedback_legacy_polyfill_test.php +++ b/mod/assign/tests/privacy/feedback_legacy_polyfill_test.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Unit tests for the privacy legacy polyfill for mod_assign. * @@ -22,6 +23,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_assign\privacy; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -31,10 +34,12 @@ require_once($CFG->dirroot . '/mod/assign/feedback/comments/locallib.php'); /** * Unit tests for the assignment feedback subplugins API's privacy legacy_polyfill. * + * @package mod_assign + * @category test * @copyright 2018 Adrian Greeve * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_assignfeedback_privacy_legacy_polyfill_test extends advanced_testcase { +class feedback_legacy_polyfill_test extends \advanced_testcase { /** * Convenience function to create an instance of an assignment. @@ -86,8 +91,8 @@ class mod_assignfeedback_privacy_legacy_polyfill_test extends advanced_testcase $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); $assign = $this->create_instance(['course' => $course]); - $context = context_system::instance(); - $subplugin = new assign_feedback_comments($assign, 'comments'); + $context = \context_system::instance(); + $subplugin = new \assign_feedback_comments($assign, 'comments'); $requestdata = new \mod_assign\privacy\assign_plugin_request_data($context,$assign); $mock = $this->createMock(test_assignfeedback_legacy_polyfill_mock_wrapper::class); $mock->expects($this->once()) @@ -104,8 +109,8 @@ class mod_assignfeedback_privacy_legacy_polyfill_test extends advanced_testcase $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); $assign = $this->create_instance(['course' => $course]); - $context = context_system::instance(); - $subplugin = new assign_feedback_comments($assign, 'comments'); + $context = \context_system::instance(); + $subplugin = new \assign_feedback_comments($assign, 'comments'); $requestdata = new \mod_assign\privacy\assign_plugin_request_data($context,$assign); $mock = $this->createMock(test_assignfeedback_legacy_polyfill_mock_wrapper::class); $mock->expects($this->once()) @@ -122,8 +127,8 @@ class mod_assignfeedback_privacy_legacy_polyfill_test extends advanced_testcase $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); $assign = $this->create_instance(['course' => $course]); - $context = context_system::instance(); - $subplugin = new assign_feedback_comments($assign, 'comments'); + $context = \context_system::instance(); + $subplugin = new \assign_feedback_comments($assign, 'comments'); $requestdata = new \mod_assign\privacy\assign_plugin_request_data($context,$assign); $mock = $this->createMock(test_assignfeedback_legacy_polyfill_mock_wrapper::class); $mock->expects($this->once()) diff --git a/mod/assign/tests/privacy_submission_legacy_polyfill_test.php b/mod/assign/tests/privacy/submission_legacy_polyfill_test.php similarity index 94% rename from mod/assign/tests/privacy_submission_legacy_polyfill_test.php rename to mod/assign/tests/privacy/submission_legacy_polyfill_test.php index 41ab5e7b1b9..5a91de789b1 100644 --- a/mod/assign/tests/privacy_submission_legacy_polyfill_test.php +++ b/mod/assign/tests/privacy/submission_legacy_polyfill_test.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Unit tests for the privacy legacy polyfill for mod_assign. * @@ -21,6 +22,9 @@ * @copyright 2018 Adrian Greeve * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +namespace mod_assign\privacy; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -30,10 +34,12 @@ require_once($CFG->dirroot . '/mod/assign/submission/comments/locallib.php'); /** * Unit tests for the assignment submission subplugins API's privacy legacy_polyfill. * + * @package mod_assign + * @category test * @copyright 2018 Adrian Greeve * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_assignsubmission_privacy_legacy_polyfill_test extends advanced_testcase { +class submission_legacy_polyfill_test extends \advanced_testcase { /** * Convenience function to create an instance of an assignment. @@ -85,8 +91,8 @@ class mod_assignsubmission_privacy_legacy_polyfill_test extends advanced_testcas $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); $assign = $this->create_instance(['course' => $course]); - $context = context_system::instance(); - $subplugin = new assign_submission_comments($assign, 'comment'); + $context = \context_system::instance(); + $subplugin = new \assign_submission_comments($assign, 'comment'); $requestdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign); $mock = $this->createMock(test_assignsubmission_legacy_polyfill_mock_wrapper::class); $mock->expects($this->once()) @@ -103,8 +109,8 @@ class mod_assignsubmission_privacy_legacy_polyfill_test extends advanced_testcas $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); $assign = $this->create_instance(['course' => $course]); - $context = context_system::instance(); - $subplugin = new assign_submission_comments($assign, 'comment'); + $context = \context_system::instance(); + $subplugin = new \assign_submission_comments($assign, 'comment'); $requestdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign); $mock = $this->createMock(test_assignsubmission_legacy_polyfill_mock_wrapper::class); $mock->expects($this->once()) @@ -121,8 +127,8 @@ class mod_assignsubmission_privacy_legacy_polyfill_test extends advanced_testcas $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); $assign = $this->create_instance(['course' => $course]); - $context = context_system::instance(); - $subplugin = new assign_submission_comments($assign, 'comment'); + $context = \context_system::instance(); + $subplugin = new \assign_submission_comments($assign, 'comment'); $requestdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign); $mock = $this->createMock(test_assignsubmission_legacy_polyfill_mock_wrapper::class); $mock->expects($this->once()) diff --git a/mod/chat/tests/format_message_test.php b/mod/chat/tests/format_message_test.php index 99aba3d51b7..d27691b4f36 100644 --- a/mod/chat/tests/format_message_test.php +++ b/mod/chat/tests/format_message_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 format_message. - * - * @package mod_chat - * @copyright 2016 Andrew NIcols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_chat; defined('MOODLE_INTERNAL') || die(); @@ -34,7 +28,7 @@ require_once($CFG->dirroot . '/mod/chat/lib.php'); * @copyright 2016 Andrew NIcols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_chat_format_message_testcase extends advanced_testcase { +class format_message_test extends \advanced_testcase { const USER_CURRENT = 1; const USER_OTHER = 2; diff --git a/mod/feedback/tests/completion_test.php b/mod/feedback/tests/completion_test.php index eef05dd874c..2b322b2c26c 100644 --- a/mod/feedback/tests/completion_test.php +++ b/mod/feedback/tests/completion_test.php @@ -13,13 +13,11 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for (some of) mod/feedback/classes/lib.php. - * - * @package mod_feedback - * @copyright 2019 Tobias Reischmann - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ + +namespace mod_feedback; + +use mod_feedback_completion; + defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/mod/feedback/classes/completion.php'); @@ -27,10 +25,11 @@ require_once($CFG->dirroot . '/mod/feedback/classes/completion.php'); /** * Unit tests for (some of) mod/feedback/classes/completion.php. * + * @package mod_feedback * @copyright 2019 Tobias Reischmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_feedback_completion_testcase extends advanced_testcase { +class completion_test extends \advanced_testcase { /** * Returns the number of pages with visible elements for the current state of the feedback completion. * @param mod_feedback_completion $completion diff --git a/mod/forum/tests/backup_forum_activity_test.php b/mod/forum/tests/backup_forum_activity_task_test.php similarity index 94% rename from mod/forum/tests/backup_forum_activity_test.php rename to mod/forum/tests/backup_forum_activity_task_test.php index 676950e1684..d0990a31d46 100644 --- a/mod/forum/tests/backup_forum_activity_test.php +++ b/mod/forum/tests/backup_forum_activity_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 . -/** - * Tests for mod_forum_backup_forum_activity_task. - * - * @package mod_forum - * @category test - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_forum; + +use backup_forum_activity_task; defined('MOODLE_INTERNAL') || die(); @@ -40,7 +35,7 @@ require_once($CFG->dirroot . '/mod/forum/backup/moodle2/backup_forum_activity_ta * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_backup_forum_activity_task_testcase extends advanced_testcase { +class backup_forum_activity_task_test extends \advanced_testcase { /** * Test the encoding of forum content links. diff --git a/mod/forum/tests/builders_exported_posts_test.php b/mod/forum/tests/builders_exported_posts_test.php index b3db3495906..f321617cea9 100644 --- a/mod/forum/tests/builders_exported_posts_test.php +++ b/mod/forum/tests/builders_exported_posts_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The exported_posts builder tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @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(); @@ -33,7 +29,7 @@ require_once(__DIR__ . '/generator_trait.php'); * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_builders_exported_posts_testcase extends advanced_testcase { +class builders_exported_posts_test extends \advanced_testcase { // Make use of the test generator trait. use mod_forum_tests_generator_trait; @@ -78,16 +74,16 @@ class mod_forum_builders_exported_posts_testcase extends advanced_testcase { array_map(function($forum) use ($entityfactory, $DB) { $course = $DB->get_record('course', ['id' => $forum->course]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); - return $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); + $context = \context_module::instance($coursemodule->id); + return $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); }, $forums), // Discussions. array_map(function($discussion) use ($entityfactory) { - return $entityfactory->get_discussion_from_stdclass($discussion); + return $entityfactory->get_discussion_from_stdClass($discussion); }, $discussions), // Posts. array_map(function($post) use ($entityfactory) { - return $entityfactory->get_post_from_stdclass($post); + return $entityfactory->get_post_from_stdClass($post); }, $posts) ]; } diff --git a/mod/forum/tests/entities_author_test.php b/mod/forum/tests/entities_author_test.php index 198566fbb24..0fc19054aa9 100644 --- a/mod/forum/tests/entities_author_test.php +++ b/mod/forum/tests/entities_author_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The author entity tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; use mod_forum\local\entities\author as author_entity; @@ -33,7 +25,7 @@ use mod_forum\local\entities\author as author_entity; * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_entities_author_testcase extends advanced_testcase { +class entities_author_test extends \advanced_testcase { /** * Test the entity returns expected values. */ diff --git a/mod/forum/tests/entities_discussion_summary_test.php b/mod/forum/tests/entities_discussion_summary_test.php index adc051ae9c4..9fed57a368d 100644 --- a/mod/forum/tests/entities_discussion_summary_test.php +++ b/mod/forum/tests/entities_discussion_summary_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The discussion_summary entity tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; use mod_forum\local\entities\author as author_entity; use mod_forum\local\entities\discussion as discussion_entity; @@ -36,7 +28,7 @@ use mod_forum\local\entities\post as post_entity; * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_entities_discussion_summary_testcase extends advanced_testcase { +class entities_discussion_summary_test extends \advanced_testcase { /** * Test the entity returns expected values. */ diff --git a/mod/forum/tests/entities_discussion_test.php b/mod/forum/tests/entities_discussion_test.php index b4779010fc5..ae161e3389c 100644 --- a/mod/forum/tests/entities_discussion_test.php +++ b/mod/forum/tests/entities_discussion_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The discussion entity tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; use mod_forum\local\entities\discussion as discussion_entity; use mod_forum\local\entities\post as post_entity; @@ -34,7 +26,7 @@ use mod_forum\local\entities\post as post_entity; * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_entities_discussion_testcase extends advanced_testcase { +class entities_discussion_test extends \advanced_testcase { /** * Test the entity returns expected values. */ diff --git a/mod/forum/tests/entities_forum_test.php b/mod/forum/tests/entities_forum_test.php index aaf9f7b5ea4..2d52ba37910 100644 --- a/mod/forum/tests/entities_forum_test.php +++ b/mod/forum/tests/entities_forum_test.php @@ -14,22 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The forum entity tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_forum; + +use mod_forum\local\entities\discussion as discussion_entity; +use mod_forum\local\entities\forum as forum_entity; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/rating/lib.php'); -use mod_forum\local\entities\discussion as discussion_entity; -use mod_forum\local\entities\forum as forum_entity; - /** * The forum entity tests. * @@ -37,7 +31,7 @@ use mod_forum\local\entities\forum as forum_entity; * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_entities_forum_testcase extends advanced_testcase { +class entities_forum_test extends \advanced_testcase { /** * Test the entity returns expected values. */ @@ -66,7 +60,7 @@ class mod_forum_entities_forum_testcase extends advanced_testcase { $course = $this->getDataGenerator()->create_course(); $forum = $this->getDataGenerator()->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); $effectivegroupmode = NOGROUPS; $id = 1; $courseid = 2; diff --git a/mod/forum/tests/entities_post_read_receipt_collection_test.php b/mod/forum/tests/entities_post_read_receipt_collection_test.php index f1dc18927ee..6bab5a2ade5 100644 --- a/mod/forum/tests/entities_post_read_receipt_collection_test.php +++ b/mod/forum/tests/entities_post_read_receipt_collection_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The post_read_receipt_collection entity tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; use mod_forum\local\entities\post_read_receipt_collection as collection_entity; use mod_forum\local\entities\post as post_entity; @@ -34,7 +26,7 @@ use mod_forum\local\entities\post as post_entity; * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_entities_post_read_receipt_collection_testcase extends advanced_testcase { +class entities_post_read_receipt_collection_test extends \advanced_testcase { /** * Test the entity returns expected values. */ diff --git a/mod/forum/tests/entities_post_test.php b/mod/forum/tests/entities_post_test.php index 01ecf6ee4ea..4c826bcceea 100644 --- a/mod/forum/tests/entities_post_test.php +++ b/mod/forum/tests/entities_post_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The post entity tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; use mod_forum\local\entities\post as post_entity; @@ -33,7 +25,7 @@ use mod_forum\local\entities\post as post_entity; * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_entities_post_testcase extends advanced_testcase { +class entities_post_test extends \advanced_testcase { /** * Test the entity returns expected values. */ diff --git a/mod/forum/tests/entities_sorter_test.php b/mod/forum/tests/entities_sorter_test.php index f27020f566a..28e32e285a6 100644 --- a/mod/forum/tests/entities_sorter_test.php +++ b/mod/forum/tests/entities_sorter_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The discussion entity tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; use mod_forum\local\entities\sorter as sorter_entity; @@ -33,7 +25,7 @@ use mod_forum\local\entities\sorter as sorter_entity; * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_entities_sorter_testcase extends advanced_testcase { +class entities_sorter_test extends \advanced_testcase { /** * Test the entity returns expected values. */ diff --git a/mod/forum/tests/exporters_author_test.php b/mod/forum/tests/exporters_author_test.php index 7e85c102e3d..9ede08173ef 100644 --- a/mod/forum/tests/exporters_author_test.php +++ b/mod/forum/tests/exporters_author_test.php @@ -14,19 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The author exporter tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; use mod_forum\local\entities\author as author_entity; use mod_forum\local\exporters\author as author_exporter; -global $CFG; /** * The author exporter tests. @@ -35,7 +26,7 @@ global $CFG; * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_exporters_author_testcase extends advanced_testcase { +class exporters_author_test extends \advanced_testcase { /** * Test the export function returns expected values. */ @@ -48,9 +39,9 @@ class mod_forum_exporters_author_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); $entityfactory = \mod_forum\local\container::get_entity_factory(); - $forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); + $forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); $author = new author_entity( 1, 1, @@ -88,9 +79,9 @@ class mod_forum_exporters_author_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); $entityfactory = \mod_forum\local\container::get_entity_factory(); - $forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); + $forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); $author = new author_entity( 1, 1, @@ -127,9 +118,9 @@ class mod_forum_exporters_author_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); $entityfactory = \mod_forum\local\container::get_entity_factory(); - $forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); + $forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); $author = new author_entity( 1, 1, diff --git a/mod/forum/tests/exporters_discussion_test.php b/mod/forum/tests/exporters_discussion_test.php index d31d1499a49..6a2d294260e 100644 --- a/mod/forum/tests/exporters_discussion_test.php +++ b/mod/forum/tests/exporters_discussion_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The discussion exporter tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; use mod_forum\local\entities\discussion as discussion_entity; use mod_forum\local\exporters\discussion as discussion_exporter; @@ -34,7 +26,7 @@ use mod_forum\local\exporters\discussion as discussion_exporter; * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_exporters_discussion_testcase extends advanced_testcase { +class exporters_discussion_test extends \advanced_testcase { /** * Test set up function. */ @@ -69,9 +61,9 @@ class mod_forum_exporters_discussion_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); $entityfactory = \mod_forum\local\container::get_entity_factory(); - $forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); + $forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); $group = $datagenerator->create_group(['courseid' => $course->id]); $now = time(); $discussion = new discussion_entity( diff --git a/mod/forum/tests/exporters_forum_test.php b/mod/forum/tests/exporters_forum_test.php index 3cd8af43263..b28f5e80608 100644 --- a/mod/forum/tests/exporters_forum_test.php +++ b/mod/forum/tests/exporters_forum_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The discussion forum tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; use mod_forum\local\entities\forum as forum_entity; use mod_forum\local\exporters\forum as forum_exporter; @@ -34,7 +26,7 @@ use mod_forum\local\exporters\forum as forum_exporter; * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_exporters_forum_testcase extends advanced_testcase { +class exporters_forum_test extends \advanced_testcase { /** * Test the export function returns expected values. */ @@ -51,9 +43,9 @@ class mod_forum_exporters_forum_testcase extends advanced_testcase { 'groupmode' => VISIBLEGROUPS ]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); $entityfactory = \mod_forum\local\container::get_entity_factory(); - $forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); + $forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); $exporter = new forum_exporter($forum, [ 'legacydatamapperfactory' => \mod_forum\local\container::get_legacy_data_mapper_factory(), diff --git a/mod/forum/tests/exporters_post_test.php b/mod/forum/tests/exporters_post_test.php index c182e6ce4d2..ef2c33a51cd 100644 --- a/mod/forum/tests/exporters_post_test.php +++ b/mod/forum/tests/exporters_post_test.php @@ -22,12 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; -use \mod_forum\local\entities\discussion as discussion_entity; -use \mod_forum\local\entities\post as post_entity; -use \mod_forum\local\exporters\post as post_exporter; -use \mod_forum\local\managers\capability as capability_manager; +use mod_forum\local\entities\discussion as discussion_entity; +use mod_forum\local\entities\post as post_entity; +use mod_forum\local\exporters\post as post_exporter; +use mod_forum\local\managers\capability as capability_manager; +use mod_forum_tests_generator_trait; + +defined('MOODLE_INTERNAL') || die(); global $CFG; require_once(__DIR__ . '/generator_trait.php'); @@ -40,7 +43,7 @@ require_once($CFG->dirroot . '/rating/lib.php'); * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_exporters_post_testcase extends advanced_testcase { +class exporters_post_test extends \advanced_testcase { // Make use of the test generator trait. use mod_forum_tests_generator_trait; @@ -64,7 +67,7 @@ class mod_forum_exporters_post_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); $now = time(); $forumgenparams = [ @@ -128,11 +131,11 @@ class mod_forum_exporters_post_testcase extends advanced_testcase { ); $managerfactory = \mod_forum\local\container::get_manager_factory(); $entityfactory = \mod_forum\local\container::get_entity_factory(); - $forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); - $discussion = $entityfactory->get_discussion_from_stdclass($discussion); - $post = $entityfactory->get_post_from_stdclass($post); - $author = $entityfactory->get_author_from_stdclass($user); - $authorcontext = context_user::instance($author->get_id()); + $forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); + $discussion = $entityfactory->get_discussion_from_stdClass($discussion); + $post = $entityfactory->get_post_from_stdClass($post); + $author = $entityfactory->get_author_from_stdClass($user); + $authorcontext = \context_user::instance($author->get_id()); $exporter = new post_exporter($post, [ 'legacydatamapperfactory' => \mod_forum\local\container::get_legacy_data_mapper_factory(), @@ -229,7 +232,7 @@ class mod_forum_exporters_post_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); $discussion = $forumgenerator->create_discussion((object) [ 'course' => $forum->course, 'userid' => $user->id, @@ -283,11 +286,11 @@ class mod_forum_exporters_post_testcase extends advanced_testcase { ); $managerfactory = \mod_forum\local\container::get_manager_factory(); $entityfactory = \mod_forum\local\container::get_entity_factory(); - $forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); - $discussion = $entityfactory->get_discussion_from_stdclass($discussion); - $post = $entityfactory->get_post_from_stdclass($post); - $author = $entityfactory->get_author_from_stdclass($user); - $authorcontext = context_user::instance($author->get_id()); + $forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); + $discussion = $entityfactory->get_discussion_from_stdClass($discussion); + $post = $entityfactory->get_post_from_stdClass($post); + $author = $entityfactory->get_author_from_stdClass($user); + $authorcontext = \context_user::instance($author->get_id()); $exporter = new post_exporter($post, [ 'legacydatamapperfactory' => \mod_forum\local\container::get_legacy_data_mapper_factory(), @@ -337,7 +340,7 @@ class mod_forum_exporters_post_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); $discussion = $forumgenerator->create_discussion((object) [ 'course' => $forum->course, 'userid' => $user->id, @@ -391,11 +394,11 @@ class mod_forum_exporters_post_testcase extends advanced_testcase { ); $managerfactory = \mod_forum\local\container::get_manager_factory(); $entityfactory = \mod_forum\local\container::get_entity_factory(); - $forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); - $discussion = $entityfactory->get_discussion_from_stdclass($discussion); - $post = $entityfactory->get_post_from_stdclass($post); - $author = $entityfactory->get_author_from_stdclass($user); - $authorcontext = context_user::instance($author->get_id()); + $forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); + $discussion = $entityfactory->get_discussion_from_stdClass($discussion); + $post = $entityfactory->get_post_from_stdClass($post); + $author = $entityfactory->get_author_from_stdClass($user); + $authorcontext = \context_user::instance($author->get_id()); $exporter = new post_exporter($post, [ 'legacydatamapperfactory' => \mod_forum\local\container::get_legacy_data_mapper_factory(), @@ -492,37 +495,37 @@ class test_capability_manager extends capability_manager { /** * Override can_view_post * - * @param stdClass $user The user + * @param \stdClass $user The user * @param discussion_entity $discussion The discussion * @param post_entity $post The post * @return bool */ - public function can_view_post(stdClass $user, discussion_entity $discussion, post_entity $post) : bool { + public function can_view_post(\stdClass $user, discussion_entity $discussion, post_entity $post) : bool { return $this->view; } /** * Override can_edit_post * - * @param stdClass $user The user + * @param \stdClass $user The user * @param discussion_entity $discussion The discussion * @param post_entity $post The post * @return bool */ - public function can_edit_post(stdClass $user, discussion_entity $discussion, post_entity $post) : bool { + public function can_edit_post(\stdClass $user, discussion_entity $discussion, post_entity $post) : bool { return $this->edit; } /** * Override can_delete_post * - * @param stdClass $user The user + * @param \stdClass $user The user * @param discussion_entity $discussion The discussion * @param post_entity $post The post * @param bool $hasreplies * @return bool */ - public function can_delete_post(stdClass $user, discussion_entity $discussion, post_entity $post, + public function can_delete_post(\stdClass $user, discussion_entity $discussion, post_entity $post, bool $hasreplies = false) : bool { return $this->delete; } @@ -530,64 +533,64 @@ class test_capability_manager extends capability_manager { /** * Override can_split_post * - * @param stdClass $user The user + * @param \stdClass $user The user * @param discussion_entity $discussion The discussion * @param post_entity $post The post * @return bool */ - public function can_split_post(stdClass $user, discussion_entity $discussion, post_entity $post) : bool { + public function can_split_post(\stdClass $user, discussion_entity $discussion, post_entity $post) : bool { return $this->split; } /** * Override can_reply_to_post * - * @param stdClass $user The user + * @param \stdClass $user The user * @param discussion_entity $discussion The discussion * @param post_entity $post The post * @return bool */ - public function can_reply_to_post(stdClass $user, discussion_entity $discussion, post_entity $post) : bool { + public function can_reply_to_post(\stdClass $user, discussion_entity $discussion, post_entity $post) : bool { return $this->reply; } /** * Override can_export_post * - * @param stdClass $user The user + * @param \stdClass $user The user * @param post_entity $post The post * @return bool */ - public function can_export_post(stdClass $user, post_entity $post) : bool { + public function can_export_post(\stdClass $user, post_entity $post) : bool { return $this->export; } /** * Override can_manually_control_post_read_status * - * @param stdClass $user The user + * @param \stdClass $user The user * @return bool */ - public function can_manually_control_post_read_status(stdClass $user) : bool { + public function can_manually_control_post_read_status(\stdClass $user) : bool { return $this->controlreadstatus; } /** * Override can_reply_privately_to_post - * @param stdClass $user + * @param \stdClass $user * @param post_entity $post * @return bool */ - public function can_reply_privately_to_post(stdClass $user, post_entity $post) : bool { + public function can_reply_privately_to_post(\stdClass $user, post_entity $post) : bool { return $this->canreplyprivatelytopost; } /** * Override can_self_enrol - * @param stdClass $user + * @param \stdClass $user * @return bool */ - public function can_self_enrol(stdClass $user) : bool { + public function can_self_enrol(\stdClass $user) : bool { return $this->canenrol; } } diff --git a/mod/forum/tests/local_container_test.php b/mod/forum/tests/local_container_test.php index 07e90a6c4db..24032076057 100644 --- a/mod/forum/tests/local_container_test.php +++ b/mod/forum/tests/local_container_test.php @@ -14,24 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_forum; + /** * Tests for the local\container class. * * @package mod_forum * @copyright 2019 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Tests for the local\container class. - * - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @coversDefaultClass \mod_forum\local\container */ -class mod_forum_local_container_testcase extends advanced_testcase { +class local_container_test extends \advanced_testcase { /** * Ensure that a renderer factory is returned. * diff --git a/mod/forum/tests/mail_group_test.php b/mod/forum/tests/mail_group_test.php index f7e24390d59..e32dd2ea672 100644 --- a/mod/forum/tests/mail_group_test.php +++ b/mod/forum/tests/mail_group_test.php @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The forum module mail generation tests for groups. - * - * @package mod_forum - * @copyright 2013 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_forum; + +use mod_forum_tests_cron_trait; +use mod_forum_tests_generator_trait; defined('MOODLE_INTERNAL') || die(); @@ -35,7 +32,7 @@ require_once(__DIR__ . '/generator_trait.php'); * @copyright 2013 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_mail_group_testcase extends advanced_testcase { +class mail_group_test extends \advanced_testcase { // Make use of the cron tester trait. use mod_forum_tests_cron_trait; diff --git a/mod/forum/tests/mail_test.php b/mod/forum/tests/mail_test.php index 4a60c7646d1..0a4db889641 100644 --- a/mod/forum/tests/mail_test.php +++ b/mod/forum/tests/mail_test.php @@ -14,14 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The forum module mail generation tests. - * - * @package mod_forum - * @category external - * @copyright 2013 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_forum; + +use mod_forum_tests_generator_trait; +use mod_forum_tests_cron_trait; defined('MOODLE_INTERNAL') || die(); @@ -30,7 +26,16 @@ require_once($CFG->dirroot . '/mod/forum/lib.php'); require_once(__DIR__ . '/cron_trait.php'); require_once(__DIR__ . '/generator_trait.php'); -class mod_forum_mail_testcase extends advanced_testcase { +/** + * The forum module mail generation tests. + * + * @package mod_forum + * @category test + * @copyright 2013 Andrew Nicols + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ +class mail_test extends \advanced_testcase { // Make use of the cron tester trait. use mod_forum_tests_cron_trait; @@ -240,7 +245,7 @@ class mod_forum_mail_testcase extends advanced_testcase { // A user with the manageactivities capability within the course can subscribe. $roleids = $DB->get_records_menu('role', null, '', 'shortname, id'); - assign_capability('moodle/course:manageactivities', CAP_ALLOW, $roleids['student'], context_course::instance($course->id)); + assign_capability('moodle/course:manageactivities', CAP_ALLOW, $roleids['student'], \context_course::instance($course->id)); // Suscribe the recipient only. \mod_forum\subscriptions::subscribe_user($recipient->id, $forum); @@ -289,7 +294,7 @@ class mod_forum_mail_testcase extends advanced_testcase { // A user with the manageactivities capability within the course can subscribe. $roleids = $DB->get_records_menu('role', null, '', 'shortname, id'); - assign_capability('moodle/course:manageactivities', CAP_ALLOW, $roleids['student'], context_course::instance($course->id)); + assign_capability('moodle/course:manageactivities', CAP_ALLOW, $roleids['student'], \context_course::instance($course->id)); // Run cron and check that the expected number of users received the notification. list($discussion, $post) = $this->helper_post_to_forum($forum, $author); @@ -1187,7 +1192,7 @@ class mod_forum_mail_testcase extends advanced_testcase { $fs = get_file_storage(); foreach ($attachments as $attachment) { $filerecord = array( - 'contextid' => context_module::instance($forum->cmid)->id, + 'contextid' => \context_module::instance($forum->cmid)->id, 'component' => 'mod_forum', 'filearea' => 'attachment', 'itemid' => $post->id, diff --git a/mod/forum/tests/maildigest_test.php b/mod/forum/tests/maildigest_test.php index e0cecbe3863..191422d1f9b 100644 --- a/mod/forum/tests/maildigest_test.php +++ b/mod/forum/tests/maildigest_test.php @@ -15,21 +15,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The module forums external functions unit tests - * - * @package mod_forum - * @category external - * @copyright 2013 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_forum; -defined('MOODLE_INTERNAL') || die(); +use mod_forum_tests_cron_trait; +use mod_forum_tests_generator_trait; + +defined('MOODLE_INTERNAL') || die; require_once(__DIR__ . '/cron_trait.php'); require_once(__DIR__ . '/generator_trait.php'); -class mod_forum_maildigest_testcase extends advanced_testcase { +/** + * The module forums external functions unit tests + * + * @package mod_forum + * @category test + * @copyright 2013 Andrew Nicols + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class maildigest_test extends \advanced_testcase { // Make use of the cron tester trait. use mod_forum_tests_cron_trait; @@ -95,9 +99,9 @@ class mod_forum_maildigest_testcase extends advanced_testcase { protected function helper_setup_user_in_course() { global $DB; - $return = new stdClass(); - $return->courses = new stdClass(); - $return->forums = new stdClass(); + $return = new \stdClass(); + $return->courses = new \stdClass(); + $return->forums = new \stdClass(); $return->forumids = array(); // Create a user. @@ -108,7 +112,7 @@ class mod_forum_maildigest_testcase extends advanced_testcase { $return->courses->course1 = $this->getDataGenerator()->create_course(); // Create forums. - $record = new stdClass(); + $record = new \stdClass(); $record->course = $return->courses->course1->id; $record->forcesubscribe = 1; diff --git a/mod/forum/tests/managers_capability_test.php b/mod/forum/tests/managers_capability_test.php index d3a26c7ab4b..fb5e5979f29 100644 --- a/mod/forum/tests/managers_capability_test.php +++ b/mod/forum/tests/managers_capability_test.php @@ -14,22 +14,18 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The capability manager tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_forum; + +use mod_forum\local\container; +use mod_forum\local\entities\forum; +use mod_forum\local\managers\capability as capability_manager; +use mod_forum_tests_generator_trait; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once(__DIR__ . '/generator_trait.php'); -use mod_forum\local\entities\forum; -use mod_forum\local\managers\capability as capability_manager; - /** * The capability manager tests. * @@ -38,7 +34,7 @@ use mod_forum\local\managers\capability as capability_manager; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @coversDefaultClass \mod_forum\local\managers\capability */ -class mod_forum_managers_capability_testcase extends advanced_testcase { +class managers_capability_test extends \advanced_testcase { // Make use of the test generator trait. use mod_forum_tests_generator_trait; @@ -90,19 +86,19 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $datagenerator = $this->getDataGenerator(); $this->user = $datagenerator->create_user(); - $this->managerfactory = \mod_forum\local\container::get_manager_factory(); - $this->entityfactory = \mod_forum\local\container::get_entity_factory(); + $this->managerfactory = container::get_manager_factory(); + $this->entityfactory = container::get_entity_factory(); $this->course = $datagenerator->create_course(); $this->forumrecord = $datagenerator->create_module('forum', ['course' => $this->course->id]); $this->coursemodule = get_coursemodule_from_instance('forum', $this->forumrecord->id); - $this->context = context_module::instance($this->coursemodule->id); + $this->context = \context_module::instance($this->coursemodule->id); $this->roleid = $DB->get_field('role', 'id', ['shortname' => 'teacher'], MUST_EXIST); $datagenerator->enrol_user($this->user->id, $this->course->id, 'teacher'); [$discussion, $post] = $this->helper_post_to_forum($this->forumrecord, $this->user, ['timemodified' => time() - 100]); - $this->discussion = $this->entityfactory->get_discussion_from_stdclass($discussion); + $this->discussion = $this->entityfactory->get_discussion_from_stdClass($discussion); $this->discussionrecord = $discussion; - $this->post = $this->entityfactory->get_post_from_stdclass( + $this->post = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $post, ['timecreated' => time() - 100]) ); $this->postrecord = $post; @@ -127,7 +123,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { */ private function create_forum(array $forumproperties = []) { $forumrecord = (object) array_merge((array) $this->forumrecord, $forumproperties); - return $this->entityfactory->get_forum_from_stdclass( + return $this->entityfactory->get_forum_from_stdClass( $forumrecord, $this->context, $this->coursemodule, @@ -218,8 +214,8 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { ['course' => $this->course->id, 'groupmode' => SEPARATEGROUPS] ); $coursemodule = get_coursemodule_from_instance('forum', $forumrecord->id); - $context = context_module::instance($coursemodule->id); - $forum = $this->entityfactory->get_forum_from_stdclass( + $context = \context_module::instance($coursemodule->id); + $forum = $this->entityfactory->get_forum_from_stdClass( $forumrecord, $context, $coursemodule, @@ -421,7 +417,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $forum = $this->create_forum(); $user = $this->user; $capabilitymanager = $this->managerfactory->get_capability_manager($forum); - $cache = cache::make('mod_forum', 'forum_is_tracked'); + $cache = \cache::make('mod_forum', 'forum_is_tracked'); $user->trackforums = true; $prefid = $DB->insert_record('forum_track_prefs', ['userid' => $user->id, 'forumid' => $forum->get_id()]); @@ -577,8 +573,8 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { ['course' => $this->course->id, 'groupmode' => SEPARATEGROUPS] ); $coursemodule = get_coursemodule_from_instance('forum', $forumrecord->id); - $context = context_module::instance($coursemodule->id); - $forum = $this->entityfactory->get_forum_from_stdclass( + $context = \context_module::instance($coursemodule->id); + $forum = $this->entityfactory->get_forum_from_stdClass( $forumrecord, $context, $coursemodule, @@ -593,7 +589,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $this->assertFalse($capabilitymanager->can_post_in_discussion($user, $discussion)); $group = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]); - $discussion = $this->entityfactory->get_discussion_from_stdclass( + $discussion = $this->entityfactory->get_discussion_from_stdClass( (object) array_merge((array) $this->discussionrecord, ['groupid' => $group->id]) ); @@ -609,8 +605,8 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { ['course' => $this->course->id, 'groupmode' => VISIBLEGROUPS] ); $coursemodule = get_coursemodule_from_instance('forum', $forumrecord->id); - $context = context_module::instance($coursemodule->id); - $forum = $this->entityfactory->get_forum_from_stdclass( + $context = \context_module::instance($coursemodule->id); + $forum = $this->entityfactory->get_forum_from_stdClass( $forumrecord, $context, $coursemodule, @@ -625,7 +621,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $this->assertTrue($capabilitymanager->can_post_in_discussion($user, $discussion)); $group = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]); - $discussion = $this->entityfactory->get_discussion_from_stdclass( + $discussion = $this->entityfactory->get_discussion_from_stdClass( (object) array_merge((array) $this->discussionrecord, ['groupid' => $group->id]) ); @@ -689,7 +685,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $forum = $this->create_forum(['type' => 'news']); $capabilitymanager = $this->managerfactory->get_capability_manager($forum); // Discussion hasn't started yet. - $discussion = $this->entityfactory->get_discussion_from_stdclass( + $discussion = $this->entityfactory->get_discussion_from_stdClass( (object) array_merge((array) $this->discussionrecord, ['timestart' => time() + 100]) ); @@ -698,7 +694,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { // Back to a discussion that has started. $discussion = $this->discussion; // Post is a reply. - $post = $this->entityfactory->get_post_from_stdclass( + $post = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['parent' => 5]) ); @@ -714,7 +710,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { // Create a new post that definitely isn't the first post of the discussion. // Only the author, and a user with editanypost can edit it. - $post = $this->entityfactory->get_post_from_stdclass( + $post = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['id' => $post->get_id() + 100]) ); $this->give_capability('mod/forum:editanypost'); @@ -723,7 +719,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $post = $this->post; // Set the first post of the discussion to our post. - $discussion = $this->entityfactory->get_discussion_from_stdclass( + $discussion = $this->entityfactory->get_discussion_from_stdClass( (object) array_merge((array) $this->discussionrecord, ['firstpost' => $post->get_id()]) ); @@ -752,7 +748,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); // Set the first post of the discussion to our post. - $discussion = $this->entityfactory->get_discussion_from_stdclass( + $discussion = $this->entityfactory->get_discussion_from_stdClass( (object) array_merge((array) $this->discussionrecord, ['firstpost' => $post->get_id()]) ); @@ -760,7 +756,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $this->assertFalse($capabilitymanager->can_delete_post($user, $discussion, $post)); // Set the first post of the discussion to something else. - $discussion = $this->entityfactory->get_discussion_from_stdclass( + $discussion = $this->entityfactory->get_discussion_from_stdClass( (object) array_merge((array) $this->discussionrecord, ['firstpost' => $post->get_id() - 1]) ); @@ -774,7 +770,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $CFG->maxeditingtime = 200; // Make the post owned by someone else. - $post = $this->entityfactory->get_post_from_stdclass( + $post = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['userid' => $user->id - 1]) ); @@ -815,7 +811,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); // Make the post a reply. - $post = $this->entityfactory->get_post_from_stdclass( + $post = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['parent' => 5]) ); @@ -826,7 +822,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $this->assertTrue($capabilitymanager->can_split_post($user, $discussion, $post)); // Make the post have no parent. - $post = $this->entityfactory->get_post_from_stdclass( + $post = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['parent' => 0]) ); @@ -835,7 +831,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $forum = $this->create_forum(['type' => 'single']); $capabilitymanager = $this->managerfactory->get_capability_manager($forum); // Make the post a reply. - $post = $this->entityfactory->get_post_from_stdclass( + $post = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['parent' => 5]) ); @@ -843,7 +839,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $this->assertFalse($capabilitymanager->can_split_post($user, $discussion, $post)); // Make the post a private reply. - $post = $this->entityfactory->get_post_from_stdclass( + $post = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['parent' => 5, 'privatereplyto' => $user->id]) ); @@ -899,8 +895,8 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { ['course' => $this->course->id, 'groupmode' => SEPARATEGROUPS] ); $coursemodule = get_coursemodule_from_instance('forum', $forumrecord->id); - $context = context_module::instance($coursemodule->id); - $forum = $this->entityfactory->get_forum_from_stdclass( + $context = \context_module::instance($coursemodule->id); + $forum = $this->entityfactory->get_forum_from_stdClass( $forumrecord, $context, $coursemodule, @@ -915,7 +911,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $this->assertFalse($capabilitymanager->can_reply_to_post($user, $discussion, $post)); $group = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]); - $discussion = $this->entityfactory->get_discussion_from_stdclass( + $discussion = $this->entityfactory->get_discussion_from_stdClass( (object) array_merge((array) $this->discussionrecord, ['groupid' => $group->id]) ); @@ -931,8 +927,8 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { ['course' => $this->course->id, 'groupmode' => VISIBLEGROUPS] ); $coursemodule = get_coursemodule_from_instance('forum', $forumrecord->id); - $context = context_module::instance($coursemodule->id); - $forum = $this->entityfactory->get_forum_from_stdclass( + $context = \context_module::instance($coursemodule->id); + $forum = $this->entityfactory->get_forum_from_stdClass( $forumrecord, $context, $coursemodule, @@ -947,7 +943,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $this->assertTrue($capabilitymanager->can_reply_to_post($user, $discussion, $post)); $group = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]); - $discussion = $this->entityfactory->get_discussion_from_stdclass( + $discussion = $this->entityfactory->get_discussion_from_stdClass( (object) array_merge((array) $this->discussionrecord, ['groupid' => $group->id]) ); @@ -958,7 +954,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $this->assertTrue($capabilitymanager->can_reply_to_post($user, $discussion, $post)); // Make the post a private reply. - $post = $this->entityfactory->get_post_from_stdclass( + $post = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['parent' => 5, 'privatereplyto' => $user->id]) ); @@ -997,7 +993,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $now = time(); $options = ['parent' => $this->post->get_id(), 'created' => $now - 100]; $student1post = $this->helper_post_to_discussion($this->forumrecord, $this->discussionrecord, $student1, $options); - $student1postentity = $this->entityfactory->get_post_from_stdclass($student1post); + $student1postentity = $this->entityfactory->get_post_from_stdClass($student1post); // Confirm Student 2 cannot reply student 1's answer yet. $this->assertFalse($capabilitymanager->can_reply_to_post($student2, $this->discussion, $student1postentity)); @@ -1035,7 +1031,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $this->assertTrue($capabilitymanager->can_reply_privately_to_post($this->user, $post)); // Make the post a private reply. - $post = $this->entityfactory->get_post_from_stdclass( + $post = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['parent' => 5, 'privatereplyto' => $user->id]) ); @@ -1060,7 +1056,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $discussion = $this->discussion; $post = $this->post; - $privatepost = $this->entityfactory->get_post_from_stdclass( + $privatepost = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['parent' => $post->get_id(), 'privatereplyto' => $otheruser->id]) ); @@ -1084,10 +1080,10 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $discussion = $this->discussion; $post = $this->post; - $privatepost = $this->entityfactory->get_post_from_stdclass( + $privatepost = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['parent' => $post->get_id(), 'privatereplyto' => $otheruser->id]) ); - $privateposttome = $this->entityfactory->get_post_from_stdclass( + $privateposttome = $this->entityfactory->get_post_from_stdClass( (object) array_merge((array) $this->postrecord, ['parent' => $post->get_id(), 'privatereplyto' => $user->id]) ); @@ -1232,7 +1228,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $forum = $this->create_forum(); $user = $this->user; $capabilitymanager = $this->managerfactory->get_capability_manager($forum); - $context = context_system::instance(); + $context = \context_system::instance(); $roleid = $DB->get_field('role', 'id', ['shortname' => 'user'], MUST_EXIST); assign_capability('moodle/tag:manage', CAP_PREVENT, $roleid, $context->id, true); @@ -1275,7 +1271,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { self::getDataGenerator()->enrol_user($user->id, $course->id, $role->id); // Add a discussion. - $record = new stdClass(); + $record = new \stdClass(); $record->course = $course->id; $record->userid = $user->id; $record->forum = $forum->id; @@ -1287,7 +1283,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $post->totalscore = 80; $DB->update_record('forum_posts', $post); - $vaultfactory = mod_forum\local\container::get_vault_factory(); + $vaultfactory = container::get_vault_factory(); $forumvault = $vaultfactory->get_forum_vault(); $discussionvault = $vaultfactory->get_discussion_vault(); $postvault = $vaultfactory->get_post_vault(); @@ -1317,7 +1313,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { self::getDataGenerator()->enrol_user($user->id, $course->id, $role->id); // Add a discussion. - $record = new stdClass(); + $record = new \stdClass(); $record->course = $course->id; $record->userid = $user->id; $record->forum = $forum->id; @@ -1326,7 +1322,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $parentpost = $DB->get_record('forum_posts', array('discussion' => $discussion->id)); // Add a post. - $record = new stdClass(); + $record = new \stdClass(); $record->course = $course->id; $record->userid = $user->id; $record->forum = $forum->id; @@ -1334,7 +1330,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase { $record->parent = $parentpost->id; $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record); - $vaultfactory = mod_forum\local\container::get_vault_factory(); + $vaultfactory = container::get_vault_factory(); $forumvault = $vaultfactory->get_forum_vault(); $discussionvault = $vaultfactory->get_discussion_vault(); $postvault = $vaultfactory->get_post_vault(); diff --git a/mod/forum/tests/output_email_test.php b/mod/forum/tests/output_email_test.php index a13e09f9957..1169e2e032c 100644 --- a/mod/forum/tests/output_email_test.php +++ b/mod/forum/tests/output_email_test.php @@ -14,23 +14,18 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace mod_forum; + +use mod_forum\output\forum_post_email; + /** - * The module forums tests + * Tests for the forum output/email class. * * @package mod_forum * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Tests for the forum output/email class. - * - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class mod_forum_output_email_testcase extends advanced_testcase { +class output_email_test extends \advanced_testcase { /** * Data provider for the postdate function tests. */ @@ -174,7 +169,7 @@ class mod_forum_output_email_testcase extends advanced_testcase { $DB->update_record('forum_posts', $post); // Create the renderable. - $renderable = new mod_forum\output\forum_post_email( + $renderable = new forum_post_email( $course, $cm, $forum, diff --git a/mod/forum/tests/private_replies_test.php b/mod/forum/tests/private_replies_test.php index f22cc7e34ec..a09b788cc1a 100644 --- a/mod/forum/tests/private_replies_test.php +++ b/mod/forum/tests/private_replies_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests for private reply functionality. - * - * @package mod_forum - * @copyright 2019 Andrew Nicols - * @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(); @@ -32,10 +28,11 @@ require_once(__DIR__ . '/generator_trait.php'); /** * Tests for private reply functionality. * + * @package mod_forum * @copyright 2019 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class private_replies extends advanced_testcase { +class private_replies_test extends \advanced_testcase { use mod_forum_tests_generator_trait; diff --git a/mod/forum/tests/qanda_test.php b/mod/forum/tests/qanda_test.php index 2710d1bc3c7..16d85805ed3 100644 --- a/mod/forum/tests/qanda_test.php +++ b/mod/forum/tests/qanda_test.php @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The forum module mail generation tests for groups. - * - * @package mod_forum - * @copyright 2013 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_forum; + +use mod_forum_tests_cron_trait; +use mod_forum_tests_generator_trait; defined('MOODLE_INTERNAL') || die(); @@ -32,10 +29,11 @@ require_once(__DIR__ . '/generator_trait.php'); /** * The forum module mail generation tests for groups. * + * @package mod_forum * @copyright 2013 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_qanda_testcase extends advanced_testcase { +class qanda_test extends \advanced_testcase { // Make use of the cron tester trait. use mod_forum_tests_cron_trait; diff --git a/mod/forum/tests/subscriptions_test.php b/mod/forum/tests/subscriptions_test.php index ba0d8a54e2a..1194b60b92b 100644 --- a/mod/forum/tests/subscriptions_test.php +++ b/mod/forum/tests/subscriptions_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The module forums tests - * - * @package mod_forum - * @copyright 2013 Frédéric Massart - * @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(); @@ -28,7 +24,14 @@ global $CFG; require_once(__DIR__ . '/generator_trait.php'); require_once("{$CFG->dirroot}/mod/forum/lib.php"); -class mod_forum_subscriptions_testcase extends advanced_testcase { +/** + * The module forums tests + * + * @package mod_forum + * @copyright 2013 Frédéric Massart + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class subscriptions_test extends \advanced_testcase { // Include the mod_forum test helpers. // This includes functions to create forums, users, discussions, and posts. use mod_forum_tests_generator_trait; @@ -843,7 +846,7 @@ class mod_forum_subscriptions_testcase extends advanced_testcase { $this->assertEquals($usercount, count($subscribers)); // Manually insert an extra subscription for one of the users. - $record = new stdClass(); + $record = new \stdClass(); $record->userid = $users[2]->id; $record->forum = $forum->id; $record->discussion = $discussion->id; diff --git a/mod/forum/tests/vaults_author_test.php b/mod/forum/tests/vaults_author_test.php index b35d0ea59c4..a96696e1eaa 100644 --- a/mod/forum/tests/vaults_author_test.php +++ b/mod/forum/tests/vaults_author_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The author vault tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mod_forum; /** * The author vault tests. @@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_vaults_author_testcase extends advanced_testcase { +class vaults_author_test extends \advanced_testcase { /** * Test get_from_id. */ @@ -62,9 +54,9 @@ class mod_forum_vaults_author_testcase extends advanced_testcase { $fakeuserid = $user3->id + 1000; $vaultfactory = \mod_forum\local\container::get_vault_factory(); $authorvault = $vaultfactory->get_author_vault(); - $user1context = context_user::instance($user1->id); - $user2context = context_user::instance($user2->id); - $user3context = context_user::instance($user3->id); + $user1context = \context_user::instance($user1->id); + $user2context = \context_user::instance($user2->id); + $user3context = \context_user::instance($user3->id); $user1contextid = $user1context->id; $user2contextid = $user2context->id; $user3contextid = $user3context->id; diff --git a/mod/forum/tests/vaults_discussion_list_test.php b/mod/forum/tests/vaults_discussion_list_test.php index 68bdabe241a..22b822b18c0 100644 --- a/mod/forum/tests/vaults_discussion_list_test.php +++ b/mod/forum/tests/vaults_discussion_list_test.php @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The discussion_list vault tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace mod_forum; + +use mod_forum_external; +use mod_forum_tests_generator_trait; defined('MOODLE_INTERNAL') || die(); @@ -36,7 +33,7 @@ require_once(__DIR__ . '/generator_trait.php'); * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_vaults_discussion_list_testcase extends advanced_testcase { +class vaults_discussion_list_test extends \advanced_testcase { // Make use of the test generator trait. use mod_forum_tests_generator_trait; @@ -536,9 +533,9 @@ class mod_forum_vaults_discussion_list_testcase extends advanced_testcase { /** * Pin a duscussion. * - * @param stdClass $discussion + * @param \stdClass $discussion */ - private function pin_discussion(stdClass $discussion) { + private function pin_discussion(\stdClass $discussion) { global $DB; $DB->update_record('forum_discussions', @@ -548,10 +545,10 @@ class mod_forum_vaults_discussion_list_testcase extends advanced_testcase { /** * Star a duscussion. * - * @param stdClass $discussion + * @param \stdClass $discussion * @param bool $targetstate The new starred state of the discussion (0 => unstar, 1 => star) */ - private function star_discussion(stdClass $discussion, bool $targetstate) { + private function star_discussion(\stdClass $discussion, bool $targetstate) { mod_forum_external::toggle_favourite_state($discussion->id, $targetstate); } } diff --git a/mod/forum/tests/vaults_discussion_test.php b/mod/forum/tests/vaults_discussion_test.php index 3b27cc9f392..cf982494336 100644 --- a/mod/forum/tests/vaults_discussion_test.php +++ b/mod/forum/tests/vaults_discussion_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The discussion vault tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @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(); @@ -33,7 +29,7 @@ require_once(__DIR__ . '/generator_trait.php'); * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_vaults_discussion_testcase extends advanced_testcase { +class vaults_discussion_test extends \advanced_testcase { // Make use of the test generator trait. use mod_forum_tests_generator_trait; @@ -79,8 +75,8 @@ class mod_forum_vaults_discussion_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); - $forumentity = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); + $context = \context_module::instance($coursemodule->id); + $forumentity = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); $this->assertEquals(null, $vault->get_first_discussion_in_forum($forumentity)); @@ -105,8 +101,8 @@ class mod_forum_vaults_discussion_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); - $forumentity = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course); + $context = \context_module::instance($coursemodule->id); + $forumentity = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course); $this->assertEquals([], $vault->get_all_discussions_in_forum($forumentity)); diff --git a/mod/forum/tests/vaults_forum_test.php b/mod/forum/tests/vaults_forum_test.php index fbf72c77e1a..7141d8607fc 100644 --- a/mod/forum/tests/vaults_forum_test.php +++ b/mod/forum/tests/vaults_forum_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The forum vault tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @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\forum */ -class mod_forum_vaults_forum_testcase extends advanced_testcase { +class vaults_forum_test extends \advanced_testcase { // Make use of the test generator trait. use mod_forum_tests_generator_trait; diff --git a/mod/forum/tests/vaults_post_attachment_test.php b/mod/forum/tests/vaults_post_attachment_test.php index 4746d0abf12..8745485f3d5 100644 --- a/mod/forum/tests/vaults_post_attachment_test.php +++ b/mod/forum/tests/vaults_post_attachment_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The post_attachment vault tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @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(); @@ -33,7 +29,7 @@ require_once(__DIR__ . '/generator_trait.php'); * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_vaults_post_attachment_testcase extends advanced_testcase { +class vaults_post_attachment_test extends \advanced_testcase { // Make use of the test generator trait. use mod_forum_tests_generator_trait; @@ -52,7 +48,7 @@ class mod_forum_vaults_post_attachment_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); [$discussion, $post1] = $this->helper_post_to_forum($forum, $user); $post2 = $this->helper_reply_to_post($post1, $user); $post3 = $this->helper_reply_to_post($post1, $user); @@ -79,11 +75,11 @@ class mod_forum_vaults_post_attachment_testcase extends advanced_testcase { 'image contents' ); - $post1 = $entityfactory->get_post_from_stdclass($post1); - $post2 = $entityfactory->get_post_from_stdclass($post2); - $post3 = $entityfactory->get_post_from_stdclass($post3); + $post1 = $entityfactory->get_post_from_stdClass($post1); + $post2 = $entityfactory->get_post_from_stdClass($post2); + $post3 = $entityfactory->get_post_from_stdClass($post3); - $results = $vault->get_attachments_for_posts(context_system::instance(), [$post1, $post2, $post3]); + $results = $vault->get_attachments_for_posts(\context_system::instance(), [$post1, $post2, $post3]); $this->assertCount(3, $results); $this->assertEquals([], $results[$post1->get_id()]); $this->assertEquals([], $results[$post2->get_id()]); @@ -120,7 +116,7 @@ class mod_forum_vaults_post_attachment_testcase extends advanced_testcase { $course = $datagenerator->create_course(); $forum = $datagenerator->create_module('forum', ['course' => $course->id]); $coursemodule = get_coursemodule_from_instance('forum', $forum->id); - $context = context_module::instance($coursemodule->id); + $context = \context_module::instance($coursemodule->id); [$discussion, $post1] = $this->helper_post_to_forum($forum, $user); $post2 = $this->helper_reply_to_post($post1, $user); $post3 = $this->helper_reply_to_post($post1, $user); @@ -147,11 +143,11 @@ class mod_forum_vaults_post_attachment_testcase extends advanced_testcase { 'image contents' ); - $post1 = $entityfactory->get_post_from_stdclass($post1); - $post2 = $entityfactory->get_post_from_stdclass($post2); - $post3 = $entityfactory->get_post_from_stdclass($post3); + $post1 = $entityfactory->get_post_from_stdClass($post1); + $post2 = $entityfactory->get_post_from_stdClass($post2); + $post3 = $entityfactory->get_post_from_stdClass($post3); - $results = $vault->get_inline_attachments_for_posts(context_system::instance(), [$post1, $post2, $post3]); + $results = $vault->get_inline_attachments_for_posts(\context_system::instance(), [$post1, $post2, $post3]); $this->assertCount(3, $results); $this->assertEquals([], $results[$post1->get_id()]); $this->assertEquals([], $results[$post2->get_id()]); diff --git a/mod/forum/tests/vaults_post_read_receipt_collection_test.php b/mod/forum/tests/vaults_post_read_receipt_collection_test.php index 3768bdb257b..56db40a17b4 100644 --- a/mod/forum/tests/vaults_post_read_receipt_collection_test.php +++ b/mod/forum/tests/vaults_post_read_receipt_collection_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The post read receipt collection vault tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @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(); @@ -33,7 +29,7 @@ require_once(__DIR__ . '/generator_trait.php'); * @copyright 2019 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_forum_vaults_post_read_receipt_collection_testcase extends advanced_testcase { +class vaults_post_read_receipt_collection_test extends \advanced_testcase { // Make use of the test generator trait. use mod_forum_tests_generator_trait; @@ -82,9 +78,9 @@ class mod_forum_vaults_post_read_receipt_collection_testcase extends advanced_te 'lastread' => time() ]); - $post1 = $entityfactory->get_post_from_stdclass($post1); - $post2 = $entityfactory->get_post_from_stdclass($post2); - $post3 = $entityfactory->get_post_from_stdclass($post3); + $post1 = $entityfactory->get_post_from_stdClass($post1); + $post2 = $entityfactory->get_post_from_stdClass($post2); + $post3 = $entityfactory->get_post_from_stdClass($post3); $collection = $vault->get_from_user_id_and_post_ids($user->id, [$post1->get_id(), $post2->get_id()]); // True because there is a read receipt for this user. diff --git a/mod/forum/tests/vaults_post_test.php b/mod/forum/tests/vaults_post_test.php index 0057e6047d3..ab7f7f9abf7 100644 --- a/mod/forum/tests/vaults_post_test.php +++ b/mod/forum/tests/vaults_post_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The post vault tests. - * - * @package mod_forum - * @copyright 2019 Ryan Wyllie - * @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)); }