Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 33... Línea 33...
33
 
33
 
34
        parent::setUpBeforeClass();
34
        parent::setUpBeforeClass();
Línea 35... Línea 35...
35
    }
35
    }
36
 
-
 
37
    /**
-
 
38
     * Test message_get_blocked_users throws an exception because has been removed.
-
 
39
     */
-
 
40
    public function test_message_get_blocked_users(): void {
-
 
41
        $this->expectException('coding_exception');
-
 
42
        $this->expectExceptionMessage(
-
 
43
            'message_get_blocked_users() has been removed, please use \core_message\api::get_blocked_users() instead.'
-
 
44
        );
-
 
45
        message_get_blocked_users();
-
 
46
    }
-
 
47
 
-
 
48
    /**
-
 
49
     * Test message_get_contacts throws an exception because has been removed.
-
 
50
     */
-
 
51
    public function test_message_get_contacts(): void {
-
 
52
        $this->expectException('coding_exception');
-
 
53
        $this->expectExceptionMessage('message_get_contacts() has been removed.');
-
 
54
        message_get_contacts();
-
 
55
    }
-
 
56
 
36
 
57
    /**
37
    /**
58
     * Test message_search_users.
38
     * Test message_search_users.
59
     */
39
     */
Línea 64... Línea 44...
64
 
44
 
65
        // Set this user as the admin.
45
        // Set this user as the admin.
Línea 66... Línea 46...
66
        $this->setAdminUser();
46
        $this->setAdminUser();
67
 
47
 
68
        // Create a user to add to the admin's contact list.
48
        // Create a user to add to the admin's contact list.
Línea 69... Línea 49...
69
        $user1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'user1'));
49
        $user1 = $this->getDataGenerator()->create_user(['firstname' => 'Test1', 'lastname' => 'user1']);
70
        $user2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'user2'));
50
        $user2 = $this->getDataGenerator()->create_user(['firstname' => 'Test2', 'lastname' => 'user2']);
71
 
51
 
Línea 72... Línea 52...
72
        // Add users to the admin's contact list.
52
        // Add users to the admin's contact list.
73
        \core_message\api::add_contact($USER->id, $user1->id);
53
        api::add_contact($USER->id, $user1->id);
74
        \core_message\api::add_contact($USER->id, $user2->id);
54
        api::add_contact($USER->id, $user2->id);
75
 
55
 
Línea 92... Línea 72...
92
 
72
 
93
        $user1 = self::getDataGenerator()->create_user();
73
        $user1 = self::getDataGenerator()->create_user();
94
        $user2 = self::getDataGenerator()->create_user();
74
        $user2 = self::getDataGenerator()->create_user();
Línea 95... Línea 75...
95
        $user3 = self::getDataGenerator()->create_user();
75
        $user3 = self::getDataGenerator()->create_user();
96
 
76
 
Línea 97... Línea 77...
97
        \core_message\api::add_contact($user1->id, $user2->id);
77
        api::add_contact($user1->id, $user2->id);
-
 
78
        api::add_contact($user1->id, $user3->id);
98
        \core_message\api::add_contact($user1->id, $user3->id);
79
 
99
 
80
        // Create some individual conversations.
-
 
81
        $ic1 = api::create_conversation(
-
 
82
            api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
100
        // Create some individual conversations.
83
            [$user1->id, $user2->id]
101
        $ic1 = \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
84
        );
-
 
85
        $ic2 = api::create_conversation(
Línea 102... Línea 86...
102
            [$user1->id, $user2->id]);
86
            api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
103
        $ic2 = \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
87
            [$user1->id, $user3->id]
104
            [$user1->id, $user3->id]);
88
        );
105
 
89
 
106
        // Send some messages to individual conversations.
90
        // Send some messages to individual conversations.
Línea 107... Línea 91...
107
        $im1 = testhelper::send_fake_message_to_conversation($user1, $ic1->id, 'Message 1');
91
        $im1 = testhelper::send_fake_message_to_conversation($user1, $ic1->id, 'Message 1');
108
        $im2 = testhelper::send_fake_message_to_conversation($user2, $ic1->id, 'Message 2');
92
        $im2 = testhelper::send_fake_message_to_conversation($user2, $ic1->id, 'Message 2');
109
        $im3 = testhelper::send_fake_message_to_conversation($user1, $ic1->id, 'Message 3');
93
        $im3 = testhelper::send_fake_message_to_conversation($user1, $ic1->id, 'Message 3');
Línea 110... Línea 94...
110
        $im4 = testhelper::send_fake_message_to_conversation($user1, $ic2->id, 'Message 4');
94
        $im4 = testhelper::send_fake_message_to_conversation($user1, $ic2->id, 'Message 4');
111
 
95
 
112
        // Mark a message as read by user2.
96
        // Mark a message as read by user2.
113
        $message = $DB->get_record('messages', ['id' => $im1]);
97
        $message = $DB->get_record('messages', ['id' => $im1]);
Línea 137... Línea 121...
137
        $lastmessages = message_get_messages($user2->id, $user1->id, 0, true);
121
        $lastmessages = message_get_messages($user2->id, $user1->id, 0, true);
138
        $this->assertCount(1, $lastmessages);
122
        $this->assertCount(1, $lastmessages);
139
        $this->assertArrayHasKey($im1, $lastmessages);
123
        $this->assertArrayHasKey($im1, $lastmessages);
Línea 140... Línea 124...
140
 
124
 
-
 
125
        // Create some group conversations.
141
        // Create some group conversations.
126
        $gc1 = api::create_conversation(
142
        $gc1 = \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
127
            api::MESSAGE_CONVERSATION_TYPE_GROUP,
-
 
128
            [$user1->id, $user2->id, $user3->id],
-
 
129
            'Group chat'
Línea 143... Línea 130...
143
            [$user1->id, $user2->id, $user3->id], 'Group chat');
130
        );
144
 
131
 
Línea 145... Línea 132...
145
        // Send some messages to group conversations.
132
        // Send some messages to group conversations.
Línea 165... Línea 152...
165
        $user1 = self::getDataGenerator()->create_user();
152
        $user1 = self::getDataGenerator()->create_user();
166
        $user2 = self::getDataGenerator()->create_user();
153
        $user2 = self::getDataGenerator()->create_user();
167
        $user3 = self::getDataGenerator()->create_user();
154
        $user3 = self::getDataGenerator()->create_user();
Línea 168... Línea 155...
168
 
155
 
-
 
156
        // Create some group conversations.
169
        // Create some group conversations.
157
        $gc1 = api::create_conversation(
170
        $gc1 = \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
158
            api::MESSAGE_CONVERSATION_TYPE_GROUP,
-
 
159
            [$user1->id, $user2->id, $user3->id],
-
 
160
            'Group chat'
Línea 171... Línea 161...
171
            [$user1->id, $user2->id, $user3->id], 'Group chat');
161
        );
172
 
162
 
173
        // Send some messages to group conversations.
163
        // Send some messages to group conversations.
Línea 174... Línea 164...
174
        $gm1 = testhelper::send_fake_message_to_conversation($user1, $gc1->id, 'Group message 1');
164
        $gm1 = testhelper::send_fake_message_to_conversation($user1, $gc1->id, 'Group message 1');
175
        $gm2 = testhelper::send_fake_message_to_conversation($user2, $gc1->id, 'Group message 2');
165
        $gm2 = testhelper::send_fake_message_to_conversation($user2, $gc1->id, 'Group message 2');
176
 
166
 
177
        // Retrieve all messages sent from user1 to user2. There shouldn't be messages, because only individual
167
        // Retrieve all messages sent from user1 to user2. There shouldn't be messages, because only individual
178
        // conversations should be considered by the message_get_messages function.
168
        // conversations should be considered by the message_get_messages function.
179
        $lastmessages = message_get_messages($user2->id, $user1->id, 0, MESSAGE_GET_READ_AND_UNREAD);
-
 
180
        $this->assertCount(0, $lastmessages);
169
        $lastmessages = message_get_messages($user2->id, $user1->id, 0, MESSAGE_GET_READ_AND_UNREAD);