From 780cf0a728e7f8ab666e75e29e1bf4d757544385 Mon Sep 17 00:00:00 2001 From: Michael Aherne Date: Wed, 18 Dec 2013 10:22:07 +0000 Subject: [PATCH] MDL-43440 unit tests Use correct cm identifier in unit tests --- grade/tests/edittreelib_test.php | 2 +- grade/tests/externallib_test.php | 2 +- lib/tests/messagelib_test.php | 6 +++--- mod/assign/tests/externallib_test.php | 8 ++++---- repository/tests/repositorylib_test.php | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/grade/tests/edittreelib_test.php b/grade/tests/edittreelib_test.php index f3d768c22db39..051c15559da94 100644 --- a/grade/tests/edittreelib_test.php +++ b/grade/tests/edittreelib_test.php @@ -52,7 +52,7 @@ public function test_grade_edit_tree_column_range_get_item_cell() { $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 3230236434dd5..5bc51208b5f20 100644 --- a/grade/tests/externallib_test.php +++ b/grade/tests/externallib_test.php @@ -209,7 +209,7 @@ public function test_get_gradingform_instances() { // 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($assign->id); + $modulecontext = context_module::instance($assign->cmid); $this->assignUserCapability('mod/assign:grade', $modulecontext->id, $roleid); // Create the teacher's enrolment record. diff --git a/lib/tests/messagelib_test.php b/lib/tests/messagelib_test.php index 46c710bf23af7..c279e28c068dd 100644 --- a/lib/tests/messagelib_test.php +++ b/lib/tests/messagelib_test.php @@ -134,7 +134,7 @@ public function test_message_get_providers_for_user_more() { // 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); @@ -162,7 +162,7 @@ public function test_message_get_providers_for_user_more() { // 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); @@ -173,7 +173,7 @@ public function test_message_get_providers_for_user_more() { // 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 5ab2faa7d6c4b..5adc03906a335 100644 --- a/mod/assign/tests/externallib_test.php +++ b/mod/assign/tests/externallib_test.php @@ -66,7 +66,7 @@ public function test_get_grades() { // 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. @@ -332,7 +332,7 @@ public function test_get_user_flags() { // 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. @@ -403,7 +403,7 @@ public function test_get_user_mappings() { // 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:revealidentities', $context->id, $roleid); // Create the teacher's enrolment record. @@ -1072,7 +1072,7 @@ public function test_set_user_flags() { // 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. diff --git a/repository/tests/repositorylib_test.php b/repository/tests/repositorylib_test.php index fefb6bec4aa88..ac161d1a4078b 100644 --- a/repository/tests/repositorylib_test.php +++ b/repository/tests/repositorylib_test.php @@ -246,10 +246,10 @@ public function test_check_capability() { $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;