Commit 8a14a7bd authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

MDL-71036 phpunit: assertContains() now performs strict comparison

The methods assertContains() and assertNotContains() now perform
strict (type and value) comparison, pretty much like assertSame()
does.

A couple of new assertContainsEquals() and assertNotContainsEquals()
methods have been created to provide old (non-strict) behavior, pretty
much like assertEquals() do.

Apart from replacing the calls needing a relaxed comparison to those
new methods, there are also a couple of alternative, about how to
fix this, depending of every case:

- If the test is making any array_values() conversion, then it's better
  to remove that conversion and use assertArrayHasKey(), that is not
  strict.
- Sometimes if may be also possible to, simply, cast the expectation
  to the exact type coming in the array. I've not applied this technique
  to any of the cases in core.

Link: https://github.com/sebastianbergmann/phpunit/issues/3426
parent 4a1df021
......@@ -237,9 +237,9 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
// There should only be one PO role.
$this->assertCount(1, $roleids);
// Confirm it contains the manager role.
$this->assertContains($managerroleid, $roleids);
$this->assertContainsEquals($managerroleid, $roleids);
// And it does not contain the editing teacher role.
$this->assertNotContains($editingteacherroleid, $roleids);
$this->assertNotContainsEquals($editingteacherroleid, $roleids);
}
/**
......@@ -838,7 +838,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$this->assertCount($filteredcount, $filteredrequests);
// Confirm the filtered requests match the status filter(s).
foreach ($filteredrequests as $request) {
$this->assertContains($request->get('status'), $statuses);
$this->assertContainsEquals($request->get('status'), $statuses);
}
if ($numstatus > 1) {
......
......@@ -950,8 +950,8 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$forumlist = $userlist->get_userlist_for_component('mod_forum');
$userids = $forumlist->get_userids();
$this->assertCount(1, $userids);
$this->assertContains($student->id, $userids);
$this->assertNotContains($teacher->id, $userids);
$this->assertContainsEquals($student->id, $userids);
$this->assertNotContainsEquals($teacher->id, $userids);
return true;
}));
......@@ -1038,8 +1038,8 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$forumlist = $userlist->get_userlist_for_component('mod_forum');
$userids = $forumlist->get_userids();
$this->assertCount(1, $userids);
$this->assertContains($student->id, $userids);
$this->assertNotContains($teacher->id, $userids);
$this->assertContainsEquals($student->id, $userids);
$this->assertNotContainsEquals($teacher->id, $userids);
return true;
}));
......@@ -1127,8 +1127,8 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$forumlist = $userlist->get_userlist_for_component('mod_forum');
$userids = $forumlist->get_userids();
$this->assertCount(1, $userids);
$this->assertContains($student->id, $userids);
$this->assertNotContains($teacher->id, $userids);
$this->assertContainsEquals($student->id, $userids);
$this->assertNotContainsEquals($teacher->id, $userids);
return true;
}));
......@@ -1223,8 +1223,8 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$forumlist = $userlist->get_userlist_for_component('mod_forum');
$userids = $forumlist->get_userids();
$this->assertCount(2, $userids);
$this->assertContains($student->id, $userids);
$this->assertContains($teacher->id, $userids);
$this->assertContainsEquals($student->id, $userids);
$this->assertContainsEquals($teacher->id, $userids);
return true;
}));
......
......@@ -261,8 +261,8 @@ class core_analytics_prediction_testcase extends advanced_testcase {
$this->assertEquals($predictedrangeindex, $predictedrange->rangeindex);
$sampleids = json_decode($predictedrange->sampleids, true);
$this->assertCount(2, $sampleids);
$this->assertContains($course1->id, $sampleids);
$this->assertContains($course2->id, $sampleids);
$this->assertContainsEquals($course1->id, $sampleids);
$this->assertContainsEquals($course2->id, $sampleids);
}
$this->assertEquals(1, $DB->count_records('analytics_used_files',
array('modelid' => $model->get_id(), 'action' => 'predicted')));
......@@ -302,10 +302,10 @@ class core_analytics_prediction_testcase extends advanced_testcase {
$this->assertEquals($predictedrangeindex, $predictedrange->rangeindex);
$sampleids = json_decode($predictedrange->sampleids, true);
$this->assertCount(4, $sampleids);
$this->assertContains($course1->id, $sampleids);
$this->assertContains($course2->id, $sampleids);
$this->assertContains($course3->id, $sampleids);
$this->assertContains($course4->id, $sampleids);
$this->assertContainsEquals($course1->id, $sampleids);
$this->assertContainsEquals($course2->id, $sampleids);
$this->assertContainsEquals($course3->id, $sampleids);
$this->assertContainsEquals($course4->id, $sampleids);
}
$this->assertEquals(2, $DB->count_records('analytics_used_files',
array('modelid' => $model->get_id(), 'action' => 'predicted')));
......
......@@ -388,7 +388,7 @@ class core_blog_privacy_testcase extends provider_testcase {
// Generate list of contexts for user.
$contexts = provider::get_contexts_for_userid($user->id);
$this->assertContains($context->id, $contexts->get_contextids());
$this->assertContainsEquals($context->id, $contexts->get_contextids());
// Now delete the blog entry.
$entry->delete();
......
......@@ -2437,7 +2437,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
// Assert that the record is either the 7th, 8th, 9th, ... 13th day of the month.
$this->assertContains(date('j', $record->timestart), $bymonthdays);
$this->assertContainsEquals(date('j', $record->timestart), $bymonthdays);
}
}
......@@ -2494,7 +2494,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertEquals($expecteddate->format('Y-m-d H:i:s'), date('Y-m-d H:i:s', $record->timestart));
// Assert that the record is either the 2nd, 3rd, 4th ... 8th day of the month.
$this->assertContains(date('j', $record->timestart), $bymonthdays);
$this->assertContainsEquals(date('j', $record->timestart), $bymonthdays);
}
}
......@@ -2525,7 +2525,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
(new DateTime('1997-11-06 09:00:00 EST'))->getTimestamp()
];
foreach ($records as $record) {
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2603,7 +2603,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
(new DateTime('1997-09-02 15:00:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2634,7 +2634,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
(new DateTime('1997-09-02 10:15:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2663,7 +2663,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
(new DateTime('1997-09-02 13:30:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2707,7 +2707,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount($count, $records);
foreach ($records as $record) {
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2751,7 +2751,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
$this->assertCount($count, $records);
foreach ($records as $record) {
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2782,7 +2782,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
(new DateTime('1997-08-24 09:00:00 EDT'))->getTimestamp(),
];
foreach ($records as $record) {
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......@@ -2815,7 +2815,7 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
];
foreach ($records as $record) {
$this->assertContains($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
$this->assertContainsEquals($record->timestart, $expecteddates, date('Y-m-d H:i:s', $record->timestart) . ' is not found.');
}
}
......
......@@ -71,8 +71,8 @@ class core_cohort_testcase extends provider_testcase {
// User is member of 2 cohorts.
$contextlist = provider::get_contexts_for_userid($user->id);
$this->assertCount(2, (array) $contextlist->get_contextids());
$this->assertContains($coursecategoryctx->id, $contextlist->get_contextids());
$this->assertContains($systemctx->id, $contextlist->get_contextids());
$this->assertContainsEquals($coursecategoryctx->id, $contextlist->get_contextids());
$this->assertContainsEquals($systemctx->id, $contextlist->get_contextids());
}
/**
......
......@@ -4395,7 +4395,7 @@ class core_competency_api_testcase extends advanced_testcase {
$leastarray = array($comp4->get('id'), $comp6->get('id'));
foreach ($result as $one) {
$this->assertInstanceOf('\core_competency\competency', $one);
$this->assertContains($one->get('id'), $leastarray);
$this->assertContainsEquals($one->get('id'), $leastarray);
}
}
......
......@@ -68,10 +68,10 @@ class core_contentbank_privacy_testcase extends provider_testcase {
$contextlistids = $contextlist->get_contextids();
$this->assertCount(3, $contextlistids);
// Check the list against the expected list of contexts.
$this->assertContains($scenario->systemcontext->id, $contextlistids);
$this->assertContains($scenario->coursecategorycontext->id,
$this->assertContainsEquals($scenario->systemcontext->id, $contextlistids);
$this->assertContainsEquals($scenario->coursecategorycontext->id,
$contextlistids);
$this->assertContains($scenario->coursecontext->id, $contextlistids);
$this->assertContainsEquals($scenario->coursecontext->id, $contextlistids);
// Testing againts Teacher who has content in the one context.
$contextlist = provider::get_contexts_for_userid($scenario->teacher->id);
......@@ -79,10 +79,10 @@ class core_contentbank_privacy_testcase extends provider_testcase {
$contextlistids = $contextlist->get_contextids();
$this->assertCount(1, $contextlistids);
// Check the againts Course Context.
$this->assertContains($scenario->coursecontext->id, $contextlistids);
$this->assertContainsEquals($scenario->coursecontext->id, $contextlistids);
// And there is not a System and Course Category Context.
$this->assertNotContains($scenario->systemcontext->id, $contextlistids);
$this->assertNotContains($scenario->coursecategorycontext->id, $contextlistids);
$this->assertNotContainsEquals($scenario->systemcontext->id, $contextlistids);
$this->assertNotContainsEquals($scenario->coursecategorycontext->id, $contextlistids);
}
/**
......
......@@ -1517,9 +1517,9 @@ class core_course_courselib_testcase extends advanced_testcase {
$modinfo = get_fast_modinfo($course);
// Verify that forum and page have been moved to the hidden section and quiz has not.
$this->assertContains($forum->cmid, $modinfo->sections[3]);
$this->assertContains($page->cmid, $modinfo->sections[3]);
$this->assertNotContains($quiz->cmid, $modinfo->sections[3]);
$this->assertContainsEquals($forum->cmid, $modinfo->sections[3]);
$this->assertContainsEquals($page->cmid, $modinfo->sections[3]);
$this->assertNotContainsEquals($quiz->cmid, $modinfo->sections[3]);
// Verify that forum has been made invisible.
$forumcm = $modinfo->cms[$forum->cmid];
......
......@@ -92,14 +92,14 @@ class enrol_flatfile_privacy_testcase extends provider_testcase {
$contextlist = provider::get_contexts_for_userid($this->user1->id);
$this->assertEquals(2, $contextlist->count());
$contextids = $contextlist->get_contextids();
$this->assertContains($this->coursecontext1->id, $contextids);
$this->assertContains($this->coursecontext3->id, $contextids);
$this->assertContainsEquals($this->coursecontext1->id, $contextids);
$this->assertContainsEquals($this->coursecontext3->id, $contextids);
// And 1 for user2 on course2.
$contextlist = provider::get_contexts_for_userid($this->user2->id);
$this->assertEquals(1, $contextlist->count());
$contextids = $contextlist->get_contextids();
$this->assertContains($this->coursecontext2->id, $contextids);
$this->assertContainsEquals($this->coursecontext2->id, $contextids);
}
/**
......@@ -189,8 +189,8 @@ class enrol_flatfile_privacy_testcase extends provider_testcase {
$contextlist = provider::get_contexts_for_userid($this->user1->id);
$this->assertEquals(2, $contextlist->count());
$contextids = $contextlist->get_contextids();
$this->assertContains($this->coursecontext1->id, $contextids);
$this->assertContains($this->coursecontext3->id, $contextids);
$this->assertContainsEquals($this->coursecontext1->id, $contextids);
$this->assertContainsEquals($this->coursecontext3->id, $contextids);
$approvedcontextlist = new approved_contextlist(
$this->user1,
......
......@@ -263,8 +263,8 @@ class enrol_paypal_privacy_provider_testcase extends \core_privacy\tests\provide
$this->assertCount(2, $contextlist);
$contextids = $contextlist->get_contextids();
$this->assertContains($coursecontext1->id, $contextids);
$this->assertContains($coursecontext2->id, $contextids);
$this->assertContainsEquals($coursecontext1->id, $contextids);
$this->assertContainsEquals($coursecontext2->id, $contextids);
}
/**
......
......@@ -53,7 +53,7 @@ class core_files_testcase extends provider_testcase {
$contextlist = provider::get_contexts_for_userid($user->id);
$this->assertCount(1, (array) $contextlist->get_contextids());
$this->assertContains($userctx->id, $contextlist->get_contextids());
$this->assertContainsEquals($userctx->id, $contextlist->get_contextids());
}
/**
......@@ -223,4 +223,4 @@ class core_files_testcase extends provider_testcase {
// The user data in userctx2 should not be deleted.
$this->assertCount(1, $userlist3);
}
}
\ No newline at end of file
}
......@@ -72,14 +72,14 @@ class core_grading_privacy_testcase extends provider_testcase {
// User1 has created grading definitions for instance1 and instance2.
$contextlist = provider::get_contexts_for_userid($this->user1->id);
$this->assertCount(2, $contextlist);
$this->assertContains($this->instancecontext1->id, $contextlist->get_contextids());
$this->assertContains($this->instancecontext2->id, $contextlist->get_contextids());
$this->assertNotContains($this->instancecontext0->id, $contextlist->get_contextids());
$this->assertContainsEquals($this->instancecontext1->id, $contextlist->get_contextids());
$this->assertContainsEquals($this->instancecontext2->id, $contextlist->get_contextids());
$this->assertNotContainsEquals($this->instancecontext0->id, $contextlist->get_contextids());
// User2 has only modified grading definitions for instance2.
$contextlist = provider::get_contexts_for_userid($this->user2->id);
$this->assertCount(1, $contextlist);
$this->assertContains($this->instancecontext2->id, $contextlist->get_contextids());
$this->assertContainsEquals($this->instancecontext2->id, $contextlist->get_contextids());
// User0 hasn't created or modified any grading definition.
$contextlist = provider::get_contexts_for_userid($this->user0->id);
......
......@@ -719,8 +719,8 @@ class core_group_privacy_provider_testcase extends provider_testcase {
$this->assertCount(3, $contextlist);
// One of the user context is the one related to self-conversation. Let's test group contexts.
$this->assertContains($coursecontext1->id, $contextids);
$this->assertContains($coursecontext2->id, $contextids);
$this->assertContainsEquals($coursecontext1->id, $contextids);
$this->assertContainsEquals($coursecontext2->id, $contextids);
}
/**
......
......@@ -641,8 +641,8 @@ class core_grouplib_testcase extends advanced_testcase {
$this->assertSame($group3->name, $data->groups[$group3->id]->name);
// Check we have the expected number of groupings.
$this->assertContains($grouping1->id, array_keys($data->groupings));
$this->assertContains($grouping2->id, array_keys($data->groupings));
$this->assertArrayHasKey($grouping1->id, $data->groupings);
$this->assertArrayHasKey($grouping2->id, $data->groupings);
// Test a grouping-id is mapped correctly.
$this->assertEquals($grouping2->name, $data->groupings[$grouping2->id]->name);
......@@ -657,10 +657,10 @@ class core_grouplib_testcase extends advanced_testcase {
foreach ($data->mappings as $mapping) {
if ($mapping->groupingid === $grouping1->id) {
$grouping1maps++;
$this->assertContains($mapping->groupid, array($group1->id, $group2->id));
$this->assertContainsEquals($mapping->groupid, array($group1->id, $group2->id));
} else if ($mapping->groupingid === $grouping2->id) {
$grouping2maps++;
$this->assertContains($mapping->groupid, array($group3->id, $group4->id));
$this->assertContainsEquals($mapping->groupid, array($group3->id, $group4->id));
} else {
$this->fail('Unexpected groupingid');
}
......@@ -680,35 +680,31 @@ class core_grouplib_testcase extends advanced_testcase {
// Test the groups_get_all_groups which uses this functionality.
$groups = groups_get_all_groups($course->id);
$groupkeys = array_keys($groups);
$this->assertCount(4, $groups);
$this->assertContains($group1->id, $groupkeys);
$this->assertContains($group2->id, $groupkeys);
$this->assertContains($group3->id, $groupkeys);
$this->assertContains($group4->id, $groupkeys);
$this->assertArrayHasKey($group1->id, $groups);
$this->assertArrayHasKey($group2->id, $groups);
$this->assertArrayHasKey($group3->id, $groups);
$this->assertArrayHasKey($group4->id, $groups);
$groups = groups_get_all_groups($course->id, null, $grouping1->id);
$groupkeys = array_keys($groups);
$this->assertCount(2, $groups);
$this->assertContains($group1->id, $groupkeys);
$this->assertContains($group2->id, $groupkeys);
$this->assertNotContains($group3->id, $groupkeys);
$this->assertNotContains($group4->id, $groupkeys);
$this->assertArrayHasKey($group1->id, $groups);
$this->assertArrayHasKey($group2->id, $groups);
$this->assertArrayNotHasKey($group3->id, $groups);
$this->assertArrayNotHasKey($group4->id, $groups);
$groups = groups_get_all_groups($course->id, null, $grouping2->id);
$groupkeys = array_keys($groups);
$this->assertCount(2, $groups);
$this->assertNotContains($group1->id, $groupkeys);
$this->assertNotContains($group2->id, $groupkeys);
$this->assertContains($group3->id, $groupkeys);
$this->assertContains($group4->id, $groupkeys);
$this->assertArrayNotHasKey($group1->id, $groups);
$this->assertArrayNotHasKey($group2->id, $groups);
$this->assertArrayHasKey($group3->id, $groups);
$this->assertArrayHasKey($group4->id, $groups);
// Test this function using an alternate column for the result index
$groups = groups_get_all_groups($course->id, null, $grouping2->id, 'g.name, g.id');
$groupkeys = array_keys($groups);
$this->assertCount(2, $groups);
$this->assertNotContains($group3->id, $groupkeys);
$this->assertContains($group3->name, $groupkeys);
$this->assertArrayNotHasKey($group3->id, $groups);
$this->assertArrayHasKey($group3->name, $groups);
$this->assertEquals($group3->id, $groups[$group3->name]->id);
}
......
......@@ -1545,7 +1545,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
$conversations = \core_message\api::get_conversations($user1->id);
// Consider first conversations is self-conversation.
$this->assertCount(7, $conversations);
$this->assertContains($gc2->id, array_column($conversations, 'id'));
$this->assertContainsEquals($gc2->id, array_column($conversations, 'id'));
// Delete all messages from an individual conversation the user is in - it should not be returned.
$this->assertTrue(\core_message\api::is_user_in_conversation($user1->id, $ic1->id));
......@@ -1557,7 +1557,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
$conversations = \core_message\api::get_conversations($user1->id);
// Consider first conversations is self-conversation.
$this->assertCount(6, $conversations);
$this->assertNotContains($ic1->id, array_column($conversations, 'id'));
$this->assertNotContainsEquals($ic1->id, array_column($conversations, 'id'));
}
/**
......@@ -5580,8 +5580,8 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
// however, we can still determine the number and ids of any recipients this way.
$this->assertCount(1, $events);
$userids = array_column($events, 'userid');
$this->assertNotContains($user1->id, $userids);
$this->assertContains($user2->id, $userids);
$this->assertNotContainsEquals($user1->id, $userids);
$this->assertContainsEquals($user2->id, $userids);
}
/**
......@@ -5629,9 +5629,9 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
// however, we can still determine the number and ids of any recipients this way.
$this->assertCount(2, $events);
$userids = array_column($events, 'userid');
$this->assertNotContains($user1->id, $userids);
$this->assertContains($user3->id, $userids);
$this->assertContains($user4->id, $userids);
$this->assertNotContainsEquals($user1->id, $userids);
$this->assertContainsEquals($user3->id, $userids);
$this->assertContainsEquals($user4->id, $userids);
}
/**
......
......@@ -2828,14 +2828,14 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
$members = $result['members'];
$this->assertCount(3, $members);
$membersid = [$members[0]['id'], $members[1]['id'], $members[2]['id']];
$this->assertContains($user1->id, $membersid);
$this->assertContains($user2->id, $membersid);
$this->assertContains($user3->id, $membersid);
$this->assertContainsEquals($user1->id, $membersid);
$this->assertContainsEquals($user2->id, $membersid);
$this->assertContainsEquals($user3->id, $membersid);
$membersfullnames = [$members[0]['fullname'], $members[1]['fullname'], $members[2]['fullname']];
$this->assertContains(fullname($user1), $membersfullnames);
$this->assertContains(fullname($user2), $membersfullnames);
$this->assertContains(fullname($user3), $membersfullnames);
$this->assertContainsEquals(fullname($user1), $membersfullnames);
$this->assertContainsEquals(fullname($user2), $membersfullnames);
$this->assertContainsEquals(fullname($user3), $membersfullnames);
// Confirm the messages data is correct.
$messages = $result['messages'];
......@@ -2957,9 +2957,9 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
$members = $result['members'];
$this->assertCount(3, $members);
$membersid = [$members[0]['id'], $members[1]['id'], $members[2]['id']];
$this->assertContains($user1->id, $membersid);
$this->assertContains($user2->id, $membersid);
$this->assertContains($user3->id, $membersid);
$this->assertContainsEquals($user1->id, $membersid);
$this->assertContainsEquals($user2->id, $membersid);
$this->assertContainsEquals($user3->id, $membersid);
// Confirm the message data is correct.
$messages = $result['messages'];
......
......@@ -1550,8 +1550,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
$contextlist = new contextlist();
provider::add_contexts_for_conversations($contextlist, $user1->id, $component, $itemtype);
$this->assertCount(2, $contextlist);
$this->assertContains($coursecontext1->id, $contextlist->get_contextids());
$this->assertContains($coursecontext2->id, $contextlist->get_contextids());
$this->assertContainsEquals($coursecontext1->id, $contextlist->get_contextids());
$this->assertContainsEquals($coursecontext2->id, $contextlist->get_contextids());
// Test for user2 (is member of the conversation and has sent a message).
$contextlist = new contextlist();
......@@ -2012,12 +2012,12 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
// There should be 5 messages - 3 individual - 2 group (course2).
$this->assertEquals(5, $DB->count_records('messages'));
$messages = array_keys($DB->get_records('messages'));
$this->assertContains($im1, $messages);
$this->assertContains($im2, $messages);
$this->assertContains($im3, $messages);
$this->assertContains($gm4, $messages);
$this->assertContains($gm5, $messages);
$messages = $DB->get_records('messages');
$this->assertArrayHasKey($im1, $messages);
$this->assertArrayHasKey($im2, $messages);
$this->assertArrayHasKey($im3, $messages);
$this->assertArrayHasKey($gm4, $messages);
$this->assertArrayHasKey($gm5, $messages);
// There should be 3 user actions - 2 for reading the message, 1 for deleting.
$this->assertEquals(3, $DB->count_records('message_user_actions'));
......@@ -2529,11 +2529,11 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
// There should be 4 messages - 3 private + 1 group sent by user2.
$this->assertEquals(4, $DB->count_records('messages'));
$messages = array_keys($DB->get_records('messages'));
$this->assertContains($pm1, $messages);
$this->assertContains($pm2, $messages);
$this->assertContains($pm3, $messages);
$this->assertContains($gm3, $messages);
$messages = $DB->get_records('messages');
$this->assertArrayHasKey($pm1, $messages);
$this->assertArrayHasKey($pm2, $messages);
$this->assertArrayHasKey($pm3, $messages);
$this->assertArrayHasKey($gm3, $messages);
// There should be 3 user actions - 2 for reading the message, one for deleting.
$this->assertEquals(3, $DB->count_records('message_user_actions'));
......@@ -2763,11 +2763,11 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
// There should be 4 messages - 3 private + 1 group sent by user3.
$this->assertEquals(4, $DB->count_records('messages'));
$messages = array_keys($DB->get_records('messages'));
$this->assertContains($pm1, $messages);
$this->assertContains($pm2, $messages);
$this->assertContains($pm3, $messages);
$this->assertContains($gm3, $messages);
$messages = $DB->get_records('messages');
$this->assertArrayHasKey($pm1, $messages);
$this->assertArrayHasKey($pm2, $messages);
$this->assertArrayHasKey($pm3, $messages);
$this->assertArrayHasKey($gm3, $messages);
// There should be 3 user actions - 2 for reading the message, one for deleting.
$this->assertEquals(3, $DB->count_records('message_user_actions'));
......
......@@ -175,10 +175,10 @@ class assignsubmission_comments_privacy_testcase extends \mod_assign\tests\mod_a
$userids = $userlist->get_userids();
$this->assertCount(3, $userids);
// User 1,2 and 3 are the expected ones in the array. User 4 isn't.
$this->assertContains($user1->id, $userids);
$this->assertContains($user2->id, $userids);
$this->assertContains($user3->id, $userids);
$this->assertNotContains($user4->id, $userids);
$this->assertContainsEquals($user1->id, $userids);
$this->assertContainsEquals($user2->id, $userids);
$this->assertContainsEquals($user3->id, $userids);
$this->assertNotContainsEquals($user4->id, $userids);
}
/**
......
......@@ -3388,23 +3388,23 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
// Get shared group members for students 0 and 1.
$groupmembers = $assign->get_shared_group_members($cm, $student1->id);
$this->assertCount(2, $groupmembers);
$this->assertContains($student1->id, $groupmembers);
$this->assertContains($student2->id, $groupmembers);