MDL-64993 core_message: fix unit test for non-ordered queries
authorAmaia Anabitarte <amaia@moodle.com>
Tue, 7 May 2019 09:49:05 +0000 (11:49 +0200)
committerSara Arjona <sara@moodle.com>
Tue, 7 May 2019 15:54:43 +0000 (17:54 +0200)
group/tests/privacy_provider_test.php
message/tests/api_test.php
message/tests/externallib_test.php
message/tests/privacy_provider_test.php

index 33c8aaf..3e8ff58 100644 (file)
@@ -716,14 +716,12 @@ class core_group_privacy_provider_testcase extends provider_testcase {
 
         // 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);
     }
 
     /**
index b335cc3..8d92645 100644 (file)
@@ -1766,10 +1766,12 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         // 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'.
index adafb5c..32247c7 100644 (file)
@@ -2811,7 +2811,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
             $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) {
index 24db3c0..5c0ad08 100644 (file)
@@ -1133,8 +1133,10 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
         $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);