// User1 is member of some groups in course1 and course2 + self-conversation.
$contextlist = provider::get_contexts_for_userid($user1->id);
- $contextids = $contextlist->get_contextids();
- // First user context is the one related to self-conversation. Let's test group contexts.
- array_pop($contextids);
+ $contextids = array_values($contextlist->get_contextids());
+
$this->assertCount(3, $contextlist);
- $this->assertEquals(
- [$coursecontext1->id, $coursecontext2->id],
- $contextids,
- '', 0.0, 10, true);
+ // 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);
}
/**
// Now, get ONLY favourite conversations (including self-conversation).
$conversations = \core_message\api::get_conversations($user1->id, 0, 20, null, true);
$this->assertCount(2, $conversations);
- $self = array_pop($conversations);
foreach ($conversations as $conv) {
- $this->assertTrue($conv->isfavourite);
- $this->assertEquals($ic2->id, $conv->id);
+ if ($conv->type != \core_message\api::MESSAGE_CONVERSATION_TYPE_SELF) {
+ $this->assertTrue($conv->isfavourite);
+ $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $conv->type);
+ $this->assertEquals($ic2->id, $conv->id);
+ }
}
// Now, try ONLY favourites of type 'group'.
$users[$i] = $user;
}
- // Enrol the first 9 users in the same course, but leave them as non-contacts.
+ // Enrol the first 8 users in the same course, but leave them as non-contacts.
$this->setAdminUser();
$course1 = $this->getDataGenerator()->create_course();
foreach (range(1, 8) as $i) {
$this->assertCount(0, $muas);
$this->assertCount(6, $mcms);
- $mcm = reset($mcms);
- $this->assertEquals($user2->id, $mcm->userid);
+ $members = array_map(function($member) {
+ return $member->userid;
+ }, $mcms);
+ $this->assertContains($user2->id, $members);
$this->assertCount(2, $notifications);
ksort($notifications);