diff --git a/badges/tests/badgeslib_test.php b/badges/tests/badgeslib_test.php index b70d377f1b0..3f61a8d262b 100644 --- a/badges/tests/badgeslib_test.php +++ b/badges/tests/badgeslib_test.php @@ -233,7 +233,7 @@ class core_badges_badgeslib_testcase extends advanced_testcase { $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id)); $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY)); $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_ACTIVITY, 'badgeid' => $badge->id)); - $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY, 'module_'.$this->module->id => $this->module->id)); + $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY, 'module_'.$this->module->cmid => $this->module->cmid)); // Set completion for forum activity. $c = new completion_info($this->course); diff --git a/files/tests/externallib_test.php b/files/tests/externallib_test.php index 36383fb7aa2..bf34e14b47d 100644 --- a/files/tests/externallib_test.php +++ b/files/tests/externallib_test.php @@ -223,7 +223,7 @@ class core_files_externallib_testcase extends advanced_testcase { // Insert the information about the file. $contentid = $DB->insert_record('data_content', $datacontent); // Required information for uploading a file. - $context = context_module::instance($module->id); + $context = context_module::instance($module->cmid); $usercontext = context_user::instance($USER->id); $component = 'mod_data'; $filearea = 'content'; @@ -301,7 +301,7 @@ class core_files_externallib_testcase extends advanced_testcase { $modified = 0; // Context level and instance ID are used to determine what the context is. $contextlevel = 'module'; - $instanceid = $module->id; + $instanceid = $module->cmid; $testfilelisting = core_files_external::get_files($nocontext, $component, $filearea, $itemid, '/', $filename, $modified, $contextlevel, $instanceid); $this->assertEquals($testfilelisting, $testdata); } diff --git a/grade/tests/edittreelib_test.php b/grade/tests/edittreelib_test.php index 07c59e70a26..35aa429220b 100644 --- a/grade/tests/edittreelib_test.php +++ b/grade/tests/edittreelib_test.php @@ -52,7 +52,7 @@ 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->id); + $modulecontext = context_module::instance($assign->cmid); // The generator returns a dummy object, lets get the real assign object. $assign = new assign($modulecontext, false, false); $cm = $assign->get_course_module(); diff --git a/grade/tests/externallib_test.php b/grade/tests/externallib_test.php index 3230236434d..4c5aeb325ea 100644 --- a/grade/tests/externallib_test.php +++ b/grade/tests/externallib_test.php @@ -66,7 +66,7 @@ class core_grading_externallib_testcase extends externallib_advanced_testcase { // Create a teacher and give them capabilities. $coursecontext = context_course::instance($course->id); $roleid = $this->assignUserCapability('moodle/course:viewparticipants', $coursecontext->id, 3); - $modulecontext = context_module::instance($cm->id); + $modulecontext = context_module::instance($cm->cmid); $this->assignUserCapability('mod/assign:grade', $modulecontext->id, $roleid); // Create the teacher's enrolment record. @@ -146,7 +146,7 @@ class core_grading_externallib_testcase extends externallib_advanced_testcase { $DB->insert_record('gradingform_rubric_levels', $rubriclevel2); // Call the external function. - $cmids = array ($cm->id); + $cmids = array ($cm->cmid); $areaname = 'submissions'; $result = core_grading_external::get_definitions($cmids, $areaname); diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index 6a9f8d688fc..ac7cc067474 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -60,7 +60,7 @@ class core_accesslib_testcase extends advanced_testcase { $this->assertNotEmpty($ACCESSLIB_PRIVATE->rolepermissions); $this->assertNotEmpty($ACCESSLIB_PRIVATE->rolepermissions); $this->assertNotEmpty($ACCESSLIB_PRIVATE->accessdatabyuser); - accesslib_clear_all_caches(true); + accesslib_clear_all_caches_for_unit_testing(); $this->assertEmpty($ACCESSLIB_PRIVATE->rolepermissions); $this->assertEmpty($ACCESSLIB_PRIVATE->rolepermissions); $this->assertEmpty($ACCESSLIB_PRIVATE->dirtycontexts); @@ -2095,7 +2095,7 @@ class core_accesslib_testcase extends advanced_testcase { unassign_capability('moodle/site:accessallgroups', $allroles['teacher'], $frontpagecontext->id, true); unset($rc); - accesslib_clear_all_caches(false); // Must be done after assign_capability(). + accesslib_clear_all_caches_for_unit_testing(); // Must be done after assign_capability(). // Test role_assign(), role_unassign(), role_unassign_all() functions. @@ -2112,7 +2112,7 @@ class core_accesslib_testcase extends advanced_testcase { $this->assertEquals(0, $DB->count_records('role_assignments', array('contextid'=>$context->id))); unset($context); - accesslib_clear_all_caches(false); // Just in case. + accesslib_clear_all_caches_for_unit_testing(); // Just in case. // Test has_capability(), get_users_by_capability(), role_switch(), reload_all_capabilities() and friends functions. @@ -2173,7 +2173,7 @@ class core_accesslib_testcase extends advanced_testcase { assign_capability('mod/page:view', CAP_PREVENT, $allroles['guest'], $systemcontext, true); - accesslib_clear_all_caches(false); // Must be done after assign_capability(). + accesslib_clear_all_caches_for_unit_testing(); /// Must be done after assign_capability(). // Extra tests for guests and not-logged-in users because they can not be verified by cross checking // with get_users_by_capability() where they are ignored. @@ -2296,7 +2296,7 @@ class core_accesslib_testcase extends advanced_testcase { unset($permissions); unset($roles); - accesslib_clear_all_caches(false); // Must be done after assign_capability(). + accesslib_clear_all_caches_for_unit_testing(); // must be done after assign_capability(). // Test time - let's set up some real user, just in case the logic for USER affects the others... $USER = $DB->get_record('user', array('id'=>$testusers[3])); diff --git a/lib/tests/completionlib_test.php b/lib/tests/completionlib_test.php index 63d67d67ca8..23d7770bc2d 100644 --- a/lib/tests/completionlib_test.php +++ b/lib/tests/completionlib_test.php @@ -812,7 +812,7 @@ class core_completionlib_testcase extends advanced_testcase { $this->assertInstanceOf('\core\event\course_module_completion_updated', $event); $this->assertEquals($forum->cmid, $event->get_record_snapshot('course_modules_completion', $event->objectid)->coursemoduleid); $this->assertEquals($current, $event->get_record_snapshot('course_modules_completion', $event->objectid)); - $this->assertEquals(context_module::instance($forum->id), $event->get_context()); + $this->assertEquals(context_module::instance($forum->cmid), $event->get_context()); $this->assertEquals($USER->id, $event->userid); $this->assertEquals($this->user->id, $event->other['relateduserid']); $this->assertInstanceOf('moodle_url', $event->get_url()); diff --git a/lib/tests/messagelib_test.php b/lib/tests/messagelib_test.php index 4f95515dd44..5d45c1a3f89 100644 --- a/lib/tests/messagelib_test.php +++ b/lib/tests/messagelib_test.php @@ -93,7 +93,7 @@ class core_messagelib_testcase extends advanced_testcase { // however mod_quiz doesn't have a data generator. // Instead we're going to use backup notifications and give and take away the capability at various levels. $assign = $this->getDataGenerator()->create_module('assign', array('course'=>$course->id)); - $modulecontext = context_module::instance($assign->id); + $modulecontext = context_module::instance($assign->cmid); // Create and enrol a teacher. $teacherrole = $DB->get_record('role', array('shortname'=>'editingteacher'), '*', MUST_EXIST); @@ -121,7 +121,7 @@ class core_messagelib_testcase extends advanced_testcase { // They should now be able to see the backup message. assign_capability('moodle/site:config', CAP_ALLOW, $teacherrole->id, $modulecontext->id, true); accesslib_clear_all_caches_for_unit_testing(); - $modulecontext = context_module::instance($assign->id); + $modulecontext = context_module::instance($assign->cmid); $this->assertTrue(has_capability('moodle/site:config', $modulecontext)); $providers = message_get_providers_for_user($teacher->id); @@ -132,7 +132,7 @@ class core_messagelib_testcase extends advanced_testcase { // They should not be able to see the backup message. assign_capability('moodle/site:config', CAP_PROHIBIT, $teacherrole->id, $coursecontext->id, true); accesslib_clear_all_caches_for_unit_testing(); - $modulecontext = context_module::instance($assign->id); + $modulecontext = context_module::instance($assign->cmid); $this->assertFalse(has_capability('moodle/site:config', $modulecontext)); $providers = message_get_providers_for_user($teacher->id); diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php index 5ab2faa7d6c..876b761c710 100644 --- a/mod/assign/tests/externallib_test.php +++ b/mod/assign/tests/externallib_test.php @@ -66,7 +66,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { // Create a teacher and give them capabilities. $context = context_course::instance($course->id); $roleid = $this->assignUserCapability('moodle/course:viewparticipants', $context->id, 3); - $context = context_module::instance($assign->id); + $context = context_module::instance($assign->cmid); $this->assignUserCapability('mod/assign:grade', $context->id, $roleid); // Create the teacher's enrolment record. @@ -163,7 +163,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { // Create the user and give them capabilities. $context = context_course::instance($course1->id); $roleid = $this->assignUserCapability('moodle/course:view', $context->id); - $context = context_module::instance($assign1->id); + $context = context_module::instance($assign1->cmid); $this->assignUserCapability('mod/assign:view', $context->id, $roleid); // Create the user enrolment record. diff --git a/mod/book/tests/events_test.php b/mod/book/tests/events_test.php index d53db31529d..b84c2cff3b1 100644 --- a/mod/book/tests/events_test.php +++ b/mod/book/tests/events_test.php @@ -65,7 +65,7 @@ class mod_book_events_testcase extends advanced_testcase { // Checking that the event contains the expected values. $this->assertInstanceOf('\mod_book\event\chapter_created', $event); - $this->assertEquals(context_module::instance($book->id), $event->get_context()); + $this->assertEquals(context_module::instance($book->cmid), $event->get_context()); $this->assertEquals($chapter->id, $event->objectid); $expected = array($course->id, 'book', 'add chapter', 'view.php?id='.$book->cmid.'&chapterid='.$chapter->id, $chapter->id, $book->cmid); @@ -97,7 +97,7 @@ class mod_book_events_testcase extends advanced_testcase { // Checking that the event contains the expected values. $this->assertInstanceOf('\mod_book\event\chapter_updated', $event); - $this->assertEquals(context_module::instance($book->id), $event->get_context()); + $this->assertEquals(context_module::instance($book->cmid), $event->get_context()); $this->assertEquals($chapter->id, $event->objectid); $expected = array($course->id, 'book', 'update chapter', 'view.php?id='.$book->cmid.'&chapterid='.$chapter->id, $chapter->id, $book->cmid); @@ -131,7 +131,7 @@ class mod_book_events_testcase extends advanced_testcase { // Checking that the event contains the expected values. $this->assertInstanceOf('\mod_book\event\chapter_deleted', $event); - $this->assertEquals(context_module::instance($book->id), $event->get_context()); + $this->assertEquals(context_module::instance($book->cmid), $event->get_context()); $this->assertEquals($chapter->id, $event->objectid); $this->assertEquals($chapter, $event->get_record_snapshot('book_chapters', $chapter->id)); $this->assertEventLegacyLogData(array('1', 2, false), $event); diff --git a/mod/choice/tests/events_test.php b/mod/choice/tests/events_test.php index ef38abb2327..60898d414ae 100644 --- a/mod/choice/tests/events_test.php +++ b/mod/choice/tests/events_test.php @@ -84,7 +84,7 @@ class mod_choice_events_testcase extends advanced_testcase { $this->assertCount(1, $events); $this->assertInstanceOf('\mod_choice\event\answer_submitted', $events[0]); $this->assertEquals($user->id, $events[0]->userid); - $this->assertEquals(context_module::instance($this->choice->id), $events[0]->get_context()); + $this->assertEquals(context_module::instance($this->choice->cmid), $events[0]->get_context()); $this->assertEquals(1, $events[0]->other['choiceid']); $this->assertEquals(3, $events[0]->other['optionid']); $expected = array($this->course->id, "choice", "choose", 'view.php?id=' . $this->cm->id, $this->choice->id, $this->cm->id); @@ -133,7 +133,7 @@ class mod_choice_events_testcase extends advanced_testcase { $this->assertCount(1, $events); $this->assertInstanceOf('\mod_choice\event\answer_updated', $events[0]); $this->assertEquals($user->id, $events[0]->userid); - $this->assertEquals(context_module::instance($this->choice->id), $events[0]->get_context()); + $this->assertEquals(context_module::instance($this->choice->cmid), $events[0]->get_context()); $this->assertEquals(1, $events[0]->other['choiceid']); $this->assertEquals(3, $events[0]->other['optionid']); $expected = array($this->course->id, "choice", "choose again", 'view.php?id=' . $this->cm->id, diff --git a/mod/data/tests/lib_test.php b/mod/data/tests/lib_test.php index 6941825a5e5..4b5b49b9192 100644 --- a/mod/data/tests/lib_test.php +++ b/mod/data/tests/lib_test.php @@ -104,4 +104,4 @@ class data_lib_testcase extends advanced_testcase { // Make sure the function returns true on a successful deletion. $this->assertTrue($result); } -} \ No newline at end of file +} diff --git a/mod/feedback/tests/events_test.php b/mod/feedback/tests/events_test.php index ff5dcbb9ab9..1754a436047 100644 --- a/mod/feedback/tests/events_test.php +++ b/mod/feedback/tests/events_test.php @@ -283,7 +283,7 @@ class mod_feedback_events_testcase extends advanced_testcase { // Test legacy data. $arr = array($this->eventcourse->id, 'feedback', 'submit', 'view.php?id=' . $this->eventcm->id, $this->eventfeedback->id, - $this->eventfeedback->id, $USER->id); + $this->eventcm->id, $USER->id); $this->assertEventLegacyLogData($arr, $event); // Test can_view(). diff --git a/mod/forum/tests/externallib_test.php b/mod/forum/tests/externallib_test.php index 087e8026b38..e78f863bf56 100644 --- a/mod/forum/tests/externallib_test.php +++ b/mod/forum/tests/externallib_test.php @@ -90,7 +90,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase { $enrol->enrol_user($instance2, $user->id); // Assign capabilities to view forums for forum 2. - $cm2 = get_coursemodule_from_id('forum', $forum2->id, 0, false, MUST_EXIST); + $cm2 = get_coursemodule_from_id('forum', $forum2->cmid, 0, false, MUST_EXIST); $context2 = context_module::instance($cm2->id); $newrole = create_role('Role 2', 'role2', 'Role 2 description'); $roleid2 = $this->assignUserCapability('mod/forum:viewdiscussion', $context2->id, $newrole); @@ -256,13 +256,13 @@ class mod_forum_external_testcase extends externallib_advanced_testcase { $enrol->enrol_user($instance2, $user1->id); // Assign capabilities to view discussions for forum 2. - $cm = get_coursemodule_from_id('forum', $forum2->id, 0, false, MUST_EXIST); + $cm = get_coursemodule_from_id('forum', $forum2->cmid, 0, false, MUST_EXIST); $context = context_module::instance($cm->id); $newrole = create_role('Role 2', 'role2', 'Role 2 description'); $this->assignUserCapability('mod/forum:viewdiscussion', $context->id, $newrole); // Assign capabilities to view discussions for forum 3. - $cm = get_coursemodule_from_id('forum', $forum3->id, 0, false, MUST_EXIST); + $cm = get_coursemodule_from_id('forum', $forum3->cmid, 0, false, MUST_EXIST); $context = context_module::instance($cm->id); $this->assignUserCapability('mod/forum:viewdiscussion', $context->id, $newrole); diff --git a/mod/forum/tests/lib_test.php b/mod/forum/tests/lib_test.php index dd724ddab42..5419bf8658d 100644 --- a/mod/forum/tests/lib_test.php +++ b/mod/forum/tests/lib_test.php @@ -36,7 +36,7 @@ class mod_forum_lib_testcase extends advanced_testcase { $this->setUser($user->id); $fakepost = (object) array('id' => 123, 'message' => 'Yay!', 'discussion' => 100); - $cm = get_coursemodule_from_instance('forum', $forum->cmid); + $cm = get_coursemodule_from_instance('forum', $forum->id); $fs = get_file_storage(); $dummy = (object) array( diff --git a/repository/tests/repositorylib_test.php b/repository/tests/repositorylib_test.php index fefb6bec4aa..ac161d1a407 100644 --- a/repository/tests/repositorylib_test.php +++ b/repository/tests/repositorylib_test.php @@ -246,10 +246,10 @@ class core_repositorylib_testcase extends advanced_testcase { $forumdata = new stdClass(); $forumdata->course = $course1->id; $forumc1 = $this->getDataGenerator()->create_module('forum', $forumdata); - $forumc1context = context_module::instance($forumc1->id); + $forumc1context = context_module::instance($forumc1->cmid); $forumdata->course = $course2->id; $forumc2 = $this->getDataGenerator()->create_module('forum', $forumdata); - $forumc2context = context_module::instance($forumc2->id); + $forumc2context = context_module::instance($forumc2->cmid); $blockdata = new stdClass(); $blockdata->parentcontextid = $course1context->id;