diff --git a/backup/util/dbops/tests/backup_dbops_test.php b/backup/util/dbops/tests/backup_dbops_test.php index e57dc7e8d79..219b5304653 100644 --- a/backup/util/dbops/tests/backup_dbops_test.php +++ b/backup/util/dbops/tests/backup_dbops_test.php @@ -47,7 +47,7 @@ class backup_dbops_testcase extends advanced_testcase { $page = $this->getDataGenerator()->create_module('page', array('course'=>$course->id), array('section'=>3)); $coursemodule = $DB->get_record('course_modules', array('id'=>$page->cmid)); - $this->moduleid = $coursemodule->id; + $this->moduleid = $page->cmid; $this->sectionid = $DB->get_field("course_sections", 'id', array("section"=>$coursemodule->section, "course"=>$course->id)); $this->courseid = $coursemodule->course; $this->userid = 2; // admin @@ -180,7 +180,7 @@ class backup_dbops_testcase extends advanced_testcase { $this->assertEquals(backup_controller_dbops::backup_includes_files($bc->get_backupid()), 0); // A MODE_SAMESITE controller - should not include files - $bc = new mock_backup_controller4dbops(backup::TYPE_1COURSE, $this->moduleid, backup::FORMAT_MOODLE, + $bc = new mock_backup_controller4dbops(backup::TYPE_1COURSE, $this->courseid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_SAMESITE, $this->userid); $this->assertEquals(backup_controller_dbops::backup_includes_files($bc->get_backupid()), 0); } diff --git a/backup/util/structure/tests/structure_test.php b/backup/util/structure/tests/structure_test.php index c8870cc38e5..93a51a7c627 100644 --- a/backup/util/structure/tests/structure_test.php +++ b/backup/util/structure/tests/structure_test.php @@ -35,8 +35,22 @@ require_once($CFG->dirroot . '/backup/util/xml/output/memory_xml_output.class.ph */ class backup_structure_testcase extends advanced_testcase { - protected $forumid; // To store the inserted forum->id - protected $contextid; // Official contextid for these tests + /** @var int Store the inserted forum->id for use in test functions */ + protected $forumid; + /** @var int Store the inserted discussion1->id for use in test functions */ + protected $discussionid1; + /** @var int Store the inserted discussion2->id for use in test functions */ + protected $discussionid2; + /** @var int Store the inserted post1->id for use in test functions */ + protected $postid1; + /** @var int Store the inserted post2->id for use in test functions */ + protected $postid2; + /** @var int Store the inserted post3->id for use in test functions */ + protected $postid3; + /** @var int Store the inserted post4->id for use in test functions */ + protected $postid4; + /** @var int Official contextid for these tests */ + protected $contextid; protected function setUp() { @@ -72,30 +86,30 @@ class backup_structure_testcase extends advanced_testcase { // Create two discussions $discussion1 = (object)array('course' => 1, 'forum' => $this->forumid, 'name' => 'd1', 'userid' => 100, 'groupid' => 200); - $d1id = $DB->insert_record('forum_discussions', $discussion1); + $this->discussionid1 = $DB->insert_record('forum_discussions', $discussion1); $discussion2 = (object)array('course' => 1, 'forum' => $this->forumid, 'name' => 'd2', 'userid' => 101, 'groupid' => 201); - $d2id = $DB->insert_record('forum_discussions', $discussion2); + $this->discussionid2 = $DB->insert_record('forum_discussions', $discussion2); // Create four posts - $post1 = (object)array('discussion' => $d1id, 'userid' => 100, 'subject' => 'p1', 'message' => 'm1'); - $p1id = $DB->insert_record('forum_posts', $post1); - $post2 = (object)array('discussion' => $d1id, 'parent' => $p1id, 'userid' => 102, 'subject' => 'p2', 'message' => 'm2'); - $p2id = $DB->insert_record('forum_posts', $post2); - $post3 = (object)array('discussion' => $d1id, 'parent' => $p2id, 'userid' => 103, 'subject' => 'p3', 'message' => 'm3'); - $p3id = $DB->insert_record('forum_posts', $post3); - $post4 = (object)array('discussion' => $d2id, 'userid' => 101, 'subject' => 'p4', 'message' => 'm4'); - $p4id = $DB->insert_record('forum_posts', $post4); + $post1 = (object)array('discussion' => $this->discussionid1, 'userid' => 100, 'subject' => 'p1', 'message' => 'm1'); + $this->postid1 = $DB->insert_record('forum_posts', $post1); + $post2 = (object)array('discussion' => $this->discussionid1, 'parent' => $this->postid1, 'userid' => 102, 'subject' => 'p2', 'message' => 'm2'); + $this->postid2 = $DB->insert_record('forum_posts', $post2); + $post3 = (object)array('discussion' => $this->discussionid1, 'parent' => $this->postid2, 'userid' => 103, 'subject' => 'p3', 'message' => 'm3'); + $this->postid3 = $DB->insert_record('forum_posts', $post3); + $post4 = (object)array('discussion' => $this->discussionid2, 'userid' => 101, 'subject' => 'p4', 'message' => 'm4'); + $this->postid4 = $DB->insert_record('forum_posts', $post4); // With two related file $f1_post1 = (object)array( 'contenthash' => 'testp1', 'contextid' => $this->contextid, 'component'=>'mod_forum', - 'filearea' => 'post', 'filename' => 'tp1', 'itemid' => $p1id, + 'filearea' => 'post', 'filename' => 'tp1', 'itemid' => $this->postid1, 'filesize' => 123, 'timecreated' => 0, 'timemodified' => 0, 'pathnamehash' => 'testp1' ); $DB->insert_record('files', $f1_post1); $f1_post2 = (object)array( 'contenthash' => 'testp2', 'contextid' => $this->contextid, 'component'=>'mod_forum', - 'filearea' => 'attachment', 'filename' => 'tp2', 'itemid' => $p2id, + 'filearea' => 'attachment', 'filename' => 'tp2', 'itemid' => $this->postid2, 'filesize' => 123, 'timecreated' => 0, 'timemodified' => 0, 'pathnamehash' => 'testp2' ); @@ -103,16 +117,16 @@ class backup_structure_testcase extends advanced_testcase { // Create two ratings $rating1 = (object)array( - 'contextid' => $this->contextid, 'userid' => 104, 'itemid' => $p1id, 'rating' => 2, + 'contextid' => $this->contextid, 'userid' => 104, 'itemid' => $this->postid1, 'rating' => 2, 'scaleid' => -1, 'timecreated' => time(), 'timemodified' => time()); $r1id = $DB->insert_record('rating', $rating1); $rating2 = (object)array( - 'contextid' => $this->contextid, 'userid' => 105, 'itemid' => $p1id, 'rating' => 3, + 'contextid' => $this->contextid, 'userid' => 105, 'itemid' => $this->postid1, 'rating' => 3, 'scaleid' => -1, 'timecreated' => time(), 'timemodified' => time()); $r2id = $DB->insert_record('rating', $rating2); // Create 1 reads - $read1 = (object)array('userid' => 102, 'forumid' => $this->forumid, 'discussionid' => $d2id, 'postid' => $p4id); + $read1 = (object)array('userid' => 102, 'forumid' => $this->forumid, 'discussionid' => $this->discussionid2, 'postid' => $this->postid4); $DB->insert_record('forum_read', $read1); } @@ -195,11 +209,11 @@ class backup_structure_testcase extends advanced_testcase { // Let's add 1 optigroup with 4 elements $alternative1 = new backup_optigroup_element('alternative1', - array('name', 'value'), '../../id', 1); + array('name', 'value'), '../../id', $this->postid1); $alternative2 = new backup_optigroup_element('alternative2', - array('name', 'value'), backup::VAR_PARENTID, 2); + array('name', 'value'), backup::VAR_PARENTID, $this->postid2); $alternative3 = new backup_optigroup_element('alternative3', - array('name', 'value'), '/forum/discussions/discussion/posts/post/id', 3); + array('name', 'value'), '/forum/discussions/discussion/posts/post/id', $this->postid3); $alternative4 = new backup_optigroup_element('alternative4', array('forumtype', 'forumname')); // Alternative without conditions // Create the optigroup, adding one element @@ -239,7 +253,7 @@ class backup_structure_testcase extends advanced_testcase { array(backup::VAR_PARENTID) ); - $read->set_source_table('forum_read', array('id' => '../../id')); + $read->set_source_table('forum_read', array('forumid' => '../../id')); $inventeds->set_source_array(array((object)array('reason' => 'I love Moodle', 'version' => '1.0'), (object)array('reason' => 'I love Moodle', 'version' => '2.0'))); // 2 object array @@ -334,83 +348,83 @@ class backup_structure_testcase extends advanced_testcase { $ratarr[$node->nodeName] = $node->nodeValue; } } - $this->assertEquals($ratarr['userid'], $DB->get_field('rating', 'userid', array('id' => $ratarr['id']))); - $this->assertEquals($ratarr['itemid'], $DB->get_field('rating', 'itemid', array('id' => $ratarr['id']))); - $this->assertEquals($ratarr['post_rating'], $DB->get_field('rating', 'rating', array('id' => $ratarr['id']))); + $this->assertEquals($DB->get_field('rating', 'userid', array('id' => $ratarr['id'])), $ratarr['userid']); + $this->assertEquals($DB->get_field('rating', 'itemid', array('id' => $ratarr['id'])), $ratarr['itemid']); + $this->assertEquals($DB->get_field('rating', 'rating', array('id' => $ratarr['id'])), $ratarr['post_rating']); } // Check forum has "blockeperiod" with value 0 (was declared by object instead of name) $query = '/forum[blockperiod="0"]'; $result = $xpath->query($query); - $this->assertEquals($result->length, 1); + $this->assertEquals(1, $result->length); // Check forum is missing "completiondiscussions" (as we are using mock_skip_final_element) $query = '/forum/completiondiscussions'; $result = $xpath->query($query); - $this->assertEquals($result->length, 0); + $this->assertEquals(0, $result->length); // Check forum has "completionreplies" with value "original was 0, now changed" (because of mock_modify_final_element) $query = '/forum[completionreplies="original was 0, now changed"]'; $result = $xpath->query($query); - $this->assertEquals($result->length, 1); + $this->assertEquals(1, $result->length); // Check forum has "completionposts" with value "intercepted!" (because of mock_final_element_interceptor) $query = '/forum[completionposts="intercepted!"]'; $result = $xpath->query($query); - $this->assertEquals($result->length, 1); + $this->assertEquals(1, $result->length); // Check there isn't any alternative2 tag, as far as it hasn't source defined $query = '//alternative2'; $result = $xpath->query($query); - $this->assertEquals($result->length, 0); + $this->assertEquals(0, $result->length); // Check there are 4 "field1" elements $query = '/forum/discussions/discussion/posts/post//field1'; $result = $xpath->query($query); - $this->assertEquals($result->length, 4); + $this->assertEquals(4, $result->length); // Check first post has one name element with value "alternative1" - $query = '/forum/discussions/discussion/posts/post[@id="1"][name="alternative1"]'; + $query = '/forum/discussions/discussion/posts/post[@id="'.$this->postid1.'"][name="alternative1"]'; $result = $xpath->query($query); - $this->assertEquals($result->length, 1); + $this->assertEquals(1, $result->length); // Check there are two "dupetest1" elements $query = '/forum/discussions/discussion/posts/post//dupetest1'; $result = $xpath->query($query); - $this->assertEquals($result->length, 2); + $this->assertEquals(2, $result->length); // Check second post has one name element with value "dupetest2" - $query = '/forum/discussions/discussion/posts/post[@id="2"]/dupetest2'; + $query = '/forum/discussions/discussion/posts/post[@id="'.$this->postid2.'"]/dupetest2'; $result = $xpath->query($query); - $this->assertEquals($result->length, 1); + $this->assertEquals(1, $result->length); // Check element "dupetest2" of second post has one field1 element with value "2" - $query = '/forum/discussions/discussion/posts/post[@id="2"]/dupetest2[field1="2"]'; + $query = '/forum/discussions/discussion/posts/post[@id="'.$this->postid2.'"]/dupetest2[field1="2"]'; $result = $xpath->query($query); - $this->assertEquals($result->length, 1); + $this->assertEquals(1, $result->length); // Check forth post has no name element - $query = '/forum/discussions/discussion/posts/post[@id="4"]/name'; + $query = '/forum/discussions/discussion/posts/post[@id="'.$this->postid4.'"]/name'; $result = $xpath->query($query); - $this->assertEquals($result->length, 0); + $this->assertEquals(0, $result->length); // Check 1st, 2nd and 3rd posts have no forumtype element - $query = '/forum/discussions/discussion/posts/post[@id="1"]/forumtype'; + $query = '/forum/discussions/discussion/posts/post[@id="'.$this->postid1.'"]/forumtype'; $result = $xpath->query($query); - $this->assertEquals($result->length, 0); - $query = '/forum/discussions/discussion/posts/post[@id="2"]/forumtype'; + $this->assertEquals(0, $result->length); + $query = '/forum/discussions/discussion/posts/post[@id="'.$this->postid2.'"]/forumtype'; $result = $xpath->query($query); - $this->assertEquals($result->length, 0); - $query = '/forum/discussions/discussion/posts/post[@id="3"]/forumtype'; + $this->assertEquals(0, $result->length); + $query = '/forum/discussions/discussion/posts/post[@id="'.$this->postid3.'"]/forumtype'; $result = $xpath->query($query); - $this->assertEquals($result->length, 0); + $this->assertEquals(0, $result->length); // Check 4th post has one forumtype element with value "general" // (because it doesn't matches alternatives 1, 2, 3, then alternative 4, // the one without conditions is being applied) - $query = '/forum/discussions/discussion/posts/post[@id="4"][forumtype="general"]'; + $query = '/forum/discussions/discussion/posts/post[@id="'.$this->postid4.'"][forumtype="general"]'; $result = $xpath->query($query); - $this->assertEquals($result->length, 1); + $this->assertEquals(1, $result->length); // Check annotations information against DB // Count records in original tables diff --git a/lib/phpunit/tests/advanced_test.php b/lib/phpunit/tests/advanced_test.php index 8811bcfdd58..76ff14d28a7 100644 --- a/lib/phpunit/tests/advanced_test.php +++ b/lib/phpunit/tests/advanced_test.php @@ -142,10 +142,11 @@ class core_phpunit_advanced_testcase extends advanced_testcase { $this->assertEquals(0, $DB->count_records('user_preferences')); $originaldisplayid = $DB->insert_record('user_preferences', array('userid'=>2, 'name'=> 'phpunittest', 'value'=>'x')); - $this->assertEquals(1, $originaldisplayid); + $this->assertEquals(1, $DB->count_records('user_preferences')); + $numcourses = $DB->count_records('course'); $course = $this->getDataGenerator()->create_course(); - $this->assertEquals(2, $course->id); + $this->assertEquals($numcourses + 1, $DB->count_records('course')); $this->assertEquals(2, $DB->count_records('user')); $DB->delete_records('user', array('id'=>1)); @@ -155,8 +156,10 @@ class core_phpunit_advanced_testcase extends advanced_testcase { $this->assertEquals(1, $DB->count_records('course')); // Only frontpage in new site. $this->assertEquals(0, $DB->count_records('context_temp')); // Only frontpage in new site. + + $numcourses = $DB->count_records('course'); $course = $this->getDataGenerator()->create_course(); - $this->assertEquals(2, $course->id); + $this->assertEquals($numcourses + 1, $DB->count_records('course')); $displayid = $DB->insert_record('user_preferences', array('userid'=>2, 'name'=> 'phpunittest', 'value'=>'x')); $this->assertEquals($originaldisplayid, $displayid); @@ -164,20 +167,23 @@ class core_phpunit_advanced_testcase extends advanced_testcase { $this->assertEquals(2, $DB->count_records('user')); $DB->delete_records('user', array('id'=>2)); $user = $this->getDataGenerator()->create_user(); - $this->assertEquals(3, $user->id); + $this->assertEquals(2, $DB->count_records('user')); + $this->assertGreaterThan(2, $user->id); $this->resetAllData(); + $numcourses = $DB->count_records('course'); $course = $this->getDataGenerator()->create_course(); - $this->assertEquals(2, $course->id); + $this->assertEquals($numcourses + 1, $DB->count_records('course')); $this->assertEquals(2, $DB->count_records('user')); $DB->delete_records('user', array('id'=>2)); $this->resetAllData(); + $numcourses = $DB->count_records('course'); $course = $this->getDataGenerator()->create_course(); - $this->assertEquals(2, $course->id); + $this->assertEquals($numcourses + 1, $DB->count_records('course')); $this->assertEquals(2, $DB->count_records('user')); } diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index bb1f1e87386..d4a821da604 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -385,7 +385,7 @@ class core_accesslib_testcase extends advanced_testcase { $permission = $DB->get_record('role_capabilities', array('contextid'=>$frontcontext->id, 'roleid'=>$student->id, 'capability'=>'moodle/backup:backupcourse')); $this->assertNotEmpty($permission); $this->assertEquals(CAP_ALLOW, $permission->permission); - $this->assertEquals(3, $permission->modifierid); + $this->assertEquals($user->id, $permission->modifierid); $result = assign_capability('moodle/backup:backupcourse', CAP_PROHIBIT, $student->id, $frontcontext->id, true); $this->assertTrue($result); @@ -1796,7 +1796,7 @@ class core_accesslib_testcase extends advanced_testcase { // Add a resource to frontpage. $page = $generator->create_module('page', array('course'=>$SITE->id)); - $testpages[] = $page->id; + $testpages[] = $page->cmid; $frontpagepagecontext = context_module::instance($page->cmid); // Add block to frontpage resource. @@ -1839,7 +1839,7 @@ class core_accesslib_testcase extends advanced_testcase { // Add a resource to each course. $page = $generator->create_module('page', array('course'=>$course->id)); - $testpages[] = $page->id; + $testpages[] = $page->cmid; $modcontext = context_module::instance($page->cmid); // Add block to each module. @@ -2700,8 +2700,8 @@ class core_accesslib_testcase extends advanced_testcase { $this->assertEquals($url1, $url2); $this->assertInstanceOf('moodle_url', $url2); - $pagecm = get_coursemodule_from_instance('page', $testpages[7]); - $context = context_module::instance($pagecm->id); + $pagecm = get_coursemodule_from_id('page', $testpages[7]); + $context = context_module::instance($testpages[7]); $coursecontext1 = get_course_context($context); $this->assertDebuggingCalled('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER); $coursecontext2 = $context->get_course_context(true); diff --git a/lib/tests/grades_externallib_test.php b/lib/tests/grades_externallib_test.php index eb5a39255bc..49bcf6c6eaa 100644 --- a/lib/tests/grades_externallib_test.php +++ b/lib/tests/grades_externallib_test.php @@ -145,7 +145,7 @@ class core_grades_external_testcase extends externallib_advanced_testcase { $student2rawgrade = 20; list($course, $assignment, $student1, $student2, $teacher, $parent) = $this->load_test_data($assignmentname, $student1rawgrade, $student2rawgrade); - $assigmentcm = get_coursemodule_from_id('assign', $assignment->id, 0, false, MUST_EXIST); + $assigmentcm = get_coursemodule_from_id('assign', $assignment->cmid, 0, false, MUST_EXIST); // Student requesting their own grade for the assignment. $this->setUser($student1); @@ -395,7 +395,7 @@ class core_grades_external_testcase extends externallib_advanced_testcase { $student2rawgrade = 20; list($course, $assignment, $student1, $student2, $teacher, $parent) = $this->load_test_data($assignmentname, $student1rawgrade, $student2rawgrade); - $assigmentcm = get_coursemodule_from_id('assign', $assignment->id, 0, false, MUST_EXIST); + $assigmentcm = get_coursemodule_from_id('assign', $assignment->cmid, 0, false, MUST_EXIST); $this->setUser($teacher); diff --git a/mod/assign/tests/events_test.php b/mod/assign/tests/events_test.php index bbf9a4206b9..c3cd38f75fc 100644 --- a/mod/assign/tests/events_test.php +++ b/mod/assign/tests/events_test.php @@ -615,7 +615,7 @@ class assign_events_testcase extends mod_assign_base_testcase { // Insert a grade for this submission. $grade = new stdClass(); - $grade->assignment = 1; + $grade->assignment = $assign->get_instance()->id; $grade->userid = $this->students[0]->id; $gradeid = $DB->insert_record('assign_grades', $grade); diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php index f764d23574c..00288b109df 100644 --- a/mod/assign/tests/externallib_test.php +++ b/mod/assign/tests/externallib_test.php @@ -273,7 +273,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { // Create a teacher and give them capabilities. $context = context_course::instance($course1->id); $roleid = $this->assignUserCapability('moodle/course:viewparticipants', $context->id, 3); - $context = context_module::instance($assign1->id); + $context = context_module::instance($assign1->cmid); $this->assignUserCapability('mod/assign:grade', $context->id, $roleid); // Create the teacher's enrolment record. diff --git a/mod/choice/tests/events_test.php b/mod/choice/tests/events_test.php index dcc903062e6..a8ee8a19097 100644 --- a/mod/choice/tests/events_test.php +++ b/mod/choice/tests/events_test.php @@ -78,7 +78,7 @@ class mod_choice_events_testcase extends advanced_testcase { $this->assertInstanceOf('\mod_choice\event\answer_submitted', $events[0]); $this->assertEquals($user->id, $events[0]->userid); $this->assertEquals(context_module::instance($this->choice->cmid), $events[0]->get_context()); - $this->assertEquals(1, $events[0]->other['choiceid']); + $this->assertEquals($this->choice->id, $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); $this->assertEventLegacyLogData($expected, $events[0]); @@ -129,7 +129,7 @@ class mod_choice_events_testcase extends advanced_testcase { $this->assertInstanceOf('\mod_choice\event\answer_updated', $events[0]); $this->assertEquals($user->id, $events[0]->userid); $this->assertEquals(context_module::instance($this->choice->cmid), $events[0]->get_context()); - $this->assertEquals(1, $events[0]->other['choiceid']); + $this->assertEquals($this->choice->id, $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, $this->choice->id, $this->cm->id); diff --git a/mod/data/tests/lib_test.php b/mod/data/tests/lib_test.php index 2de1fcd4eac..78ab7ed9b71 100644 --- a/mod/data/tests/lib_test.php +++ b/mod/data/tests/lib_test.php @@ -148,7 +148,7 @@ class data_lib_testcase extends advanced_testcase { $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'database_entry'; - $cmt->itemid = $contentid; + $cmt->itemid = $recordid; $cmt->showcount = true; $cmt->component = 'mod_data'; $comment = new comment($cmt); @@ -163,7 +163,7 @@ class data_lib_testcase extends advanced_testcase { // Checking that the event contains the expected values. $this->assertInstanceOf('\mod_data\event\comment_created', $event); $this->assertEquals($context, $event->get_context()); - $url = new moodle_url('/mod/data/view.php', array('id' => $module->cmid)); + $url = new moodle_url('/mod/data/view.php', array('id' => $cm->id)); $this->assertEquals($url, $event->get_url()); $this->assertEventContextNotUsed($event); } @@ -211,7 +211,7 @@ class data_lib_testcase extends advanced_testcase { $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'database_entry'; - $cmt->itemid = $contentid; + $cmt->itemid = $recordid; $cmt->showcount = true; $cmt->component = 'mod_data'; $comment = new comment($cmt); diff --git a/mod/data/tests/search_test.php b/mod/data/tests/search_test.php index bfc84b80e91..75c02ceb451 100644 --- a/mod/data/tests/search_test.php +++ b/mod/data/tests/search_test.php @@ -102,6 +102,9 @@ class data_advanced_search_sql_test extends advanced_testcase { // we already have 2 users, we need 98 more - let's ignore the fact that guest can not post anywhere + // We reset the user sequence here to ensure we get the expected numbers. + // TODO: Invent a better way for managing data file input against database sequence id's. + $DB->get_manager()->reset_sequence('user'); for($i=3;$i<=100;$i++) { $this->getDataGenerator()->create_user(); } @@ -118,6 +121,9 @@ class data_advanced_search_sql_test extends advanced_testcase { 'data_content' => __DIR__.'/fixtures/test_data_content.csv', ); $this->loadDataSet($this->createCsvDataSet($files)); + // Set dataid to the correct value now the data has been inserted by csv file. + $DB->execute('UPDATE {data_fields} SET dataid = ?', array($data->id)); + $DB->execute('UPDATE {data_records} SET dataid = ?', array($data->id)); // Create the search array which contains our advanced search criteria. $fieldinfo = array('0' => new stdClass(), diff --git a/mod/forum/tests/events_test.php b/mod/forum/tests/events_test.php index f7cf595cae3..cbbf2dddcc1 100644 --- a/mod/forum/tests/events_test.php +++ b/mod/forum/tests/events_test.php @@ -1025,7 +1025,7 @@ class mod_forum_events_testcase extends advanced_testcase { $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id)); $params = array( - 'context' => context_module::instance($forum->id), + 'context' => context_module::instance($forum->cmid), 'other' => array('reportmode' => 'posts'), 'relateduserid' => $user->id, ); diff --git a/mod/forum/tests/externallib_test.php b/mod/forum/tests/externallib_test.php index 21c46290817..30009184062 100644 --- a/mod/forum/tests/externallib_test.php +++ b/mod/forum/tests/externallib_test.php @@ -232,7 +232,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase { // Check the discussions were correctly created. $this->assertEquals(3, $DB->count_records_select('forum_discussions', 'forum = :forum1 OR forum = :forum2 - OR id = :forum3', array('forum1' => $forum1->id, 'forum2' => $forum2->id, 'forum3' => $forum3->id))); + OR forum = :forum3', array('forum1' => $forum1->id, 'forum2' => $forum2->id, 'forum3' => $forum3->id))); // Check the posts were correctly created, don't forget each discussion created also creates a post. $this->assertEquals(7, $DB->count_records_select('forum_posts', 'discussion = :discussion1 OR discussion = :discussion2', @@ -491,7 +491,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase { 'attachment' => $discussion1reply1->attachment, 'totalscore' => $discussion1reply1->totalscore, 'mailnow' => $discussion1reply1->mailnow, - 'children' => array(4), + 'children' => array($discussion1reply2->id), 'canreply' => true, 'postread' => false, 'userfullname' => fullname($user2) diff --git a/mod/lesson/tests/events_test.php b/mod/lesson/tests/events_test.php index dda3ee935d7..d91f4178e4f 100644 --- a/mod/lesson/tests/events_test.php +++ b/mod/lesson/tests/events_test.php @@ -78,7 +78,7 @@ class mod_lesson_events_testcase extends advanced_testcase { $this->assertInstanceOf('\mod_lesson\event\essay_attempt_viewed', $event); $this->assertEquals(context_module::instance($this->lesson->properties()->cmid), $event->get_context()); $expected = array($this->course->id, 'lesson', 'view grade', 'essay.php?id=' . $this->lesson->properties()->cmid . - '&mode=grade&attemptid=1', get_string('manualgrading', 'lesson'), $this->lesson->properties()->cmid); + '&mode=grade&attemptid='.$this->lesson->id, get_string('manualgrading', 'lesson'), $this->lesson->properties()->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } diff --git a/mod/wiki/tests/events_test.php b/mod/wiki/tests/events_test.php index 59e60b5bef9..b7cf118458c 100644 --- a/mod/wiki/tests/events_test.php +++ b/mod/wiki/tests/events_test.php @@ -555,7 +555,7 @@ class mod_wiki_events_testcase extends advanced_testcase { $page = $this->wikigenerator->create_first_page($this->wiki); $context = context_module::instance($this->wiki->cmid); - $version = wiki_get_version(1); + $version = wiki_get_current_version($page->id); // Triggering and capturing the event. $sink = $this->redirectEvents(); diff --git a/mod/workshop/tests/events_test.php b/mod/workshop/tests/events_test.php index ad531219f81..ea86df9462e 100644 --- a/mod/workshop/tests/events_test.php +++ b/mod/workshop/tests/events_test.php @@ -92,7 +92,7 @@ class mod_workshop_events_testcase extends advanced_testcase { $event = reset($events); // Check that the legacy log data is valid. - $expected = array($this->course->id, 'workshop', 'update switch phase', 'view.php?id=' . $this->workshop->id, + $expected = array($this->course->id, 'workshop', 'update switch phase', 'view.php?id=' . $this->cm->id, $newphase, $this->cm->id); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); @@ -175,7 +175,7 @@ class mod_workshop_events_testcase extends advanced_testcase { $event = reset($events); // Check that the legacy log data is valid. - $expected = array($this->course->id, 'workshop', 'update clear aggregated grade', 'view.php?id=' . $this->workshop->id, + $expected = array($this->course->id, 'workshop', 'update clear aggregated grade', 'view.php?id=' . $this->cm->id, $this->workshop->id, $this->cm->id); $this->assertEventLegacyLogData($expected, $event); @@ -236,7 +236,7 @@ class mod_workshop_events_testcase extends advanced_testcase { // Check that the legacy log data is valid. $expected = array($this->course->id, 'workshop', 'add submission', - 'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->cm->id); + 'submission.php?cmid=' . $this->cm->id . '&id=' . $submissionid, $submissionid, $this->cm->id); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); @@ -272,7 +272,7 @@ class mod_workshop_events_testcase extends advanced_testcase { // Check that the legacy log data is valid. $expected = array($this->course->id, 'workshop', 'update submission', - 'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->cm->id); + 'submission.php?cmid=' . $this->cm->id . '&id=' . $submissionid, $submissionid, $this->cm->id); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); @@ -308,7 +308,7 @@ class mod_workshop_events_testcase extends advanced_testcase { // Check that the legacy log data is valid. $expected = array($this->course->id, 'workshop', 'view submission', - 'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->cm->id); + 'submission.php?cmid=' . $this->cm->id . '&id=' . $submissionid, $submissionid, $this->cm->id); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event);