From ffd303146fa7529df2bacdf5fdc4619c8c9620ea Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 20 Nov 2018 14:28:58 +0800 Subject: [PATCH 1/3] MDL-63692 message: Fix unit test assumption Contact requests do not cause notifications. --- message/tests/privacy_provider_test.php | 44 ++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/message/tests/privacy_provider_test.php b/message/tests/privacy_provider_test.php index 182c8bb23fd..c10756d6b46 100644 --- a/message/tests/privacy_provider_test.php +++ b/message/tests/privacy_provider_test.php @@ -1845,8 +1845,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide // There should be 9 conversation members - (2 + 2) individual + (3 + 2) group. $this->assertEquals(9, $DB->count_records('message_conversation_members')); - // There should be 5 notifications - 3 notifications + 2 for the contact request. - $this->assertEquals(5, $DB->count_records('notifications')); + // There should be 3 notifications. + $this->assertEquals(3, $DB->count_records('notifications')); // There should be 3 favourite conversations. $this->assertEquals(3, $DB->count_records('favourite')); @@ -1863,8 +1863,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide // There should be still 2 blocked users. $this->assertEquals(2, $DB->count_records('message_users_blocked')); - // There should be still 5 notifications - 3 notifications + 2 for the contact request. - $this->assertEquals(5, $DB->count_records('notifications')); + // There should be 3 notifications. + $this->assertEquals(3, $DB->count_records('notifications')); // There should be 5 messages - 3 individual - 2 group (course2). $this->assertEquals(5, $DB->count_records('messages')); @@ -2018,8 +2018,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide // There should be 9 conversation members - (2 + 2) individual + (3 + 2) group. $this->assertEquals(9, $DB->count_records('message_conversation_members')); - // There should be 5 notifications - 3 notifications + 2 for the contact request. - $this->assertEquals(5, $DB->count_records('notifications')); + // There should be 3 notifications. + $this->assertEquals(3, $DB->count_records('notifications')); // There should be 3 favourite conversations. $this->assertEquals(3, $DB->count_records('favourite')); @@ -2035,7 +2035,7 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide $this->assertEquals(4, $DB->count_records('message_user_actions')); $this->assertEquals(4, $DB->count_records('message_conversations')); $this->assertEquals(9, $DB->count_records('message_conversation_members')); - $this->assertEquals(5, $DB->count_records('notifications')); + $this->assertEquals(3, $DB->count_records('notifications')); $this->assertEquals(3, $DB->count_records('favourite')); // Delete individual conversations for all users in system context. @@ -2049,7 +2049,7 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide $this->assertEquals(4, $DB->count_records('message_user_actions')); $this->assertEquals(4, $DB->count_records('message_conversations')); $this->assertEquals(9, $DB->count_records('message_conversation_members')); - $this->assertEquals(5, $DB->count_records('notifications')); + $this->assertEquals(3, $DB->count_records('notifications')); $this->assertEquals(3, $DB->count_records('favourite')); } @@ -2177,8 +2177,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide // There should be 9 conversation members - (2 + 2) individual + (3 + 2) group. $this->assertEquals(9, $DB->count_records('message_conversation_members')); - // There should be 5 notifications - 3 notifications + 2 for the contact request. - $this->assertEquals(5, $DB->count_records('notifications')); + // There should be 3 notifications. + $this->assertEquals(3, $DB->count_records('notifications')); // There should be 3 favourite conversations. $this->assertEquals(3, $DB->count_records('favourite')); @@ -2194,7 +2194,7 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide $this->assertEquals(4, $DB->count_records('message_user_actions')); $this->assertEquals(4, $DB->count_records('message_conversations')); $this->assertEquals(9, $DB->count_records('message_conversation_members')); - $this->assertEquals(5, $DB->count_records('notifications')); + $this->assertEquals(3, $DB->count_records('notifications')); $this->assertEquals(3, $DB->count_records('favourite')); // Delete individual conversations for all users in user context. @@ -2208,7 +2208,7 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide $this->assertEquals(4, $DB->count_records('message_user_actions')); $this->assertEquals(4, $DB->count_records('message_conversations')); $this->assertEquals(9, $DB->count_records('message_conversation_members')); - $this->assertEquals(5, $DB->count_records('notifications')); + $this->assertEquals(3, $DB->count_records('notifications')); $this->assertEquals(3, $DB->count_records('favourite')); } @@ -2312,8 +2312,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide // There should be 2 blocked users. $this->assertEquals(2, $DB->count_records('message_users_blocked')); - // There should be 3 notifications + 2 for the contact request. - $this->assertEquals(5, $DB->count_records('notifications')); + // There should be 3 notifications. + $this->assertEquals(3, $DB->count_records('notifications')); // There should be 6 messages. $this->assertEquals(6, $DB->count_records('messages')); @@ -2349,8 +2349,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide // There should be still 2 blocked users. $this->assertEquals(2, $DB->count_records('message_users_blocked')); - // There should be still 3 notifications + 2 for the contact request. - $this->assertEquals(5, $DB->count_records('notifications')); + // There should be 3 notifications. + $this->assertEquals(3, $DB->count_records('notifications')); // There should be 4 messages - 3 private + 1 group sent by user2. $this->assertEquals(4, $DB->count_records('messages')); @@ -2495,8 +2495,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide // There should be 2 blocked users. $this->assertEquals(2, $DB->count_records('message_users_blocked')); - // There should be 3 notifications + 2 for the contact request. - $this->assertEquals(5, $DB->count_records('notifications')); + // There should be 3 notifications. + $this->assertEquals(3, $DB->count_records('notifications')); // There should be 6 messages. $this->assertEquals(6, $DB->count_records('messages')); @@ -2528,7 +2528,7 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide $this->assertEquals(2, $DB->count_records('message_contacts')); $this->assertEquals(2, $DB->count_records('message_contact_requests')); $this->assertEquals(2, $DB->count_records('message_users_blocked')); - $this->assertEquals(5, $DB->count_records('notifications')); + $this->assertEquals(3, $DB->count_records('notifications')); $this->assertEquals(6, $DB->count_records('messages')); $this->assertEquals(4, $DB->count_records('message_user_actions')); $this->assertEquals(4, $DB->count_records('message_conversations')); @@ -2544,7 +2544,7 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide $this->assertEquals(2, $DB->count_records('message_contacts')); $this->assertEquals(2, $DB->count_records('message_contact_requests')); $this->assertEquals(2, $DB->count_records('message_users_blocked')); - $this->assertEquals(5, $DB->count_records('notifications')); + $this->assertEquals(3, $DB->count_records('notifications')); $this->assertEquals(6, $DB->count_records('messages')); $this->assertEquals(4, $DB->count_records('message_user_actions')); $this->assertEquals(4, $DB->count_records('message_conversations')); @@ -2566,8 +2566,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide // There should be still 2 blocked users. $this->assertEquals(2, $DB->count_records('message_users_blocked')); - // There should be still 3 notifications + 2 for the contact request. - $this->assertEquals(5, $DB->count_records('notifications')); + // There should be 3 notifications. + $this->assertEquals(3, $DB->count_records('notifications')); // There should be 4 messages - 3 private + 1 group sent by user3. $this->assertEquals(4, $DB->count_records('messages')); From 43f68992891b3b14be9a12a63517048b876819aa Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 20 Nov 2018 14:34:49 +0800 Subject: [PATCH 2/3] MDL-63692 message: Correct favourite fetch --- message/classes/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/message/classes/api.php b/message/classes/api.php index 68e290b5998..86a22f81e67 100644 --- a/message/classes/api.php +++ b/message/classes/api.php @@ -963,7 +963,7 @@ class api { global $DB; // Get the context for this conversation. - $conversation = $DB->get_records('message_conversations', ['id' => $conversationid]); + $conversation = $DB->get_record('message_conversations', ['id' => $conversationid]); $userctx = \context_user::instance($userid); if (empty($conversation->contextid)) { // When the conversation hasn't any contextid value defined, the favourite will be added to the user context. From 918776482acd20b6b980f782c1c2f89157fe0fb6 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 20 Nov 2018 14:41:40 +0800 Subject: [PATCH 3/3] MDL-63692 message: Set canonicalize to true for array comparison --- message/tests/privacy_provider_test.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/message/tests/privacy_provider_test.php b/message/tests/privacy_provider_test.php index c10756d6b46..4d1971cde98 100644 --- a/message/tests/privacy_provider_test.php +++ b/message/tests/privacy_provider_test.php @@ -1517,9 +1517,7 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide // Test for users with any group conversation in course1. provider::add_conversations_in_context($userlist1, $component, $itemtype); $this->assertCount(3, $userlist1); - $this->assertEquals( - [$user1->id, $user2->id, $user3->id], - $userlist1->get_userids()); + $this->assertEquals([$user1->id, $user2->id, $user3->id], $userlist1->get_userids(), '', 0, 10, true); // Test for users with any group conversation in course2. $userlist2 = new \core_privacy\local\request\userlist($coursecontext2, 'core_message');