Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
namespace core_message;
17
namespace core_message;
Línea 18... Línea -...
18
 
-
 
19
use core_message\tests\helper as testhelper;
-
 
20
 
-
 
21
defined('MOODLE_INTERNAL') || die();
-
 
22
 
-
 
23
global $CFG;
-
 
24
 
18
 
25
require_once($CFG->dirroot . '/message/tests/messagelib_test.php');
19
use core_message\tests\helper as testhelper;
26
 
20
 
27
/**
21
/**
28
 * Test message API.
22
 * Test message API.
29
 *
23
 *
30
 * @package core_message
24
 * @package core_message
-
 
25
 * @category test
31
 * @category test
26
 * @copyright 2016 Mark Nelson <markn@moodle.com>
32
 * @copyright 2016 Mark Nelson <markn@moodle.com>
27
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
28
 * @covers \core_message\api
-
 
29
 */
Línea 33... Línea -...
33
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
34
 */
30
final class api_test extends \advanced_testcase {
35
class api_test extends messagelib_test {
31
    public function test_mark_all_read_for_user_touser(): void {
Línea 36... Línea 32...
36
 
32
        $this->resetAfterTest();
37
    public function test_mark_all_read_for_user_touser() {
33
 
38
        $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
34
        $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
39
        $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
35
        $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
40
 
36
 
41
        $this->send_fake_message($sender, $recipient, 'Notification', 1);
37
        testhelper::send_fake_message($sender, $recipient, 'Notification', 1);
Línea 42... Línea 38...
42
        $this->send_fake_message($sender, $recipient, 'Notification', 1);
38
        testhelper::send_fake_message($sender, $recipient, 'Notification', 1);
Línea 43... Línea 39...
43
        $this->send_fake_message($sender, $recipient, 'Notification', 1);
39
        testhelper::send_fake_message($sender, $recipient, 'Notification', 1);
44
        $this->send_fake_message($sender, $recipient);
40
        testhelper::send_fake_message($sender, $recipient);
Línea 45... Línea 41...
45
        $this->send_fake_message($sender, $recipient);
41
        testhelper::send_fake_message($sender, $recipient);
46
        $this->send_fake_message($sender, $recipient);
42
        testhelper::send_fake_message($sender, $recipient);
47
 
43
 
Línea 48... Línea 44...
48
        $this->assertEquals(1, api::count_unread_conversations($recipient));
44
        $this->assertEquals(1, api::count_unread_conversations($recipient));
-
 
45
 
-
 
46
        api::mark_all_notifications_as_read($recipient->id);
49
 
47
        api::mark_all_messages_as_read($recipient->id);
50
        api::mark_all_notifications_as_read($recipient->id);
48
 
51
        api::mark_all_messages_as_read($recipient->id);
49
        // We've marked all of recipients conversation messages as read.
-
 
50
        $this->assertEquals(0, api::count_unread_conversations($recipient));
-
 
51
    }
-
 
52
 
52
 
53
    public function test_mark_all_read_for_user_touser_with_fromuser(): void {
53
        // We've marked all of recipients conversation messages as read.
54
        $this->resetAfterTest();
54
        $this->assertEquals(0, api::count_unread_conversations($recipient));
55
 
55
    }
56
        $sender1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
56
 
57
        $sender2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test3', 'lastname' => 'User3'));
57
    public function test_mark_all_read_for_user_touser_with_fromuser() {
58
        $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
58
        $sender1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
59
        $sender1 = $this->getDataGenerator()->create_user(['firstname' => 'Test1', 'lastname' => 'User1']);
59
        $sender2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test3', 'lastname' => 'User3'));
60
        $sender2 = $this->getDataGenerator()->create_user(['firstname' => 'Test3', 'lastname' => 'User3']);
60
        $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
61
        $recipient = $this->getDataGenerator()->create_user(['firstname' => 'Test2', 'lastname' => 'User2']);
61
 
62
 
62
        $this->send_fake_message($sender1, $recipient, 'Notification', 1);
63
        testhelper::send_fake_message($sender1, $recipient, 'Notification', 1);
63
        $this->send_fake_message($sender1, $recipient, 'Notification', 1);
64
        testhelper::send_fake_message($sender1, $recipient, 'Notification', 1);
64
        $this->send_fake_message($sender1, $recipient, 'Notification', 1);
65
        testhelper::send_fake_message($sender1, $recipient, 'Notification', 1);
Línea 65... Línea 66...
65
        $this->send_fake_message($sender1, $recipient);
66
        testhelper::send_fake_message($sender1, $recipient);
Línea 66... Línea 67...
66
        $this->send_fake_message($sender1, $recipient);
67
        testhelper::send_fake_message($sender1, $recipient);
67
        $this->send_fake_message($sender1, $recipient);
68
        testhelper::send_fake_message($sender1, $recipient);
Línea 83... Línea 84...
83
    }
84
    }
Línea 84... Línea 85...
84
 
85
 
85
    /**
86
    /**
86
     * Test count_blocked_users.
87
     * Test count_blocked_users.
87
     */
88
     */
88
    public function test_count_blocked_users() {
89
    public function test_count_blocked_users(): void {
-
 
90
        global $USER;
-
 
91
        $this->resetAfterTest();
Línea 89... Línea 92...
89
        global $USER;
92
 
90
 
93
 
Línea 91... Línea 94...
91
        // Set this user as the admin.
94
        // Set this user as the admin.
Línea 109... Línea 112...
109
     *
112
     *
110
     * This test verifies that any contacts are returned, as well as any non-contacts whose profile we can view.
113
     * This test verifies that any contacts are returned, as well as any non-contacts whose profile we can view.
111
     * If checks this by placing some users in the same course, where default caps would permit a user to view another user's
114
     * If checks this by placing some users in the same course, where default caps would permit a user to view another user's
112
     * profile.
115
     * profile.
113
     */
116
     */
114
    public function test_message_search_users_messagingallusers_disabled() {
117
    public function test_message_search_users_messagingallusers_disabled(): void {
115
        global $DB;
118
        global $DB;
116
        $this->resetAfterTest();
119
        $this->resetAfterTest();
Línea 117... Línea 120...
117
 
120
 
118
        // Create some users.
121
        // Create some users.
Línea 201... Línea 204...
201
     * Tests searching for users when site-wide messaging is enabled.
204
     * Tests searching for users when site-wide messaging is enabled.
202
     *
205
     *
203
     * This test verifies that any contacts are returned, as well as any non-contacts,
206
     * This test verifies that any contacts are returned, as well as any non-contacts,
204
     * provided the searching user can view their profile.
207
     * provided the searching user can view their profile.
205
     */
208
     */
206
    public function test_message_search_users_messagingallusers_enabled() {
209
    public function test_message_search_users_messagingallusers_enabled(): void {
207
        global $DB;
210
        global $DB;
208
        $this->resetAfterTest();
211
        $this->resetAfterTest();
Línea 209... Línea 212...
209
 
212
 
210
        // Create some users.
213
        // Create some users.
Línea 303... Línea 306...
303
    }
306
    }
Línea 304... Línea 307...
304
 
307
 
305
    /**
308
    /**
306
     * Verify searching for users find themselves when they have self-conversations.
309
     * Verify searching for users find themselves when they have self-conversations.
307
     */
310
     */
308
    public function test_message_search_users_self_conversations() {
311
    public function test_message_search_users_self_conversations(): void {
Línea 309... Línea 312...
309
        $this->resetAfterTest();
312
        $this->resetAfterTest();
310
 
313
 
311
        // Create some users.
314
        // Create some users.
Línea 332... Línea 335...
332
    }
335
    }
Línea 333... Línea 336...
333
 
336
 
334
    /**
337
    /**
335
     * Verify searching for users works even if no matching users from either contacts, or non-contacts can be found.
338
     * Verify searching for users works even if no matching users from either contacts, or non-contacts can be found.
336
     */
339
     */
337
    public function test_message_search_users_with_empty_result() {
340
    public function test_message_search_users_with_empty_result(): void {
Línea 338... Línea 341...
338
        $this->resetAfterTest();
341
        $this->resetAfterTest();
339
 
342
 
340
        // Create some users, but make sure neither will match the search term.
343
        // Create some users, but make sure neither will match the search term.
Línea 357... Línea 360...
357
    }
360
    }
Línea 358... Línea 361...
358
 
361
 
359
    /**
362
    /**
360
     * Test verifying that limits and offsets work for both the contacts and non-contacts return data.
363
     * Test verifying that limits and offsets work for both the contacts and non-contacts return data.
361
     */
364
     */
362
    public function test_message_search_users_limit_offset() {
365
    public function test_message_search_users_limit_offset(): void {
Línea 363... Línea 366...
363
        $this->resetAfterTest();
366
        $this->resetAfterTest();
364
 
367
 
365
        // Create 20 users.
368
        // Create 20 users.
Línea 433... Línea 436...
433
    }
436
    }
Línea 434... Línea 437...
434
 
437
 
435
    /**
438
    /**
436
     * Tests searching users as a user having the 'moodle/user:viewdetails' capability.
439
     * Tests searching users as a user having the 'moodle/user:viewdetails' capability.
437
     */
440
     */
438
    public function test_message_search_users_with_cap() {
441
    public function test_message_search_users_with_cap(): void {
439
        $this->resetAfterTest();
442
        $this->resetAfterTest();
Línea 440... Línea 443...
440
        global $DB;
443
        global $DB;
441
 
444
 
Línea 489... Línea 492...
489
    }
492
    }
Línea 490... Línea 493...
490
 
493
 
491
    /**
494
    /**
492
     * Tests searching users with messaging disabled.
495
     * Tests searching users with messaging disabled.
493
     */
496
     */
494
    public function test_message_search_users_messaging_disabled() {
497
    public function test_message_search_users_messaging_disabled(): void {
Línea 495... Línea 498...
495
        $this->resetAfterTest();
498
        $this->resetAfterTest();
496
 
499
 
Línea 506... Línea 509...
506
    }
509
    }
Línea 507... Línea 510...
507
 
510
 
508
    /**
511
    /**
509
     * Tests getting conversations between 2 users.
512
     * Tests getting conversations between 2 users.
510
     */
513
     */
-
 
514
    public function test_get_conversations_between_users(): void {
-
 
515
        $this->resetAfterTest();
511
    public function test_get_conversations_between_users() {
516
 
512
        // Create some users.
517
        // Create some users.
513
        $user1 = new \stdClass();
518
        $user1 = new \stdClass();
514
        $user1->firstname = 'User';
519
        $user1->firstname = 'User';
515
        $user1->lastname = 'One';
520
        $user1->lastname = 'One';
Línea 569... Línea 574...
569
    }
574
    }
Línea 570... Línea 575...
570
 
575
 
571
    /**
576
    /**
572
     * Tests getting self-conversations.
577
     * Tests getting self-conversations.
573
     */
578
     */
-
 
579
    public function test_get_self_conversation(): void {
-
 
580
        $this->resetAfterTest();
574
    public function test_get_self_conversation() {
581
 
575
        // Create some users.
582
        // Create some users.
576
        $user1 = new \stdClass();
583
        $user1 = new \stdClass();
577
        $user1->firstname = 'User';
584
        $user1->firstname = 'User';
578
        $user1->lastname = 'One';
585
        $user1->lastname = 'One';
Línea 631... Línea 638...
631
    }
638
    }
Línea 632... Línea 639...
632
 
639
 
633
    /**
640
    /**
634
     * Tests searching messages.
641
     * Tests searching messages.
635
     */
642
     */
636
    public function test_search_messages() {
643
    public function test_search_messages(): void {
Línea 637... Línea 644...
637
        $this->resetAfterTest();
644
        $this->resetAfterTest();
638
 
645
 
639
        // Create some users.
646
        // Create some users.
Línea 655... Línea 662...
655
 
662
 
656
        // Send some messages back and forth.
663
        // Send some messages back and forth.
657
        $time = 1;
664
        $time = 1;
658
        testhelper::send_fake_message_to_conversation($user1, $sc->id, 'Test message to self!', $time);
665
        testhelper::send_fake_message_to_conversation($user1, $sc->id, 'Test message to self!', $time);
659
        testhelper::send_fake_message_to_conversation($user1, $gc->id, 'My hero!', $time + 1);
666
        testhelper::send_fake_message_to_conversation($user1, $gc->id, 'My hero!', $time + 1);
660
        $this->send_fake_message($user3, $user1, 'Don\'t block me.', 0, $time + 2);
667
        testhelper::send_fake_message($user3, $user1, 'Don\'t block me.', 0, $time + 2);
661
        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 3);
668
        testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 3);
662
        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 4);
669
        testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 4);
663
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 5);
670
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 5);
Línea 664... Línea 671...
664
        $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 6);
671
        testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 6);
665
 
672
 
Línea 666... Línea 673...
666
        $convid = api::get_conversation_between_users([$user1->id, $user2->id]);
673
        $convid = api::get_conversation_between_users([$user1->id, $user2->id]);
Línea 742... Línea 749...
742
    }
749
    }
Línea 743... Línea 750...
743
 
750
 
744
    /**
751
    /**
745
     * Test verifying that favourited conversations can be retrieved.
752
     * Test verifying that favourited conversations can be retrieved.
746
     */
753
     */
-
 
754
    public function test_get_favourite_conversations(): void {
-
 
755
        $this->resetAfterTest();
747
    public function test_get_favourite_conversations() {
756
 
748
        // Create some users.
757
        // Create some users.
749
        $user1 = self::getDataGenerator()->create_user();
758
        $user1 = self::getDataGenerator()->create_user();
750
        $user2 = self::getDataGenerator()->create_user();
759
        $user2 = self::getDataGenerator()->create_user();
751
        $user3 = self::getDataGenerator()->create_user();
760
        $user3 = self::getDataGenerator()->create_user();
Línea 757... Línea 766...
757
        // Only self-conversation created.
766
        // Only self-conversation created.
758
        $this->assertCount(1, api::get_conversations($user1->id));
767
        $this->assertCount(1, api::get_conversations($user1->id));
Línea 759... Línea 768...
759
 
768
 
760
        // Create some conversations for user1.
769
        // Create some conversations for user1.
761
        $time = 1;
770
        $time = 1;
762
        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
771
        testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
763
        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
772
        testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
764
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
773
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
765
        $messageid1 = $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
774
        $messageid1 = testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
766
 
775
 
767
        $this->send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
776
        testhelper::send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
768
        $this->send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
777
        testhelper::send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
769
        $this->send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
778
        testhelper::send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
770
        $messageid2 = $this->send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
779
        $messageid2 = testhelper::send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
771
 
780
 
772
        $this->send_fake_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?', 0, $time + 9);
781
        testhelper::send_fake_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?', 0, $time + 9);
773
        $this->send_fake_message($user4, $user1, 'Yah brah, it\'s pretty rad.', 0, $time + 10);
782
        testhelper::send_fake_message($user4, $user1, 'Yah brah, it\'s pretty rad.', 0, $time + 10);
Línea 774... Línea 783...
774
        $messageid3 = $this->send_fake_message($user1, $user4, 'Dope.', 0, $time + 11);
783
        $messageid3 = testhelper::send_fake_message($user1, $user4, 'Dope.', 0, $time + 11);
775
 
784
 
776
        // Favourite the first 2 conversations for user1.
785
        // Favourite the first 2 conversations for user1.
777
        $convoids = [];
786
        $convoids = [];
Línea 801... Línea 810...
801
    }
810
    }
Línea 802... Línea 811...
802
 
811
 
803
    /**
812
    /**
804
     * Tests retrieving favourite conversations with a limit and offset to ensure pagination works correctly.
813
     * Tests retrieving favourite conversations with a limit and offset to ensure pagination works correctly.
805
     */
814
     */
-
 
815
    public function test_get_favourite_conversations_limit_offset(): void {
-
 
816
        $this->resetAfterTest();
806
    public function test_get_favourite_conversations_limit_offset() {
817
 
807
        // Create some users.
818
        // Create some users.
808
        $user1 = self::getDataGenerator()->create_user();
819
        $user1 = self::getDataGenerator()->create_user();
809
        $user2 = self::getDataGenerator()->create_user();
820
        $user2 = self::getDataGenerator()->create_user();
810
        $user3 = self::getDataGenerator()->create_user();
821
        $user3 = self::getDataGenerator()->create_user();
Línea 816... Línea 827...
816
        // Only self-conversation created.
827
        // Only self-conversation created.
817
        $this->assertCount(1, api::get_conversations($user1->id));
828
        $this->assertCount(1, api::get_conversations($user1->id));
Línea 818... Línea 829...
818
 
829
 
819
        // Create some conversations for user1.
830
        // Create some conversations for user1.
820
        $time = 1;
831
        $time = 1;
821
        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
832
        testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
822
        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
833
        testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
823
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
834
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
824
        $messageid1 = $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
835
        $messageid1 = testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
825
 
836
 
826
        $this->send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
837
        testhelper::send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
827
        $this->send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
838
        testhelper::send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
828
        $this->send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
839
        testhelper::send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
829
        $messageid2 = $this->send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
840
        $messageid2 = testhelper::send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
830
 
841
 
831
        $this->send_fake_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?', 0, $time + 9);
842
        testhelper::send_fake_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?', 0, $time + 9);
832
        $this->send_fake_message($user4, $user1, 'Yah brah, it\'s pretty rad.', 0, $time + 10);
843
        testhelper::send_fake_message($user4, $user1, 'Yah brah, it\'s pretty rad.', 0, $time + 10);
Línea 833... Línea 844...
833
        $messageid3 = $this->send_fake_message($user1, $user4, 'Dope.', 0, $time + 11);
844
        $messageid3 = testhelper::send_fake_message($user1, $user4, 'Dope.', 0, $time + 11);
834
 
845
 
835
        // Favourite the all conversations for user1.
846
        // Favourite the all conversations for user1.
836
        $convoids = [];
847
        $convoids = [];
Línea 855... Línea 866...
855
    }
866
    }
Línea 856... Línea 867...
856
 
867
 
857
    /**
868
    /**
858
     * Tests retrieving favourite conversations when a conversation contains a deleted user.
869
     * Tests retrieving favourite conversations when a conversation contains a deleted user.
859
     */
870
     */
-
 
871
    public function test_get_favourite_conversations_with_deleted_user(): void {
-
 
872
        $this->resetAfterTest();
860
    public function test_get_favourite_conversations_with_deleted_user() {
873
 
861
        // Create some users.
874
        // Create some users.
862
        $user1 = self::getDataGenerator()->create_user();
875
        $user1 = self::getDataGenerator()->create_user();
863
        $user2 = self::getDataGenerator()->create_user();
876
        $user2 = self::getDataGenerator()->create_user();
Línea 864... Línea 877...
864
        $user3 = self::getDataGenerator()->create_user();
877
        $user3 = self::getDataGenerator()->create_user();
865
 
878
 
866
        // Send some messages back and forth, have some different conversations with different users.
879
        // Send some messages back and forth, have some different conversations with different users.
867
        $time = 1;
880
        $time = 1;
868
        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
881
        testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
869
        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
882
        testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
870
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
883
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
871
        $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
884
        testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
872
 
885
 
873
        $this->send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
886
        testhelper::send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
874
        $this->send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
887
        testhelper::send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
Línea 875... Línea 888...
875
        $this->send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
888
        testhelper::send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
876
        $this->send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
889
        testhelper::send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
877
 
890
 
878
        // Favourite the all conversations for user1.
891
        // Favourite the all conversations for user1.
Línea 901... Línea 914...
901
    }
914
    }
Línea 902... Línea 915...
902
 
915
 
903
    /**
916
    /**
904
     * Test confirming that conversations can be marked as favourites.
917
     * Test confirming that conversations can be marked as favourites.
905
     */
918
     */
-
 
919
    public function test_set_favourite_conversation(): void {
-
 
920
        $this->resetAfterTest();
906
    public function test_set_favourite_conversation() {
921
 
907
        // Create some users.
922
        // Create some users.
908
        $user1 = self::getDataGenerator()->create_user();
923
        $user1 = self::getDataGenerator()->create_user();
909
        $user2 = self::getDataGenerator()->create_user();
924
        $user2 = self::getDataGenerator()->create_user();
Línea 910... Línea 925...
910
        $user3 = self::getDataGenerator()->create_user();
925
        $user3 = self::getDataGenerator()->create_user();
911
 
926
 
912
        // Send some messages back and forth, have some different conversations with different users.
927
        // Send some messages back and forth, have some different conversations with different users.
913
        $time = 1;
928
        $time = 1;
914
        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
929
        testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
915
        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
930
        testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
916
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
931
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
917
        $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
932
        testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
918
 
933
 
919
        $this->send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
934
        testhelper::send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
920
        $this->send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
935
        testhelper::send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
Línea 921... Línea 936...
921
        $this->send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
936
        testhelper::send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
922
        $this->send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
937
        testhelper::send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
923
 
938
 
Línea 939... Línea 954...
939
    }
954
    }
Línea 940... Línea 955...
940
 
955
 
941
    /**
956
    /**
942
     * Test verifying that trying to mark a non-existent conversation as a favourite, results in an exception.
957
     * Test verifying that trying to mark a non-existent conversation as a favourite, results in an exception.
943
     */
958
     */
-
 
959
    public function test_set_favourite_conversation_nonexistent_conversation(): void {
-
 
960
        $this->resetAfterTest();
944
    public function test_set_favourite_conversation_nonexistent_conversation() {
961
 
945
        // Create some users.
962
        // Create some users.
946
        $user1 = self::getDataGenerator()->create_user();
963
        $user1 = self::getDataGenerator()->create_user();
947
        // Try to favourite a non-existent conversation.
964
        // Try to favourite a non-existent conversation.
948
        $this->expectException(\moodle_exception::class);
965
        $this->expectException(\moodle_exception::class);
949
        api::set_favourite_conversation(0, $user1->id);
966
        api::set_favourite_conversation(0, $user1->id);
Línea 950... Línea 967...
950
    }
967
    }
951
 
968
 
952
    /**
969
    /**
953
     * Test verifying that a conversation cannot be marked as favourite unless the user is a member of that conversation.
970
     * Test verifying that a conversation cannot be marked as favourite unless the user is a member of that conversation.
-
 
971
     */
-
 
972
    public function test_set_favourite_conversation_non_member(): void {
954
     */
973
        $this->resetAfterTest();
955
    public function test_set_favourite_conversation_non_member() {
974
 
956
        // Create some users.
975
        // Create some users.
957
        $user1 = self::getDataGenerator()->create_user();
976
        $user1 = self::getDataGenerator()->create_user();
Línea 958... Línea 977...
958
        $user2 = self::getDataGenerator()->create_user();
977
        $user2 = self::getDataGenerator()->create_user();
959
        $user3 = self::getDataGenerator()->create_user();
978
        $user3 = self::getDataGenerator()->create_user();
960
 
979
 
961
        // Send some messages back and forth, have some different conversations with different users.
980
        // Send some messages back and forth, have some different conversations with different users.
962
        $time = 1;
981
        $time = 1;
963
        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
982
        testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
964
        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
983
        testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
965
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
984
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
966
        $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
985
        testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
967
 
986
 
968
        $this->send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
987
        testhelper::send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
Línea 969... Línea 988...
969
        $this->send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
988
        testhelper::send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
970
        $this->send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
989
        testhelper::send_fake_message($user1, $user3, 'Nothing.', 0, $time + 7);
971
        $this->send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
990
        testhelper::send_fake_message($user3, $user1, 'Cool.', 0, $time + 8);
972
 
991
 
973
        // Try to favourite the first conversation as user 3, who is not a member.
992
        // Try to favourite the first conversation as user 3, who is not a member.
Línea 974... Línea 993...
974
        $conversationid1 = api::get_conversation_between_users([$user1->id, $user2->id]);
993
        $conversationid1 = api::get_conversation_between_users([$user1->id, $user2->id]);
975
        $this->expectException(\moodle_exception::class);
994
        $this->expectException(\moodle_exception::class);
976
        api::set_favourite_conversation($conversationid1, $user3->id);
995
        api::set_favourite_conversation($conversationid1, $user3->id);
977
    }
996
    }
-
 
997
 
-
 
998
    /**
978
 
999
     * Test confirming that those conversations marked as favourites can be unfavourited.
979
    /**
1000
     */
980
     * Test confirming that those conversations marked as favourites can be unfavourited.
1001
    public function test_unset_favourite_conversation(): void {
981
     */
1002
        $this->resetAfterTest();
Línea 982... Línea 1003...
982
    public function test_unset_favourite_conversation() {
1003
 
983
        // Create some users.
1004
        // Create some users.
984
        $user1 = self::getDataGenerator()->create_user();
1005
        $user1 = self::getDataGenerator()->create_user();
985
        $user2 = self::getDataGenerator()->create_user();
1006
        $user2 = self::getDataGenerator()->create_user();
986
        $user3 = self::getDataGenerator()->create_user();
1007
        $user3 = self::getDataGenerator()->create_user();
987
 
1008
 
988
        // Send some messages back and forth, have some different conversations with different users.
1009
        // Send some messages back and forth, have some different conversations with different users.
989
        $time = 1;
1010
        $time = 1;
990
        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
1011
        testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
991
        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
1012
        testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
992
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
1013
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
Línea 993... Línea 1014...
993
        $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
1014
        testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
994
 
1015
 
995
        $this->send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
1016
        testhelper::send_fake_message($user1, $user3, 'Booyah', 0, $time + 5);
996
        $this->send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
1017
        testhelper::send_fake_message($user3, $user1, 'Whaaat?', 0, $time + 6);
Línea 1020... Línea 1041...
1020
    }
1041
    }
Línea 1021... Línea 1042...
1021
 
1042
 
1022
    /**
1043
    /**
1023
     * Test verifying that a valid conversation cannot be unset as a favourite if it's not marked as a favourite.
1044
     * Test verifying that a valid conversation cannot be unset as a favourite if it's not marked as a favourite.
1024
     */
1045
     */
-
 
1046
    public function test_unset_favourite_conversation_not_favourite(): void {
-
 
1047
        $this->resetAfterTest();
1025
    public function test_unset_favourite_conversation_not_favourite() {
1048
 
1026
        // Create some users.
1049
        // Create some users.
1027
        $user1 = self::getDataGenerator()->create_user();
1050
        $user1 = self::getDataGenerator()->create_user();
Línea 1028... Línea 1051...
1028
        $user2 = self::getDataGenerator()->create_user();
1051
        $user2 = self::getDataGenerator()->create_user();
1029
 
1052
 
1030
        // Send some messages back and forth, have some different conversations with different users.
1053
        // Send some messages back and forth, have some different conversations with different users.
1031
        $time = 1;
1054
        $time = 1;
1032
        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
1055
        testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
1033
        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
1056
        testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
Línea 1034... Línea 1057...
1034
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
1057
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
1035
        $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
1058
        testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
1036
 
1059
 
1037
        // Now try to unfavourite the conversation as user 1.
1060
        // Now try to unfavourite the conversation as user 1.
1038
        $conversationid1 = api::get_conversation_between_users([$user1->id, $user2->id]);
1061
        $conversationid1 = api::get_conversation_between_users([$user1->id, $user2->id]);
Línea 1039... Línea 1062...
1039
        $this->expectException(\moodle_exception::class);
1062
        $this->expectException(\moodle_exception::class);
1040
        api::unset_favourite_conversation($conversationid1, $user1->id);
1063
        api::unset_favourite_conversation($conversationid1, $user1->id);
1041
    }
1064
    }
1042
 
1065
 
-
 
1066
    /**
-
 
1067
     * Test verifying that a non-existent conversation cannot be unset as a favourite.
1043
    /**
1068
     */
1044
     * Test verifying that a non-existent conversation cannot be unset as a favourite.
1069
    public function test_unset_favourite_conversation_non_existent_conversation(): void {
Línea 1045... Línea 1070...
1045
     */
1070
        $this->resetAfterTest();
1046
    public function test_unset_favourite_conversation_non_existent_conversation() {
1071
 
Línea 1123... Línea 1148...
1123
    }
1148
    }
Línea 1124... Línea 1149...
1124
 
1149
 
1125
    /**
1150
    /**
1126
     * Test verifying get_conversations when no limits, offsets, type filters or favourite restrictions are used.
1151
     * Test verifying get_conversations when no limits, offsets, type filters or favourite restrictions are used.
1127
     */
1152
     */
-
 
1153
    public function test_get_conversations_no_restrictions(): void {
-
 
1154
        $this->resetAfterTest();
1128
    public function test_get_conversations_no_restrictions() {
1155
 
Línea 1129... Línea 1156...
1129
        global $DB;
1156
        global $DB;
1130
 
1157
 
1131
        $user1 = self::getDataGenerator()->create_user();
1158
        $user1 = self::getDataGenerator()->create_user();
Línea 1247... Línea 1274...
1247
    }
1274
    }
Línea 1248... Línea 1275...
1248
 
1275
 
1249
    /**
1276
    /**
1250
     * Test verifying that html format messages are supported, and that message_format_message_text() is being called appropriately.
1277
     * Test verifying that html format messages are supported, and that message_format_message_text() is being called appropriately.
1251
     */
1278
     */
1252
    public function test_get_conversations_message_format() {
1279
    public function test_get_conversations_message_format(): void {
-
 
1280
        global $DB;
-
 
1281
        $this->resetAfterTest();
1253
        global $DB;
1282
 
1254
        // Create some users.
1283
        // Create some users.
1255
        $user1 = self::getDataGenerator()->create_user();
1284
        $user1 = self::getDataGenerator()->create_user();
Línea 1256... Línea 1285...
1256
        $user2 = self::getDataGenerator()->create_user();
1285
        $user2 = self::getDataGenerator()->create_user();
Línea 1275... Línea 1304...
1275
    }
1304
    }
Línea 1276... Línea 1305...
1276
 
1305
 
1277
    /**
1306
    /**
1278
     * Test verifying get_conversations identifies if a conversation is muted or not.
1307
     * Test verifying get_conversations identifies if a conversation is muted or not.
1279
     */
1308
     */
-
 
1309
    public function test_get_conversations_some_muted(): void {
-
 
1310
        $this->resetAfterTest();
1280
    public function test_get_conversations_some_muted() {
1311
 
1281
        // Create some users.
1312
        // Create some users.
1282
        $user1 = self::getDataGenerator()->create_user();
1313
        $user1 = self::getDataGenerator()->create_user();
1283
        $user2 = self::getDataGenerator()->create_user();
1314
        $user2 = self::getDataGenerator()->create_user();
Línea 1321... Línea 1352...
1321
    }
1352
    }
Línea 1322... Línea 1353...
1322
 
1353
 
1323
    /**
1354
    /**
1324
     * Tests retrieving conversations with a limit and offset to ensure pagination works correctly.
1355
     * Tests retrieving conversations with a limit and offset to ensure pagination works correctly.
1325
     */
1356
     */
-
 
1357
    public function test_get_conversations_limit_offset(): void {
-
 
1358
        $this->resetAfterTest();
1326
    public function test_get_conversations_limit_offset() {
1359
 
1327
        // Get a bunch of conversations, some group, some individual and in different states.
1360
        // Get a bunch of conversations, some group, some individual and in different states.
1328
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
1361
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 1329... Línea 1362...
1329
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
1362
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 1360... Línea 1393...
1360
    }
1393
    }
Línea 1361... Línea 1394...
1361
 
1394
 
1362
    /**
1395
    /**
1363
     * Test verifying the type filtering behaviour of the
1396
     * Test verifying the type filtering behaviour of the
1364
     */
1397
     */
-
 
1398
    public function test_get_conversations_type_filter(): void {
-
 
1399
        $this->resetAfterTest();
1365
    public function test_get_conversations_type_filter() {
1400
 
1366
        // Get a bunch of conversations, some group, some individual and in different states.
1401
        // Get a bunch of conversations, some group, some individual and in different states.
1367
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
1402
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 1368... Línea 1403...
1368
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
1403
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 1383... Línea 1418...
1383
    }
1418
    }
Línea 1384... Línea 1419...
1384
 
1419
 
1385
    /**
1420
    /**
1386
     * Tests retrieving conversations when a 'self' conversation exists.
1421
     * Tests retrieving conversations when a 'self' conversation exists.
1387
     */
1422
     */
1388
    public function test_get_conversations_self_conversations() {
1423
    public function test_get_conversations_self_conversations(): void {
-
 
1424
        global $DB;
-
 
1425
        $this->resetAfterTest();
Línea 1389... Línea 1426...
1389
        global $DB;
1426
 
1390
 
1427
 
1391
        // Create a conversation between one user and themself.
1428
        // Create a conversation between one user and themself.
1392
        $user1 = self::getDataGenerator()->create_user();
1429
        $user1 = self::getDataGenerator()->create_user();
Línea 1444... Línea 1481...
1444
    }
1481
    }
Línea 1445... Línea 1482...
1445
 
1482
 
1446
    /**
1483
    /**
1447
     * Tests retrieving conversations when a conversation contains a deleted user.
1484
     * Tests retrieving conversations when a conversation contains a deleted user.
1448
     */
1485
     */
-
 
1486
    public function test_get_conversations_with_deleted_user(): void {
-
 
1487
        $this->resetAfterTest();
1449
    public function test_get_conversations_with_deleted_user() {
1488
 
1450
        // Get a bunch of conversations, some group, some individual and in different states.
1489
        // Get a bunch of conversations, some group, some individual and in different states.
1451
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
1490
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 1452... Línea 1491...
1452
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
1491
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 1501... Línea 1540...
1501
    }
1540
    }
Línea 1502... Línea 1541...
1502
 
1541
 
1503
    /**
1542
    /**
1504
     * Test confirming the behaviour of get_conversations() when users delete all messages.
1543
     * Test confirming the behaviour of get_conversations() when users delete all messages.
1505
     */
1544
     */
-
 
1545
    public function test_get_conversations_deleted_messages(): void {
-
 
1546
        $this->resetAfterTest();
1506
    public function test_get_conversations_deleted_messages() {
1547
 
1507
        // Get a bunch of conversations, some group, some individual and in different states.
1548
        // Get a bunch of conversations, some group, some individual and in different states.
1508
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
1549
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 1509... Línea 1550...
1509
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
1550
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 1539... Línea 1580...
1539
 
1580
 
1540
    /**
1581
    /**
1541
     * Test verifying the behaviour of get_conversations() when fetching favourite conversations with only a single
1582
     * Test verifying the behaviour of get_conversations() when fetching favourite conversations with only a single
1542
     * favourite.
1583
     * favourite.
1543
     */
1584
     */
-
 
1585
    public function test_get_conversations_favourite_conversations_single(): void {
-
 
1586
        $this->resetAfterTest();
1544
    public function test_get_conversations_favourite_conversations_single() {
1587
 
1545
        // Get a bunch of conversations, some group, some individual and in different states.
1588
        // Get a bunch of conversations, some group, some individual and in different states.
1546
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
1589
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 1547... Línea 1590...
1547
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
1590
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 1588... Línea 1631...
1588
    }
1631
    }
Línea 1589... Línea 1632...
1589
 
1632
 
1590
    /**
1633
    /**
1591
     * Test verifying the behaviour of get_conversations() when fetching favourite conversations.
1634
     * Test verifying the behaviour of get_conversations() when fetching favourite conversations.
1592
     */
1635
     */
-
 
1636
    public function test_get_conversations_favourite_conversations(): void {
-
 
1637
        $this->resetAfterTest();
1593
    public function test_get_conversations_favourite_conversations() {
1638
 
1594
        // Get a bunch of conversations, some group, some individual and in different states.
1639
        // Get a bunch of conversations, some group, some individual and in different states.
1595
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
1640
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 1596... Línea 1641...
1596
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
1641
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 1654... Línea 1699...
1654
    /**
1699
    /**
1655
     * Test verifying get_conversations when there are users in a group and/or individual conversation. The reason this
1700
     * Test verifying get_conversations when there are users in a group and/or individual conversation. The reason this
1656
     * test is performed is because we do not need as much data for group conversations (saving DB calls), so we want
1701
     * test is performed is because we do not need as much data for group conversations (saving DB calls), so we want
1657
     * to confirm this happens.
1702
     * to confirm this happens.
1658
     */
1703
     */
1659
    public function test_get_conversations_user_in_group_and_individual_chat() {
1704
    public function test_get_conversations_user_in_group_and_individual_chat(): void {
-
 
1705
        $this->resetAfterTest();
-
 
1706
 
1660
        $this->resetAfterTest();
1707
        $this->resetAfterTest();
Línea 1661... Línea 1708...
1661
 
1708
 
1662
        $user1 = self::getDataGenerator()->create_user();
1709
        $user1 = self::getDataGenerator()->create_user();
1663
        $user2 = self::getDataGenerator()->create_user();
1710
        $user2 = self::getDataGenerator()->create_user();
Línea 1711... Línea 1758...
1711
    }
1758
    }
Línea 1712... Línea 1759...
1712
 
1759
 
1713
    /**
1760
    /**
1714
     * Test verifying that group linked conversations are returned and contain a subname matching the course name.
1761
     * Test verifying that group linked conversations are returned and contain a subname matching the course name.
1715
     */
1762
     */
1716
    public function test_get_conversations_group_linked() {
1763
    public function test_get_conversations_group_linked(): void {
-
 
1764
        global $CFG, $DB;
-
 
1765
        $this->resetAfterTest();
Línea 1717... Línea 1766...
1717
        global $CFG, $DB;
1766
 
1718
 
1767
 
1719
        // Create some users.
1768
        // Create some users.
1720
        $user1 = self::getDataGenerator()->create_user();
1769
        $user1 = self::getDataGenerator()->create_user();
Línea 2066... Línea 2115...
2066
    }
2115
    }
Línea 2067... Línea 2116...
2067
 
2116
 
2068
    /**
2117
    /**
2069
     * Test that creation can't create the same conversation twice for 1:1 conversations.
2118
     * Test that creation can't create the same conversation twice for 1:1 conversations.
2070
     */
2119
     */
2071
    public function test_create_conversation_duplicate_conversations() {
2120
    public function test_create_conversation_duplicate_conversations(): void {
-
 
2121
        global $DB;
-
 
2122
        $this->resetAfterTest();
2072
        global $DB;
2123
 
Línea 2073... Línea 2124...
2073
        $user1 = $this::getDataGenerator()->create_user();
2124
        $user1 = $this::getDataGenerator()->create_user();
2074
 
2125
 
Línea 2087... Línea 2138...
2087
     * @dataProvider get_conversations_mixed_provider
2138
     * @dataProvider get_conversations_mixed_provider
2088
     * @param array $usersdata The list of users to create for this test.
2139
     * @param array $usersdata The list of users to create for this test.
2089
     * @param array $messagesdata The list of messages to create.
2140
     * @param array $messagesdata The list of messages to create.
2090
     * @param array $expectations The list of expected outcomes.
2141
     * @param array $expectations The list of expected outcomes.
2091
     */
2142
     */
2092
    public function test_get_conversations_mixed($usersdata, $contacts, $messagesdata, $expectations) {
2143
    public function test_get_conversations_mixed($usersdata, $contacts, $messagesdata, $expectations): void {
2093
        global $DB;
2144
        global $DB;
-
 
2145
        $this->resetAfterTest();
-
 
2146
 
-
 
2147
 
-
 
2148
        $this->redirectMessages();
Línea 2094... Línea 2149...
2094
 
2149
 
2095
        // Create all of the users.
2150
        // Create all of the users.
2096
        $users = array();
2151
        $users = array();
2097
        foreach ($usersdata as $username) {
2152
        foreach ($usersdata as $username) {
Línea 2113... Línea 2168...
2113
            $from       = $users[$messagedata['from']];
2168
            $from       = $users[$messagedata['from']];
2114
            $to         = $users[$messagedata['to']];
2169
            $to         = $users[$messagedata['to']];
2115
            $subject    = $messagedata['subject'];
2170
            $subject    = $messagedata['subject'];
Línea 2116... Línea 2171...
2116
 
2171
 
2117
            if (isset($messagedata['state']) && $messagedata['state'] == 'unread') {
2172
            if (isset($messagedata['state']) && $messagedata['state'] == 'unread') {
2118
                $messageid = $this->send_fake_message($from, $to, $subject);
2173
                $messageid = testhelper::send_fake_message($from, $to, $subject);
2119
            } else {
2174
            } else {
2120
                // If there is no state, or the state is not 'unread', assume the message is read.
2175
                // If there is no state, or the state is not 'unread', assume the message is read.
2121
                $messageid = message_post_message($from, $to, $subject, FORMAT_PLAIN);
2176
                $messageid = message_post_message($from, $to, $subject, FORMAT_PLAIN);
Línea 2149... Línea 2204...
2149
    }
2204
    }
Línea 2150... Línea 2205...
2150
 
2205
 
2151
    /**
2206
    /**
2152
     * Tests retrieving user contacts.
2207
     * Tests retrieving user contacts.
2153
     */
2208
     */
-
 
2209
    public function test_get_user_contacts(): void {
-
 
2210
        $this->resetAfterTest();
2154
    public function test_get_user_contacts() {
2211
 
2155
        // Create some users.
2212
        // Create some users.
Línea 2156... Línea 2213...
2156
        $user1 = self::getDataGenerator()->create_user();
2213
        $user1 = self::getDataGenerator()->create_user();
2157
 
2214
 
Línea 2209... Línea 2266...
2209
    }
2266
    }
Línea 2210... Línea 2267...
2210
 
2267
 
2211
    /**
2268
    /**
2212
     * Tests retrieving conversation messages.
2269
     * Tests retrieving conversation messages.
2213
     */
2270
     */
-
 
2271
    public function test_get_conversation_messages(): void {
-
 
2272
        $this->resetAfterTest();
2214
    public function test_get_conversation_messages() {
2273
 
2215
        // Create some users.
2274
        // Create some users.
2216
        $user1 = self::getDataGenerator()->create_user();
2275
        $user1 = self::getDataGenerator()->create_user();
Línea 2217... Línea 2276...
2217
        $user2 = self::getDataGenerator()->create_user();
2276
        $user2 = self::getDataGenerator()->create_user();
Línea 2264... Línea 2323...
2264
    }
2323
    }
Línea 2265... Línea 2324...
2265
 
2324
 
2266
    /**
2325
    /**
2267
     * Tests retrieving group conversation messages.
2326
     * Tests retrieving group conversation messages.
2268
     */
2327
     */
-
 
2328
    public function test_get_group_conversation_messages(): void {
-
 
2329
        $this->resetAfterTest();
2269
    public function test_get_group_conversation_messages() {
2330
 
2270
        // Create some users.
2331
        // Create some users.
2271
        $user1 = self::getDataGenerator()->create_user();
2332
        $user1 = self::getDataGenerator()->create_user();
2272
        $user2 = self::getDataGenerator()->create_user();
2333
        $user2 = self::getDataGenerator()->create_user();
2273
        $user3 = self::getDataGenerator()->create_user();
2334
        $user3 = self::getDataGenerator()->create_user();
Línea 2327... Línea 2388...
2327
    }
2388
    }
Línea 2328... Línea 2389...
2328
 
2389
 
2329
    /**
2390
    /**
2330
     * Test verifying the sorting param for get_conversation_messages is respected().
2391
     * Test verifying the sorting param for get_conversation_messages is respected().
2331
     */
2392
     */
-
 
2393
    public function test_get_conversation_messages_sorting(): void {
-
 
2394
        $this->resetAfterTest();
2332
    public function test_get_conversation_messages_sorting() {
2395
 
2333
        // Create some users.
2396
        // Create some users.
2334
        $user1 = self::getDataGenerator()->create_user();
2397
        $user1 = self::getDataGenerator()->create_user();
2335
        $user2 = self::getDataGenerator()->create_user();
2398
        $user2 = self::getDataGenerator()->create_user();
Línea 2394... Línea 2457...
2394
    }
2457
    }
Línea 2395... Línea 2458...
2395
 
2458
 
2396
    /**
2459
    /**
2397
     * Test retrieving conversation messages by providing a minimum timecreated value.
2460
     * Test retrieving conversation messages by providing a minimum timecreated value.
2398
     */
2461
     */
-
 
2462
    public function test_get_conversation_messages_time_from_only(): void {
-
 
2463
        $this->resetAfterTest();
2399
    public function test_get_conversation_messages_time_from_only() {
2464
 
2400
        // Create some users.
2465
        // Create some users.
2401
        $user1 = self::getDataGenerator()->create_user();
2466
        $user1 = self::getDataGenerator()->create_user();
2402
        $user2 = self::getDataGenerator()->create_user();
2467
        $user2 = self::getDataGenerator()->create_user();
2403
        $user3 = self::getDataGenerator()->create_user();
2468
        $user3 = self::getDataGenerator()->create_user();
Línea 2466... Línea 2531...
2466
    }
2531
    }
Línea 2467... Línea 2532...
2467
 
2532
 
2468
    /**
2533
    /**
2469
     * Test retrieving conversation messages by providing a maximum timecreated value.
2534
     * Test retrieving conversation messages by providing a maximum timecreated value.
2470
     */
2535
     */
-
 
2536
    public function test_get_conversation_messages_time_to_only(): void {
-
 
2537
        $this->resetAfterTest();
2471
    public function test_get_conversation_messages_time_to_only() {
2538
 
2472
        // Create some users.
2539
        // Create some users.
2473
        $user1 = self::getDataGenerator()->create_user();
2540
        $user1 = self::getDataGenerator()->create_user();
2474
        $user2 = self::getDataGenerator()->create_user();
2541
        $user2 = self::getDataGenerator()->create_user();
2475
        $user3 = self::getDataGenerator()->create_user();
2542
        $user3 = self::getDataGenerator()->create_user();
Línea 2539... Línea 2606...
2539
    }
2606
    }
Línea 2540... Línea 2607...
2540
 
2607
 
2541
    /**
2608
    /**
2542
     * Test retrieving conversation messages by providing a minimum and maximum timecreated value.
2609
     * Test retrieving conversation messages by providing a minimum and maximum timecreated value.
2543
     */
2610
     */
-
 
2611
    public function test_get_conversation_messages_time_from_and_to(): void {
-
 
2612
        $this->resetAfterTest();
2544
    public function test_get_conversation_messages_time_from_and_to() {
2613
 
2545
        // Create some users.
2614
        // Create some users.
2546
        $user1 = self::getDataGenerator()->create_user();
2615
        $user1 = self::getDataGenerator()->create_user();
2547
        $user2 = self::getDataGenerator()->create_user();
2616
        $user2 = self::getDataGenerator()->create_user();
2548
        $user3 = self::getDataGenerator()->create_user();
2617
        $user3 = self::getDataGenerator()->create_user();
Línea 2588... Línea 2657...
2588
 
2657
 
2589
 
2658
 
2590
    /**
2659
    /**
2591
     * Test retrieving conversation messages by providing a limitfrom value.
2660
     * Test retrieving conversation messages by providing a limitfrom value.
-
 
2661
     */
-
 
2662
    public function test_get_conversation_messages_limitfrom_only(): void {
2592
     */
2663
        $this->resetAfterTest();
2593
    public function test_get_conversation_messages_limitfrom_only() {
2664
 
2594
        // Create some users.
2665
        // Create some users.
2595
        $user1 = self::getDataGenerator()->create_user();
2666
        $user1 = self::getDataGenerator()->create_user();
2596
        $user2 = self::getDataGenerator()->create_user();
2667
        $user2 = self::getDataGenerator()->create_user();
Línea 2635... Línea 2706...
2635
    }
2706
    }
Línea 2636... Línea 2707...
2636
 
2707
 
2637
    /**
2708
    /**
2638
     * Test retrieving conversation messages by providing a limitnum value.
2709
     * Test retrieving conversation messages by providing a limitnum value.
2639
     */
2710
     */
-
 
2711
    public function test_get_conversation_messages_limitnum(): void {
-
 
2712
        $this->resetAfterTest();
2640
    public function test_get_conversation_messages_limitnum() {
2713
 
2641
        // Create some users.
2714
        // Create some users.
2642
        $user1 = self::getDataGenerator()->create_user();
2715
        $user1 = self::getDataGenerator()->create_user();
2643
        $user2 = self::getDataGenerator()->create_user();
2716
        $user2 = self::getDataGenerator()->create_user();
2644
        $user3 = self::getDataGenerator()->create_user();
2717
        $user3 = self::getDataGenerator()->create_user();
Línea 2681... Línea 2754...
2681
    }
2754
    }
Línea 2682... Línea 2755...
2682
 
2755
 
2683
    /**
2756
    /**
2684
     * Tests retrieving most recent conversation message.
2757
     * Tests retrieving most recent conversation message.
2685
     */
2758
     */
-
 
2759
    public function test_get_most_recent_conversation_message(): void {
-
 
2760
        $this->resetAfterTest();
2686
    public function test_get_most_recent_conversation_message() {
2761
 
2687
        // Create some users.
2762
        // Create some users.
2688
        $user1 = self::getDataGenerator()->create_user();
2763
        $user1 = self::getDataGenerator()->create_user();
2689
        $user2 = self::getDataGenerator()->create_user();
2764
        $user2 = self::getDataGenerator()->create_user();
Línea 2714... Línea 2789...
2714
    }
2789
    }
Línea 2715... Línea 2790...
2715
 
2790
 
2716
    /**
2791
    /**
2717
     * Tests checking if a user can mark all messages as read.
2792
     * Tests checking if a user can mark all messages as read.
2718
     */
2793
     */
-
 
2794
    public function test_can_mark_all_messages_as_read(): void {
-
 
2795
        $this->resetAfterTest();
2719
    public function test_can_mark_all_messages_as_read() {
2796
 
2720
        // Set as the admin.
2797
        // Set as the admin.
Línea 2721... Línea 2798...
2721
        $this->setAdminUser();
2798
        $this->setAdminUser();
2722
 
2799
 
2723
        // Create some users.
2800
        // Create some users.
2724
        $user1 = self::getDataGenerator()->create_user();
2801
        $user1 = self::getDataGenerator()->create_user();
Línea 2725... Línea 2802...
2725
        $user2 = self::getDataGenerator()->create_user();
2802
        $user2 = self::getDataGenerator()->create_user();
2726
        $user3 = self::getDataGenerator()->create_user();
2803
        $user3 = self::getDataGenerator()->create_user();
2727
 
2804
 
2728
        // Send some messages back and forth.
2805
        // Send some messages back and forth.
2729
        $time = 1;
2806
        $time = 1;
2730
        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
2807
        testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
Línea 2731... Línea 2808...
2731
        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
2808
        testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
Línea 2732... Línea 2809...
2732
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
2809
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
2733
        $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
2810
        testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
Línea 2751... Línea 2828...
2751
    }
2828
    }
Línea 2752... Línea 2829...
2752
 
2829
 
2753
    /**
2830
    /**
2754
     * Tests checking if a user can delete a conversation.
2831
     * Tests checking if a user can delete a conversation.
2755
     */
2832
     */
-
 
2833
    public function test_can_delete_conversation(): void {
-
 
2834
        $this->resetAfterTest();
2756
    public function test_can_delete_conversation() {
2835
 
2757
        // Set as the admin.
2836
        // Set as the admin.
Línea 2758... Línea 2837...
2758
        $this->setAdminUser();
2837
        $this->setAdminUser();
2759
 
2838
 
2760
        // Create some users.
2839
        // Create some users.
Línea 2761... Línea 2840...
2761
        $user1 = self::getDataGenerator()->create_user();
2840
        $user1 = self::getDataGenerator()->create_user();
2762
        $user2 = self::getDataGenerator()->create_user();
2841
        $user2 = self::getDataGenerator()->create_user();
2763
 
2842
 
2764
        // Send some messages back and forth.
2843
        // Send some messages back and forth.
2765
        $time = 1;
2844
        $time = 1;
2766
        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
2845
        testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
Línea 2767... Línea 2846...
2767
        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
2846
        testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
Línea 2768... Línea 2847...
2768
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
2847
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
2769
        $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
2848
        testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
Línea 2784... Línea 2863...
2784
    }
2863
    }
Línea 2785... Línea 2864...
2785
 
2864
 
2786
    /**
2865
    /**
2787
     * Tests deleting a conversation by conversation id.
2866
     * Tests deleting a conversation by conversation id.
2788
     */
2867
     */
2789
    public function test_delete_conversation_by_id() {
2868
    public function test_delete_conversation_by_id(): void {
-
 
2869
        global $DB;
-
 
2870
        $this->resetAfterTest();
Línea 2790... Línea 2871...
2790
        global $DB;
2871
 
2791
 
2872
 
2792
        // Create some users.
2873
        // Create some users.
Línea 2800... Línea 2881...
2800
        $sc1 = api::get_self_conversation($user1->id);
2881
        $sc1 = api::get_self_conversation($user1->id);
2801
        $sc2 = api::get_self_conversation($user2->id);
2882
        $sc2 = api::get_self_conversation($user2->id);
Línea 2802... Línea 2883...
2802
 
2883
 
2803
        // Send some messages back and forth.
2884
        // Send some messages back and forth.
2804
        $time = 1;
2885
        $time = 1;
2805
        $m1id = $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
2886
        $m1id = testhelper::send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
2806
        $m2id = $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
2887
        $m2id = testhelper::send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
2807
        $m3id = $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
2888
        $m3id = testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
2808
        $m4id = $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
2889
        $m4id = testhelper::send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
2809
        $m5id = testhelper::send_fake_message_to_conversation($user1, $sc1->id, 'Hi to myself!', $time + 5);
2890
        $m5id = testhelper::send_fake_message_to_conversation($user1, $sc1->id, 'Hi to myself!', $time + 5);
Línea 2810... Línea 2891...
2810
        $m6id = testhelper::send_fake_message_to_conversation($user2, $sc2->id, 'I am talking with myself', $time + 6);
2891
        $m6id = testhelper::send_fake_message_to_conversation($user2, $sc2->id, 'I am talking with myself', $time + 6);
Línea 2862... Línea 2943...
2862
    }
2943
    }
Línea 2863... Línea 2944...
2863
 
2944
 
2864
    /**
2945
    /**
2865
     * Tests counting unread conversations.
2946
     * Tests counting unread conversations.
2866
     */
2947
     */
2867
    public function test_count_unread_conversations() {
2948
    public function test_count_unread_conversations(): void {
Línea 2868... Línea 2949...
2868
        $this->resetAfterTest(true);
2949
        $this->resetAfterTest(true);
2869
 
2950
 
2870
        // Create some users.
2951
        // Create some users.
Línea 2875... Línea 2956...
2875
 
2956
 
2876
        // The person wanting the conversation count.
2957
        // The person wanting the conversation count.
Línea 2877... Línea 2958...
2877
        $this->setUser($user1);
2958
        $this->setUser($user1);
2878
 
2959
 
2879
        // Send some messages back and forth, have some different conversations with different users.
2960
        // Send some messages back and forth, have some different conversations with different users.
2880
        $this->send_fake_message($user1, $user2, 'Yo!');
2961
        testhelper::send_fake_message($user1, $user2, 'Yo!');
2881
        $this->send_fake_message($user2, $user1, 'Sup mang?');
2962
        testhelper::send_fake_message($user2, $user1, 'Sup mang?');
2882
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!');
2963
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!');
2883
        $this->send_fake_message($user2, $user1, 'Word.');
2964
        testhelper::send_fake_message($user2, $user1, 'Word.');
2884
 
2965
 
2885
        $this->send_fake_message($user1, $user3, 'Booyah');
2966
        testhelper::send_fake_message($user1, $user3, 'Booyah');
2886
        $this->send_fake_message($user3, $user1, 'Whaaat?');
2967
        testhelper::send_fake_message($user3, $user1, 'Whaaat?');
2887
        $this->send_fake_message($user1, $user3, 'Nothing.');
2968
        testhelper::send_fake_message($user1, $user3, 'Nothing.');
2888
        $this->send_fake_message($user3, $user1, 'Cool.');
2969
        testhelper::send_fake_message($user3, $user1, 'Cool.');
2889
 
2970
 
2890
        $this->send_fake_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?');
2971
        testhelper::send_fake_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?');
Línea 2891... Línea 2972...
2891
        $this->send_fake_message($user4, $user1, 'Yah brah, it\'s pretty rad.');
2972
        testhelper::send_fake_message($user4, $user1, 'Yah brah, it\'s pretty rad.');
2892
        $this->send_fake_message($user1, $user4, 'Dope.');
2973
        testhelper::send_fake_message($user1, $user4, 'Dope.');
Línea 2893... Línea 2974...
2893
 
2974
 
Línea 2899... Línea 2980...
2899
    }
2980
    }
Línea 2900... Línea 2981...
2900
 
2981
 
2901
    /**
2982
    /**
2902
     * Tests counting unread conversations where one conversation is disabled.
2983
     * Tests counting unread conversations where one conversation is disabled.
2903
     */
2984
     */
2904
    public function test_count_unread_conversations_disabled() {
2985
    public function test_count_unread_conversations_disabled(): void {
Línea 2905... Línea 2986...
2905
        $this->resetAfterTest(true);
2986
        $this->resetAfterTest(true);
2906
 
2987
 
2907
        // Create some users.
2988
        // Create some users.
Línea 2912... Línea 2993...
2912
 
2993
 
2913
        // The person wanting the conversation count.
2994
        // The person wanting the conversation count.
Línea 2914... Línea 2995...
2914
        $this->setUser($user1);
2995
        $this->setUser($user1);
2915
 
2996
 
2916
        // Send some messages back and forth, have some different conversations with different users.
2997
        // Send some messages back and forth, have some different conversations with different users.
2917
        $this->send_fake_message($user1, $user2, 'Yo!');
2998
        testhelper::send_fake_message($user1, $user2, 'Yo!');
2918
        $this->send_fake_message($user2, $user1, 'Sup mang?');
2999
        testhelper::send_fake_message($user2, $user1, 'Sup mang?');
2919
        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!');
3000
        testhelper::send_fake_message($user1, $user2, 'Writing PHPUnit tests!');
2920
        $this->send_fake_message($user2, $user1, 'Word.');
3001
        testhelper::send_fake_message($user2, $user1, 'Word.');
2921
 
3002
 
2922
        $this->send_fake_message($user1, $user3, 'Booyah');
3003
        testhelper::send_fake_message($user1, $user3, 'Booyah');
2923
        $this->send_fake_message($user3, $user1, 'Whaaat?');
3004
        testhelper::send_fake_message($user3, $user1, 'Whaaat?');
2924
        $this->send_fake_message($user1, $user3, 'Nothing.');
3005
        testhelper::send_fake_message($user1, $user3, 'Nothing.');
2925
        $this->send_fake_message($user3, $user1, 'Cool.');
3006
        testhelper::send_fake_message($user3, $user1, 'Cool.');
2926
 
3007
 
2927
        $this->send_fake_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?');
3008
        testhelper::send_fake_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?');
Línea 2928... Línea 3009...
2928
        $this->send_fake_message($user4, $user1, 'Yah brah, it\'s pretty rad.');
3009
        testhelper::send_fake_message($user4, $user1, 'Yah brah, it\'s pretty rad.');
2929
        $this->send_fake_message($user1, $user4, 'Dope.');
3010
        testhelper::send_fake_message($user1, $user4, 'Dope.');
2930
 
3011
 
Línea 2937... Línea 3018...
2937
    }
3018
    }
Línea 2938... Línea 3019...
2938
 
3019
 
2939
    /**
3020
    /**
2940
     * Tests deleting a conversation.
3021
     * Tests deleting a conversation.
2941
     */
3022
     */
-
 
3023
    public function test_get_all_message_preferences(): void {
-
 
3024
        $this->resetAfterTest();
2942
    public function test_get_all_message_preferences() {
3025
 
2943
        $user = self::getDataGenerator()->create_user();
3026
        $user = self::getDataGenerator()->create_user();
Línea 2944... Línea 3027...
2944
        $this->setUser($user);
3027
        $this->setUser($user);
2945
 
3028
 
Línea 2956... Línea 3039...
2956
    }
3039
    }
Línea 2957... Línea 3040...
2957
 
3040
 
2958
    /**
3041
    /**
2959
     * Tests the user can send a message.
3042
     * Tests the user can send a message.
2960
     */
3043
     */
-
 
3044
    public function test_can_send_message(): void {
-
 
3045
        $this->resetAfterTest();
2961
    public function test_can_send_message() {
3046
 
2962
        // Create some users.
3047
        // Create some users.
2963
        $user1 = self::getDataGenerator()->create_user();
3048
        $user1 = self::getDataGenerator()->create_user();
Línea 2964... Línea 3049...
2964
        $user2 = self::getDataGenerator()->create_user();
3049
        $user2 = self::getDataGenerator()->create_user();
Línea 2978... Línea 3063...
2978
    }
3063
    }
Línea 2979... Línea 3064...
2979
 
3064
 
2980
    /**
3065
    /**
2981
     * Tests the user can't send a message without proper capability.
3066
     * Tests the user can't send a message without proper capability.
2982
     */
3067
     */
2983
    public function test_can_send_message_without_sendmessage_cap() {
3068
    public function test_can_send_message_without_sendmessage_cap(): void {
-
 
3069
        global $DB;
-
 
3070
        $this->resetAfterTest();
Línea 2984... Línea 3071...
2984
        global $DB;
3071
 
2985
 
3072
 
2986
        // Create some users.
3073
        // Create some users.
Línea 3000... Línea 3087...
3000
    }
3087
    }
Línea 3001... Línea 3088...
3001
 
3088
 
3002
    /**
3089
    /**
3003
     * Tests the user can send a message when they are contact.
3090
     * Tests the user can send a message when they are contact.
3004
     */
3091
     */
-
 
3092
    public function test_can_send_message_when_contact(): void {
-
 
3093
        $this->resetAfterTest();
3005
    public function test_can_send_message_when_contact() {
3094
 
3006
        // Create some users.
3095
        // Create some users.
3007
        $user1 = self::getDataGenerator()->create_user();
3096
        $user1 = self::getDataGenerator()->create_user();
Línea 3008... Línea 3097...
3008
        $user2 = self::getDataGenerator()->create_user();
3097
        $user2 = self::getDataGenerator()->create_user();
Línea 3022... Línea 3111...
3022
 
3111
 
3023
    /**
3112
    /**
3024
     * Tests the user can't send a message if they are not a contact and the user
3113
     * Tests the user can't send a message if they are not a contact and the user
3025
     * has requested messages only from contacts.
3114
     * has requested messages only from contacts.
3026
     */
3115
     */
-
 
3116
    public function test_can_send_message_when_not_contact(): void {
-
 
3117
        $this->resetAfterTest();
3027
    public function test_can_send_message_when_not_contact() {
3118
 
3028
        // Create some users.
3119
        // Create some users.
3029
        $user1 = self::getDataGenerator()->create_user();
3120
        $user1 = self::getDataGenerator()->create_user();
Línea 3030... Línea 3121...
3030
        $user2 = self::getDataGenerator()->create_user();
3121
        $user2 = self::getDataGenerator()->create_user();
Línea 3040... Línea 3131...
3040
    }
3131
    }
Línea 3041... Línea 3132...
3041
 
3132
 
3042
    /**
3133
    /**
3043
     * Tests the user can't send a message if they are blocked.
3134
     * Tests the user can't send a message if they are blocked.
3044
     */
3135
     */
-
 
3136
    public function test_can_send_message_when_blocked(): void {
-
 
3137
        $this->resetAfterTest();
3045
    public function test_can_send_message_when_blocked() {
3138
 
3046
        // Create some users.
3139
        // Create some users.
3047
        $user1 = self::getDataGenerator()->create_user();
3140
        $user1 = self::getDataGenerator()->create_user();
Línea 3048... Línea 3141...
3048
        $user2 = self::getDataGenerator()->create_user();
3141
        $user2 = self::getDataGenerator()->create_user();
Línea 3059... Línea 3152...
3059
 
3152
 
3060
    /**
3153
    /**
3061
     * Tests the user can send a message when site-wide messaging setting is enabled,
3154
     * Tests the user can send a message when site-wide messaging setting is enabled,
3062
     * even if they are not a contact and are not members of the same course.
3155
     * even if they are not a contact and are not members of the same course.
3063
     */
3156
     */
-
 
3157
    public function test_can_send_message_site_messaging_setting(): void {
-
 
3158
        $this->resetAfterTest();
3064
    public function test_can_send_message_site_messaging_setting() {
3159
 
3065
        // Create some users.
3160
        // Create some users.
3066
        $user1 = self::getDataGenerator()->create_user();
3161
        $user1 = self::getDataGenerator()->create_user();
Línea 3067... Línea 3162...
3067
        $user2 = self::getDataGenerator()->create_user();
3162
        $user2 = self::getDataGenerator()->create_user();
Línea 3107... Línea 3202...
3107
    }
3202
    }
Línea 3108... Línea 3203...
3108
 
3203
 
3109
    /**
3204
    /**
3110
     * Tests the user with the messageanyuser capability can send a message.
3205
     * Tests the user with the messageanyuser capability can send a message.
3111
     */
3206
     */
3112
    public function test_can_send_message_with_messageanyuser_cap() {
3207
    public function test_can_send_message_with_messageanyuser_cap(): void {
-
 
3208
        global $DB;
-
 
3209
        $this->resetAfterTest();
Línea 3113... Línea 3210...
3113
        global $DB;
3210
 
3114
 
3211
 
3115
        // Create some users.
3212
        // Create some users.
3116
        $teacher1 = self::getDataGenerator()->create_user();
3213
        $teacher1 = self::getDataGenerator()->create_user();
Línea 3151... Línea 3248...
3151
    }
3248
    }
Línea 3152... Línea 3249...
3152
 
3249
 
3153
    /**
3250
    /**
3154
     * Tests the user when blocked will not be able to send messages if they are blocked.
3251
     * Tests the user when blocked will not be able to send messages if they are blocked.
3155
     */
3252
     */
3156
    public function test_can_send_message_even_if_blocked() {
3253
    public function test_can_send_message_even_if_blocked(): void {
Línea 3157... Línea 3254...
3157
        $this->resetAfterTest();
3254
        $this->resetAfterTest();
3158
 
3255
 
Línea 3164... Línea 3261...
3164
 
3261
 
3165
    /**
3262
    /**
3166
     * Tests the user will be able to send a message even if they are blocked as the user
3263
     * Tests the user will be able to send a message even if they are blocked as the user
3167
     * has the capability 'moodle/site:messageanyuser'.
3264
     * has the capability 'moodle/site:messageanyuser'.
3168
     */
3265
     */
3169
    public function test_can_send_message_even_if_blocked_with_message_any_user_cap() {
3266
    public function test_can_send_message_even_if_blocked_with_message_any_user_cap(): void {
Línea 3170... Línea 3267...
3170
        global $DB;
3267
        global $DB;
Línea 3171... Línea 3268...
3171
 
3268
 
Línea 3182... Línea 3279...
3182
 
3279
 
3183
    /**
3280
    /**
3184
     * Tests the user will be able to send a message even if they are blocked as the user
3281
     * Tests the user will be able to send a message even if they are blocked as the user
3185
     * has the capability 'moodle/site:readallmessages'.
3282
     * has the capability 'moodle/site:readallmessages'.
3186
     */
3283
     */
3187
    public function test_can_send_message_even_if_blocked_with_read_all_message_cap() {
3284
    public function test_can_send_message_even_if_blocked_with_read_all_message_cap(): void {
Línea 3188... Línea 3285...
3188
        global $DB;
3285
        global $DB;
Línea 3189... Línea 3286...
3189
 
3286
 
Línea 3199... Línea 3296...
3199
    }
3296
    }
Línea 3200... Línea 3297...
3200
 
3297
 
3201
    /**
3298
    /**
3202
     * Tests the user can not always send a message if they are blocked just because they share a course.
3299
     * Tests the user can not always send a message if they are blocked just because they share a course.
3203
     */
3300
     */
3204
    public function test_can_send_message_even_if_blocked_shared_course() {
3301
    public function test_can_send_message_even_if_blocked_shared_course(): void {
Línea 3205... Línea 3302...
3205
        $this->resetAfterTest();
3302
        $this->resetAfterTest();
3206
 
3303
 
3207
        // Create some users.
3304
        // Create some users.
Línea 3218... Línea 3315...
3218
 
3315
 
3219
    /**
3316
    /**
3220
     * Tests the user can always send a message even if they are blocked because they share a course and
3317
     * Tests the user can always send a message even if they are blocked because they share a course and
3221
     * have the capability 'moodle/site:messageanyuser' at the course context.
3318
     * have the capability 'moodle/site:messageanyuser' at the course context.
3222
     */
3319
     */
3223
    public function test_can_send_message_even_if_blocked_shared_course_with_message_any_user_cap() {
3320
    public function test_can_send_message_even_if_blocked_shared_course_with_message_any_user_cap(): void {
Línea 3224... Línea 3321...
3224
        global $DB;
3321
        global $DB;
Línea 3225... Línea 3322...
3225
 
3322
 
Línea 3243... Línea 3340...
3243
    }
3340
    }
Línea 3244... Línea 3341...
3244
 
3341
 
3245
    /**
3342
    /**
3246
     * Verify the expected behaviour of the can_send_message_to_conversation() method for authenticated users with default settings.
3343
     * Verify the expected behaviour of the can_send_message_to_conversation() method for authenticated users with default settings.
3247
     */
3344
     */
-
 
3345
    public function test_can_send_message_to_conversation_basic(): void {
-
 
3346
        $this->resetAfterTest();
3248
    public function test_can_send_message_to_conversation_basic() {
3347
 
3249
        // Create some users.
3348
        // Create some users.
3250
        $user1 = self::getDataGenerator()->create_user();
3349
        $user1 = self::getDataGenerator()->create_user();
3251
        $user2 = self::getDataGenerator()->create_user();
3350
        $user2 = self::getDataGenerator()->create_user();
Línea 3293... Línea 3392...
3293
    }
3392
    }
Línea 3294... Línea 3393...
3294
 
3393
 
3295
    /**
3394
    /**
3296
     * Verify the behaviour of can_send_message_to_conversation() for authenticated users without the sendmessage capability.
3395
     * Verify the behaviour of can_send_message_to_conversation() for authenticated users without the sendmessage capability.
3297
     */
3396
     */
3298
    public function test_can_send_message_to_conversation_sendmessage_cap() {
3397
    public function test_can_send_message_to_conversation_sendmessage_cap(): void {
-
 
3398
        global $DB;
-
 
3399
        $this->resetAfterTest();
Línea 3299... Línea 3400...
3299
        global $DB;
3400
 
3300
 
3401
 
3301
        $user1 = self::getDataGenerator()->create_user();
3402
        $user1 = self::getDataGenerator()->create_user();
Línea 3341... Línea 3442...
3341
    }
3442
    }
Línea 3342... Línea 3443...
3342
 
3443
 
3343
    /**
3444
    /**
3344
     * Verify the behaviour of can_send_message_to_conversation() for authenticated users without the messageanyuser capability.
3445
     * Verify the behaviour of can_send_message_to_conversation() for authenticated users without the messageanyuser capability.
3345
     */
3446
     */
3346
    public function test_can_send_message_to_conversation_messageanyuser_cap() {
3447
    public function test_can_send_message_to_conversation_messageanyuser_cap(): void {
-
 
3448
        global $DB;
-
 
3449
        $this->resetAfterTest();
Línea 3347... Línea 3450...
3347
        global $DB;
3450
 
3348
 
3451
 
3349
        $user1 = self::getDataGenerator()->create_user();
3452
        $user1 = self::getDataGenerator()->create_user();
Línea 3393... Línea 3496...
3393
    }
3496
    }
Línea 3394... Línea 3497...
3394
 
3497
 
3395
    /**
3498
    /**
3396
     * Test verifying that users cannot send messages to conversations they are not a part of.
3499
     * Test verifying that users cannot send messages to conversations they are not a part of.
3397
     */
3500
     */
-
 
3501
    public function test_can_send_message_to_conversation_non_member(): void {
-
 
3502
        $this->resetAfterTest();
3398
    public function test_can_send_message_to_conversation_non_member() {
3503
 
3399
        // Create some users.
3504
        // Create some users.
3400
        $user1 = self::getDataGenerator()->create_user();
3505
        $user1 = self::getDataGenerator()->create_user();
3401
        $user2 = self::getDataGenerator()->create_user();
3506
        $user2 = self::getDataGenerator()->create_user();
3402
        $user3 = self::getDataGenerator()->create_user();
3507
        $user3 = self::getDataGenerator()->create_user();
Línea 3438... Línea 3543...
3438
    }
3543
    }
Línea 3439... Línea 3544...
3439
 
3544
 
3440
    /**
3545
    /**
3441
     * Test verifying the behaviour of the can_send_message_to_conversation method when privacy is set to contacts only.
3546
     * Test verifying the behaviour of the can_send_message_to_conversation method when privacy is set to contacts only.
3442
     */
3547
     */
-
 
3548
    public function test_can_send_message_to_conversation_privacy_contacts_only(): void {
-
 
3549
        $this->resetAfterTest();
3443
    public function test_can_send_message_to_conversation_privacy_contacts_only() {
3550
 
3444
        // Create some users.
3551
        // Create some users.
3445
        $user1 = self::getDataGenerator()->create_user();
3552
        $user1 = self::getDataGenerator()->create_user();
3446
        $user2 = self::getDataGenerator()->create_user();
3553
        $user2 = self::getDataGenerator()->create_user();
Línea 3481... Línea 3588...
3481
    }
3588
    }
Línea 3482... Línea 3589...
3482
 
3589
 
3483
    /**
3590
    /**
3484
     * Test verifying the behaviour of the can_send_message_to_conversation method when privacy is set to contacts / course members.
3591
     * Test verifying the behaviour of the can_send_message_to_conversation method when privacy is set to contacts / course members.
3485
     */
3592
     */
-
 
3593
    public function test_can_send_message_to_conversation_privacy_contacts_course(): void {
-
 
3594
        $this->resetAfterTest();
3486
    public function test_can_send_message_to_conversation_privacy_contacts_course() {
3595
 
3487
        // Create some users.
3596
        // Create some users.
3488
        $user1 = self::getDataGenerator()->create_user();
3597
        $user1 = self::getDataGenerator()->create_user();
3489
        $user2 = self::getDataGenerator()->create_user();
3598
        $user2 = self::getDataGenerator()->create_user();
Línea 3529... Línea 3638...
3529
    }
3638
    }
Línea 3530... Línea 3639...
3530
 
3639
 
3531
    /**
3640
    /**
3532
     * Test verifying the behaviour of the can_send_message_to_conversation method when privacy is set to any user.
3641
     * Test verifying the behaviour of the can_send_message_to_conversation method when privacy is set to any user.
3533
     */
3642
     */
-
 
3643
    public function test_can_send_message_to_conversation_privacy_sitewide(): void {
-
 
3644
        $this->resetAfterTest();
3534
    public function test_can_send_message_to_conversation_privacy_sitewide() {
3645
 
3535
        // Create some users.
3646
        // Create some users.
3536
        $user1 = self::getDataGenerator()->create_user();
3647
        $user1 = self::getDataGenerator()->create_user();
3537
        $user2 = self::getDataGenerator()->create_user();
3648
        $user2 = self::getDataGenerator()->create_user();
Línea 3583... Línea 3694...
3583
    }
3694
    }
Línea 3584... Línea 3695...
3584
 
3695
 
3585
    /**
3696
    /**
3586
     * Test verifying the behaviour of the can_send_message_to_conversation method when a user is blocked.
3697
     * Test verifying the behaviour of the can_send_message_to_conversation method when a user is blocked.
3587
     */
3698
     */
-
 
3699
    public function test_can_send_message_to_conversation_when_blocked(): void {
-
 
3700
        $this->resetAfterTest();
3588
    public function test_can_send_message_to_conversation_when_blocked() {
3701
 
3589
        $user1 = self::getDataGenerator()->create_user();
3702
        $user1 = self::getDataGenerator()->create_user();
3590
        $user2 = self::getDataGenerator()->create_user();
3703
        $user2 = self::getDataGenerator()->create_user();
Línea 3591... Línea 3704...
3591
        $user3 = self::getDataGenerator()->create_user();
3704
        $user3 = self::getDataGenerator()->create_user();
Línea 3627... Línea 3740...
3627
    }
3740
    }
Línea 3628... Línea 3741...
3628
 
3741
 
3629
    /**
3742
    /**
3630
     * Tests get_user_privacy_messaging_preference method.
3743
     * Tests get_user_privacy_messaging_preference method.
3631
     */
3744
     */
-
 
3745
    public function test_get_user_privacy_messaging_preference(): void {
-
 
3746
        $this->resetAfterTest();
3632
    public function test_get_user_privacy_messaging_preference() {
3747
 
3633
        // Create some users.
3748
        // Create some users.
3634
        $user1 = self::getDataGenerator()->create_user();
3749
        $user1 = self::getDataGenerator()->create_user();
3635
        $user2 = self::getDataGenerator()->create_user();
3750
        $user2 = self::getDataGenerator()->create_user();
Línea 3675... Línea 3790...
3675
    }
3790
    }
Línea 3676... Línea 3791...
3676
 
3791
 
3677
    /*
3792
    /*
3678
     * Tes get_message_processor api.
3793
     * Tes get_message_processor api.
3679
     */
3794
     */
-
 
3795
    public function test_get_message_processor(): void {
-
 
3796
        $this->resetAfterTest();
3680
    public function test_get_message_processor() {
3797
 
3681
        $processors = get_message_processors(true);
3798
        $processors = get_message_processors(true);
3682
        if (empty($processors)) {
3799
        if (empty($processors)) {
3683
            $this->markTestSkipped("No message processors found");
3800
            $this->markTestSkipped("No message processors found");
Línea 3710... Línea 3827...
3710
    }
3827
    }
Línea 3711... Línea 3828...
3711
 
3828
 
3712
    /**
3829
    /**
3713
     * Test method update_processor_status.
3830
     * Test method update_processor_status.
3714
     */
3831
     */
-
 
3832
    public function test_update_processor_status(): void {
-
 
3833
        $this->resetAfterTest();
3715
    public function test_update_processor_status() {
3834
 
3716
        $processors = get_message_processors();
3835
        $processors = get_message_processors();
3717
        if (empty($processors)) {
3836
        if (empty($processors)) {
3718
            $this->markTestSkipped("No message processors found");
3837
            $this->markTestSkipped("No message processors found");
3719
        }
3838
        }
Línea 3764... Línea 3883...
3764
    }
3883
    }
Línea 3765... Línea 3884...
3765
 
3884
 
3766
    /**
3885
    /**
3767
     * Test returning blocked users.
3886
     * Test returning blocked users.
3768
     */
3887
     */
3769
    public function test_get_blocked_users() {
3888
    public function test_get_blocked_users(): void {
-
 
3889
        global $USER;
-
 
3890
        $this->resetAfterTest();
Línea 3770... Línea 3891...
3770
        global $USER;
3891
 
3771
 
3892
 
Línea 3772... Línea 3893...
3772
        // Set this user as the admin.
3893
        // Set this user as the admin.
Línea 3791... Línea 3912...
3791
    }
3912
    }
Línea 3792... Línea 3913...
3792
 
3913
 
3793
    /**
3914
    /**
3794
     * Test marking a message as read.
3915
     * Test marking a message as read.
3795
     */
3916
     */
3796
    public function test_mark_message_as_read() {
3917
    public function test_mark_message_as_read(): void {
-
 
3918
        global $DB;
Línea 3797... Línea 3919...
3797
        global $DB;
3919
        $this->resetAfterTest();
3798
 
3920
 
Línea 3799... Línea 3921...
3799
        $user1 = self::getDataGenerator()->create_user();
3921
        $user1 = self::getDataGenerator()->create_user();
3800
        $user2 = self::getDataGenerator()->create_user();
3922
        $user2 = self::getDataGenerator()->create_user();
3801
 
3923
 
3802
        $this->send_fake_message($user1, $user2);
3924
        testhelper::send_fake_message($user1, $user2);
Línea 3803... Línea 3925...
3803
        $m2id = $this->send_fake_message($user1, $user2);
3925
        $m2id = testhelper::send_fake_message($user1, $user2);
3804
        $this->send_fake_message($user2, $user1);
3926
        testhelper::send_fake_message($user2, $user1);
3805
        $m4id = $this->send_fake_message($user2, $user1);
3927
        $m4id = testhelper::send_fake_message($user2, $user1);
3806
 
3928
 
Línea 3831... Línea 3953...
3831
    }
3953
    }
Línea 3832... Línea 3954...
3832
 
3954
 
3833
    /**
3955
    /**
3834
     * Test marking a notification as read.
3956
     * Test marking a notification as read.
3835
     */
3957
     */
3836
    public function test_mark_notification_as_read() {
3958
    public function test_mark_notification_as_read(): void {
-
 
3959
        global $DB;
Línea 3837... Línea 3960...
3837
        global $DB;
3960
        $this->resetAfterTest();
3838
 
3961
 
Línea 3839... Línea 3962...
3839
        $user1 = self::getDataGenerator()->create_user();
3962
        $user1 = self::getDataGenerator()->create_user();
3840
        $user2 = self::getDataGenerator()->create_user();
3963
        $user2 = self::getDataGenerator()->create_user();
3841
 
3964
 
3842
        $this->send_fake_message($user1, $user2, 'Notification 1', 1);
3965
        testhelper::send_fake_message($user1, $user2, 'Notification 1', 1);
Línea 3843... Línea 3966...
3843
        $n2id = $this->send_fake_message($user1, $user2, 'Notification 2', 1);
3966
        $n2id = testhelper::send_fake_message($user1, $user2, 'Notification 2', 1);
3844
        $this->send_fake_message($user2, $user1, 'Notification 3', 1);
3967
        testhelper::send_fake_message($user2, $user1, 'Notification 3', 1);
Línea 3845... Línea 3968...
3845
        $n4id = $this->send_fake_message($user2, $user1, 'Notification 4', 1);
3968
        $n4id = testhelper::send_fake_message($user2, $user1, 'Notification 4', 1);
Línea 3860... Línea 3983...
3860
    }
3983
    }
Línea 3861... Línea 3984...
3861
 
3984
 
3862
    /**
3985
    /**
3863
     * Test a conversation is not returned if there is none.
3986
     * Test a conversation is not returned if there is none.
3864
     */
3987
     */
-
 
3988
    public function test_get_conversation_between_users_no_conversation(): void {
-
 
3989
        $this->resetAfterTest();
3865
    public function test_get_conversation_between_users_no_conversation() {
3990
 
3866
        $user1 = self::getDataGenerator()->create_user();
3991
        $user1 = self::getDataGenerator()->create_user();
Línea 3867... Línea 3992...
3867
        $user2 = self::getDataGenerator()->create_user();
3992
        $user2 = self::getDataGenerator()->create_user();
3868
 
3993
 
Línea 3869... Línea 3994...
3869
        $this->assertFalse(api::get_conversation_between_users([$user1->id, $user2->id]));
3994
        $this->assertFalse(api::get_conversation_between_users([$user1->id, $user2->id]));
3870
    }
3995
    }
3871
 
3996
 
3872
    /**
3997
    /**
-
 
3998
     * Test count_conversation_members for non existing conversation.
-
 
3999
     */
3873
     * Test count_conversation_members for non existing conversation.
4000
    public function test_count_conversation_members_no_existing_conversation(): void {
-
 
4001
        $this->resetAfterTest();
3874
     */
4002
 
-
 
4003
        $this->assertEquals(
3875
    public function test_count_conversation_members_no_existing_conversation() {
4004
            0,
Línea 3876... Línea 4005...
3876
        $this->assertEquals(0,
4005
            api::count_conversation_members(0)
3877
            api::count_conversation_members(0));
4006
        );
3878
    }
4007
    }
3879
 
4008
 
-
 
4009
    /**
-
 
4010
     * Test count_conversation_members for existing conversation.
3880
    /**
4011
     */
3881
     * Test count_conversation_members for existing conversation.
4012
    public function test_count_conversation_members_existing_conversation(): void {
Línea 3882... Línea 4013...
3882
     */
4013
        $this->resetAfterTest();
3883
    public function test_count_conversation_members_existing_conversation() {
4014
 
Línea 3898... Línea 4029...
3898
    }
4029
    }
Línea 3899... Línea 4030...
3899
 
4030
 
3900
    /**
4031
    /**
3901
     * Test add_members_to_conversation for an individual conversation.
4032
     * Test add_members_to_conversation for an individual conversation.
3902
     */
4033
     */
-
 
4034
    public function test_add_members_to_individual_conversation(): void {
-
 
4035
        $this->resetAfterTest();
3903
    public function test_add_members_to_individual_conversation() {
4036
 
3904
        $user1 = self::getDataGenerator()->create_user();
4037
        $user1 = self::getDataGenerator()->create_user();
3905
        $user2 = self::getDataGenerator()->create_user();
4038
        $user2 = self::getDataGenerator()->create_user();
Línea 3906... Línea 4039...
3906
        $user3 = self::getDataGenerator()->create_user();
4039
        $user3 = self::getDataGenerator()->create_user();
Línea 3919... Línea 4052...
3919
    }
4052
    }
Línea 3920... Línea 4053...
3920
 
4053
 
3921
    /**
4054
    /**
3922
     * Test add_members_to_conversation for existing conversation.
4055
     * Test add_members_to_conversation for existing conversation.
3923
     */
4056
     */
-
 
4057
    public function test_add_members_to_existing_conversation(): void {
-
 
4058
        $this->resetAfterTest();
3924
    public function test_add_members_to_existing_conversation() {
4059
 
3925
        $user1 = self::getDataGenerator()->create_user();
4060
        $user1 = self::getDataGenerator()->create_user();
3926
        $user2 = self::getDataGenerator()->create_user();
4061
        $user2 = self::getDataGenerator()->create_user();
Línea 3927... Línea 4062...
3927
        $user3 = self::getDataGenerator()->create_user();
4062
        $user3 = self::getDataGenerator()->create_user();
Línea 3941... Línea 4076...
3941
    }
4076
    }
Línea 3942... Línea 4077...
3942
 
4077
 
3943
    /**
4078
    /**
3944
     * Test add_members_to_conversation for non existing conversation.
4079
     * Test add_members_to_conversation for non existing conversation.
3945
     */
4080
     */
-
 
4081
    public function test_add_members_to_no_existing_conversation(): void {
-
 
4082
        $this->resetAfterTest();
3946
    public function test_add_members_to_no_existing_conversation() {
4083
 
Línea 3947... Línea 4084...
3947
        $user1 = self::getDataGenerator()->create_user();
4084
        $user1 = self::getDataGenerator()->create_user();
3948
 
4085
 
3949
        // Throw dml_missing_record_exception for non existing conversation.
4086
        // Throw dml_missing_record_exception for non existing conversation.
3950
        $this->expectException('dml_missing_record_exception');
4087
        $this->expectException('dml_missing_record_exception');
Línea 3951... Línea 4088...
3951
        api::add_members_to_conversation([$user1->id], 0);
4088
        api::add_members_to_conversation([$user1->id], 0);
3952
    }
4089
    }
3953
 
4090
 
3954
    /**
4091
    /**
-
 
4092
     * Test add_member_to_conversation for non existing user.
-
 
4093
     */
3955
     * Test add_member_to_conversation for non existing user.
4094
    public function test_add_members_to_no_existing_user(): void {
3956
     */
4095
        $this->resetAfterTest();
Línea 3957... Línea 4096...
3957
    public function test_add_members_to_no_existing_user() {
4096
 
3958
        $user1 = self::getDataGenerator()->create_user();
4097
        $user1 = self::getDataGenerator()->create_user();
Línea 3974... Línea 4113...
3974
    }
4113
    }
Línea 3975... Línea 4114...
3975
 
4114
 
3976
    /**
4115
    /**
3977
     * Test add_members_to_conversation for current conversation member.
4116
     * Test add_members_to_conversation for current conversation member.
3978
     */
4117
     */
-
 
4118
    public function test_add_members_to_current_conversation_member(): void {
-
 
4119
        $this->resetAfterTest();
3979
    public function test_add_members_to_current_conversation_member() {
4120
 
3980
        $user1 = self::getDataGenerator()->create_user();
4121
        $user1 = self::getDataGenerator()->create_user();
Línea 3981... Línea 4122...
3981
        $user2 = self::getDataGenerator()->create_user();
4122
        $user2 = self::getDataGenerator()->create_user();
3982
 
4123
 
Línea 3996... Línea 4137...
3996
    }
4137
    }
Línea 3997... Línea 4138...
3997
 
4138
 
3998
    /**
4139
    /**
3999
     * Test add_members_to_conversation for multiple users.
4140
     * Test add_members_to_conversation for multiple users.
4000
     */
4141
     */
-
 
4142
    public function test_add_members_for_multiple_users(): void {
-
 
4143
        $this->resetAfterTest();
4001
    public function test_add_members_for_multiple_users() {
4144
 
4002
        $user1 = self::getDataGenerator()->create_user();
4145
        $user1 = self::getDataGenerator()->create_user();
4003
        $user2 = self::getDataGenerator()->create_user();
4146
        $user2 = self::getDataGenerator()->create_user();
4004
        $user3 = self::getDataGenerator()->create_user();
4147
        $user3 = self::getDataGenerator()->create_user();
Línea 4019... Línea 4162...
4019
    }
4162
    }
Línea 4020... Línea 4163...
4020
 
4163
 
4021
    /**
4164
    /**
4022
     * Test add_members_to_conversation for multiple users, included non existing and current conversation members
4165
     * Test add_members_to_conversation for multiple users, included non existing and current conversation members
4023
     */
4166
     */
-
 
4167
    public function test_add_members_for_multiple_not_valid_users(): void {
-
 
4168
        $this->resetAfterTest();
4024
    public function test_add_members_for_multiple_not_valid_users() {
4169
 
4025
        $user1 = self::getDataGenerator()->create_user();
4170
        $user1 = self::getDataGenerator()->create_user();
4026
        $user2 = self::getDataGenerator()->create_user();
4171
        $user2 = self::getDataGenerator()->create_user();
Línea 4027... Línea 4172...
4027
        $user3 = self::getDataGenerator()->create_user();
4172
        $user3 = self::getDataGenerator()->create_user();
Línea 4042... Línea 4187...
4042
    }
4187
    }
Línea 4043... Línea 4188...
4043
 
4188
 
4044
    /**
4189
    /**
4045
     * Test remove_members_from_conversation for individual conversation.
4190
     * Test remove_members_from_conversation for individual conversation.
4046
     */
4191
     */
-
 
4192
    public function test_remove_members_from_individual_conversation(): void {
-
 
4193
        $this->resetAfterTest();
4047
    public function test_remove_members_from_individual_conversation() {
4194
 
4048
        $user1 = self::getDataGenerator()->create_user();
4195
        $user1 = self::getDataGenerator()->create_user();
Línea 4049... Línea 4196...
4049
        $user2 = self::getDataGenerator()->create_user();
4196
        $user2 = self::getDataGenerator()->create_user();
4050
 
4197
 
Línea 4062... Línea 4209...
4062
    }
4209
    }
Línea 4063... Línea 4210...
4063
 
4210
 
4064
    /**
4211
    /**
4065
     * Test remove_members_from_conversation for existing conversation.
4212
     * Test remove_members_from_conversation for existing conversation.
4066
     */
4213
     */
-
 
4214
    public function test_remove_members_from_existing_conversation(): void {
-
 
4215
        $this->resetAfterTest();
4067
    public function test_remove_members_from_existing_conversation() {
4216
 
4068
        $user1 = self::getDataGenerator()->create_user();
4217
        $user1 = self::getDataGenerator()->create_user();
Línea 4069... Línea 4218...
4069
        $user2 = self::getDataGenerator()->create_user();
4218
        $user2 = self::getDataGenerator()->create_user();
4070
 
4219
 
Línea 4083... Línea 4232...
4083
    }
4232
    }
Línea 4084... Línea 4233...
4084
 
4233
 
4085
    /**
4234
    /**
4086
     * Test remove_members_from_conversation for non existing conversation.
4235
     * Test remove_members_from_conversation for non existing conversation.
4087
     */
4236
     */
-
 
4237
    public function test_remove_members_from_no_existing_conversation(): void {
-
 
4238
        $this->resetAfterTest();
4088
    public function test_remove_members_from_no_existing_conversation() {
4239
 
Línea 4089... Línea 4240...
4089
        $user1 = self::getDataGenerator()->create_user();
4240
        $user1 = self::getDataGenerator()->create_user();
4090
 
4241
 
4091
        // Throw dml_missing_record_exception for non existing conversation.
4242
        // Throw dml_missing_record_exception for non existing conversation.
4092
        $this->expectException('dml_missing_record_exception');
4243
        $this->expectException('dml_missing_record_exception');
Línea 4093... Línea 4244...
4093
        api::remove_members_from_conversation([$user1->id], 0);
4244
        api::remove_members_from_conversation([$user1->id], 0);
4094
    }
4245
    }
4095
 
4246
 
4096
    /**
4247
    /**
-
 
4248
     * Test remove_members_from_conversation for non existing user.
-
 
4249
     */
4097
     * Test remove_members_from_conversation for non existing user.
4250
    public function test_remove_members_for_no_existing_user(): void {
4098
     */
4251
        $this->resetAfterTest();
Línea 4099... Línea 4252...
4099
    public function test_remove_members_for_no_existing_user() {
4252
 
4100
        $user1 = self::getDataGenerator()->create_user();
4253
        $user1 = self::getDataGenerator()->create_user();
Línea 4115... Línea 4268...
4115
    }
4268
    }
Línea 4116... Línea 4269...
4116
 
4269
 
4117
    /**
4270
    /**
4118
     * Test remove_members_from_conversation for multiple users.
4271
     * Test remove_members_from_conversation for multiple users.
4119
     */
4272
     */
-
 
4273
    public function test_remove_members_for_multiple_users(): void {
-
 
4274
        $this->resetAfterTest();
4120
    public function test_remove_members_for_multiple_users() {
4275
 
4121
        $user1 = self::getDataGenerator()->create_user();
4276
        $user1 = self::getDataGenerator()->create_user();
4122
        $user2 = self::getDataGenerator()->create_user();
4277
        $user2 = self::getDataGenerator()->create_user();
4123
        $user3 = self::getDataGenerator()->create_user();
4278
        $user3 = self::getDataGenerator()->create_user();
Línea 4139... Línea 4294...
4139
    }
4294
    }
Línea 4140... Línea 4295...
4140
 
4295
 
4141
    /**
4296
    /**
4142
     * Test remove_members_from_conversation for multiple non valid users.
4297
     * Test remove_members_from_conversation for multiple non valid users.
4143
     */
4298
     */
-
 
4299
    public function test_remove_members_for_multiple_no_valid_users(): void {
-
 
4300
        $this->resetAfterTest();
4144
    public function test_remove_members_for_multiple_no_valid_users() {
4301
 
4145
        $user1 = self::getDataGenerator()->create_user();
4302
        $user1 = self::getDataGenerator()->create_user();
4146
        $user2 = self::getDataGenerator()->create_user();
4303
        $user2 = self::getDataGenerator()->create_user();
4147
        $user3 = self::getDataGenerator()->create_user();
4304
        $user3 = self::getDataGenerator()->create_user();
Línea 4165... Línea 4322...
4165
    }
4322
    }
Línea 4166... Línea 4323...
4166
 
4323
 
4167
    /**
4324
    /**
4168
     * Test count_conversation_members for empty conversation.
4325
     * Test count_conversation_members for empty conversation.
4169
     */
4326
     */
-
 
4327
    public function test_count_conversation_members_empty_conversation(): void {
-
 
4328
        $this->resetAfterTest();
4170
    public function test_count_conversation_members_empty_conversation() {
4329
 
4171
        $user1 = self::getDataGenerator()->create_user();
4330
        $user1 = self::getDataGenerator()->create_user();
Línea 4172... Línea 4331...
4172
        $user2 = self::getDataGenerator()->create_user();
4331
        $user2 = self::getDataGenerator()->create_user();
4173
 
4332
 
Línea 4187... Línea 4346...
4187
    }
4346
    }
Línea 4188... Línea 4347...
4188
 
4347
 
4189
    /**
4348
    /**
4190
     * Test can create a contact request.
4349
     * Test can create a contact request.
4191
     */
4350
     */
4192
    public function test_can_create_contact_request() {
4351
    public function test_can_create_contact_request(): void {
-
 
4352
        global $CFG;
Línea 4193... Línea 4353...
4193
        global $CFG;
4353
        $this->resetAfterTest();
4194
 
4354
 
Línea 4195... Línea 4355...
4195
        $user1 = self::getDataGenerator()->create_user();
4355
        $user1 = self::getDataGenerator()->create_user();
Línea 4218... Línea 4378...
4218
    }
4378
    }
Línea 4219... Línea 4379...
4219
 
4379
 
4220
    /**
4380
    /**
4221
     * Test creating a contact request.
4381
     * Test creating a contact request.
4222
     */
4382
     */
4223
    public function test_create_contact_request() {
4383
    public function test_create_contact_request(): void {
-
 
4384
        global $DB;
Línea 4224... Línea 4385...
4224
        global $DB;
4385
        $this->resetAfterTest();
4225
 
4386
 
Línea 4226... Línea 4387...
4226
        $user1 = self::getDataGenerator()->create_user();
4387
        $user1 = self::getDataGenerator()->create_user();
Línea 4241... Línea 4402...
4241
    }
4402
    }
Línea 4242... Línea 4403...
4242
 
4403
 
4243
    /**
4404
    /**
4244
     * Test confirming a contact request.
4405
     * Test confirming a contact request.
4245
     */
4406
     */
4246
    public function test_confirm_contact_request() {
4407
    public function test_confirm_contact_request(): void {
-
 
4408
        global $DB;
Línea 4247... Línea 4409...
4247
        global $DB;
4409
        $this->resetAfterTest();
4248
 
4410
 
Línea 4249... Línea 4411...
4249
        $user1 = self::getDataGenerator()->create_user();
4411
        $user1 = self::getDataGenerator()->create_user();
Línea 4266... Línea 4428...
4266
    }
4428
    }
Línea 4267... Línea 4429...
4267
 
4429
 
4268
    /**
4430
    /**
4269
     * Test declining a contact request.
4431
     * Test declining a contact request.
4270
     */
4432
     */
4271
    public function test_decline_contact_request() {
4433
    public function test_decline_contact_request(): void {
-
 
4434
        global $DB;
Línea 4272... Línea 4435...
4272
        global $DB;
4435
        $this->resetAfterTest();
4273
 
4436
 
Línea 4274... Línea 4437...
4274
        $user1 = self::getDataGenerator()->create_user();
4437
        $user1 = self::getDataGenerator()->create_user();
Línea 4283... Línea 4446...
4283
    }
4446
    }
Línea 4284... Línea 4447...
4284
 
4447
 
4285
    /**
4448
    /**
4286
     * Test retrieving contact requests.
4449
     * Test retrieving contact requests.
4287
     */
4450
     */
4288
    public function test_get_contact_requests() {
4451
    public function test_get_contact_requests(): void {
-
 
4452
        global $PAGE;
Línea 4289... Línea 4453...
4289
        global $PAGE;
4453
        $this->resetAfterTest();
4290
 
4454
 
4291
        $user1 = self::getDataGenerator()->create_user();
4455
        $user1 = self::getDataGenerator()->create_user();
Línea 4317... Línea 4481...
4317
    }
4481
    }
Línea 4318... Línea 4482...
4318
 
4482
 
4319
    /**
4483
    /**
4320
     * Test the get_contact_requests() function when the user has blocked the sender of the request.
4484
     * Test the get_contact_requests() function when the user has blocked the sender of the request.
4321
     */
4485
     */
-
 
4486
    public function test_get_contact_requests_blocked_sender(): void {
4322
    public function test_get_contact_requests_blocked_sender() {
4487
        $this->resetAfterTest();
4323
        $user1 = self::getDataGenerator()->create_user();
4488
        $user1 = self::getDataGenerator()->create_user();
Línea 4324... Línea 4489...
4324
        $user2 = self::getDataGenerator()->create_user();
4489
        $user2 = self::getDataGenerator()->create_user();
4325
 
4490
 
Línea 4335... Línea 4500...
4335
    }
4500
    }
Línea 4336... Línea 4501...
4336
 
4501
 
4337
    /**
4502
    /**
4338
     * Test getting contact requests when there are none.
4503
     * Test getting contact requests when there are none.
4339
     */
4504
     */
4340
    public function test_get_contact_requests_no_requests() {
4505
    public function test_get_contact_requests_no_requests(): void {
Línea 4341... Línea 4506...
4341
        $this->resetAfterTest();
4506
        $this->resetAfterTest();
Línea 4342... Línea 4507...
4342
 
4507
 
Línea 4348... Línea 4513...
4348
    }
4513
    }
Línea 4349... Línea 4514...
4349
 
4514
 
4350
    /**
4515
    /**
4351
     * Test getting contact requests with limits.
4516
     * Test getting contact requests with limits.
4352
     */
4517
     */
4353
    public function test_get_contact_requests_with_limits() {
4518
    public function test_get_contact_requests_with_limits(): void {
Línea 4354... Línea 4519...
4354
        $this->resetAfterTest();
4519
        $this->resetAfterTest();
4355
 
4520
 
4356
        $user1 = self::getDataGenerator()->create_user();
4521
        $user1 = self::getDataGenerator()->create_user();
Línea 4366... Línea 4531...
4366
    }
4531
    }
Línea 4367... Línea 4532...
4367
 
4532
 
4368
    /**
4533
    /**
4369
     * Test adding contacts.
4534
     * Test adding contacts.
4370
     */
4535
     */
4371
    public function test_add_contact() {
4536
    public function test_add_contact(): void {
-
 
4537
        global $DB;
Línea 4372... Línea 4538...
4372
        global $DB;
4538
        $this->resetAfterTest();
4373
 
4539
 
Línea 4374... Línea 4540...
4374
        $user1 = self::getDataGenerator()->create_user();
4540
        $user1 = self::getDataGenerator()->create_user();
Línea 4387... Línea 4553...
4387
    }
4553
    }
Línea 4388... Línea 4554...
4388
 
4554
 
4389
    /**
4555
    /**
4390
     * Test removing contacts.
4556
     * Test removing contacts.
4391
     */
4557
     */
4392
    public function test_remove_contact() {
4558
    public function test_remove_contact(): void {
-
 
4559
        global $DB;
Línea 4393... Línea 4560...
4393
        global $DB;
4560
        $this->resetAfterTest();
4394
 
4561
 
Línea 4395... Línea 4562...
4395
        $user1 = self::getDataGenerator()->create_user();
4562
        $user1 = self::getDataGenerator()->create_user();
Línea 4402... Línea 4569...
4402
    }
4569
    }
Línea 4403... Línea 4570...
4403
 
4570
 
4404
    /**
4571
    /**
4405
     * Test blocking users.
4572
     * Test blocking users.
4406
     */
4573
     */
4407
    public function test_block_user() {
4574
    public function test_block_user(): void {
-
 
4575
        global $DB;
Línea 4408... Línea 4576...
4408
        global $DB;
4576
        $this->resetAfterTest();
4409
 
4577
 
Línea 4410... Línea 4578...
4410
        $user1 = self::getDataGenerator()->create_user();
4578
        $user1 = self::getDataGenerator()->create_user();
Línea 4423... Línea 4591...
4423
    }
4591
    }
Línea 4424... Línea 4592...
4424
 
4592
 
4425
    /**
4593
    /**
4426
     * Test unblocking users.
4594
     * Test unblocking users.
4427
     */
4595
     */
4428
    public function test_unblock_user() {
4596
    public function test_unblock_user(): void {
-
 
4597
        global $DB;
Línea 4429... Línea 4598...
4429
        global $DB;
4598
        $this->resetAfterTest();
4430
 
4599
 
Línea 4431... Línea 4600...
4431
        $user1 = self::getDataGenerator()->create_user();
4600
        $user1 = self::getDataGenerator()->create_user();
Línea 4438... Línea 4607...
4438
    }
4607
    }
Línea 4439... Línea 4608...
4439
 
4608
 
4440
    /**
4609
    /**
4441
     * Test muting a conversation.
4610
     * Test muting a conversation.
4442
     */
4611
     */
4443
    public function test_mute_conversation() {
4612
    public function test_mute_conversation(): void {
-
 
4613
        global $DB;
Línea 4444... Línea 4614...
4444
        global $DB;
4614
        $this->resetAfterTest();
4445
 
4615
 
Línea 4446... Línea 4616...
4446
        $user1 = self::getDataGenerator()->create_user();
4616
        $user1 = self::getDataGenerator()->create_user();
Línea 4469... Línea 4639...
4469
    }
4639
    }
Línea 4470... Línea 4640...
4470
 
4640
 
4471
    /**
4641
    /**
4472
     * Test unmuting a conversation.
4642
     * Test unmuting a conversation.
4473
     */
4643
     */
4474
    public function test_unmute_conversation() {
4644
    public function test_unmute_conversation(): void {
-
 
4645
        global $DB;
Línea 4475... Línea 4646...
4475
        global $DB;
4646
        $this->resetAfterTest();
4476
 
4647
 
Línea 4477... Línea 4648...
4477
        $user1 = self::getDataGenerator()->create_user();
4648
        $user1 = self::getDataGenerator()->create_user();
Línea 4493... Línea 4664...
4493
    }
4664
    }
Línea 4494... Línea 4665...
4494
 
4665
 
4495
    /**
4666
    /**
4496
     * Test if a conversation is muted.
4667
     * Test if a conversation is muted.
4497
     */
4668
     */
-
 
4669
    public function test_is_conversation_muted(): void {
-
 
4670
        $this->resetAfterTest();
4498
    public function test_is_conversation_muted() {
4671
 
4499
        $user1 = self::getDataGenerator()->create_user();
4672
        $user1 = self::getDataGenerator()->create_user();
Línea 4500... Línea 4673...
4500
        $user2 = self::getDataGenerator()->create_user();
4673
        $user2 = self::getDataGenerator()->create_user();
4501
 
4674
 
Línea 4516... Línea 4689...
4516
    }
4689
    }
Línea 4517... Línea 4690...
4517
 
4690
 
4518
    /**
4691
    /**
4519
     * Test is contact check.
4692
     * Test is contact check.
4520
     */
4693
     */
-
 
4694
    public function test_is_contact(): void {
-
 
4695
        $this->resetAfterTest();
4521
    public function test_is_contact() {
4696
 
4522
        $user1 = self::getDataGenerator()->create_user();
4697
        $user1 = self::getDataGenerator()->create_user();
4523
        $user2 = self::getDataGenerator()->create_user();
4698
        $user2 = self::getDataGenerator()->create_user();
Línea 4524... Línea 4699...
4524
        $user3 = self::getDataGenerator()->create_user();
4699
        $user3 = self::getDataGenerator()->create_user();
Línea 4531... Línea 4706...
4531
    }
4706
    }
Línea 4532... Línea 4707...
4532
 
4707
 
4533
    /**
4708
    /**
4534
     * Test get contact.
4709
     * Test get contact.
4535
     */
4710
     */
-
 
4711
    public function test_get_contact(): void {
-
 
4712
        $this->resetAfterTest();
4536
    public function test_get_contact() {
4713
 
4537
        $user1 = self::getDataGenerator()->create_user();
4714
        $user1 = self::getDataGenerator()->create_user();
Línea 4538... Línea 4715...
4538
        $user2 = self::getDataGenerator()->create_user();
4715
        $user2 = self::getDataGenerator()->create_user();
Línea 4546... Línea 4723...
4546
    }
4723
    }
Línea 4547... Línea 4724...
4547
 
4724
 
4548
    /**
4725
    /**
4549
     * Test is blocked checked.
4726
     * Test is blocked checked.
4550
     */
4727
     */
-
 
4728
    public function test_is_blocked(): void {
-
 
4729
        $this->resetAfterTest();
4551
    public function test_is_blocked() {
4730
 
4552
        $user1 = self::getDataGenerator()->create_user();
4731
        $user1 = self::getDataGenerator()->create_user();
Línea 4553... Línea 4732...
4553
        $user2 = self::getDataGenerator()->create_user();
4732
        $user2 = self::getDataGenerator()->create_user();
4554
 
4733
 
Línea 4562... Línea 4741...
4562
    }
4741
    }
Línea 4563... Línea 4742...
4563
 
4742
 
4564
    /**
4743
    /**
4565
     * Test the contact request exist check.
4744
     * Test the contact request exist check.
4566
     */
4745
     */
-
 
4746
    public function test_does_contact_request_exist(): void {
-
 
4747
        $this->resetAfterTest();
4567
    public function test_does_contact_request_exist() {
4748
 
4568
        $user1 = self::getDataGenerator()->create_user();
4749
        $user1 = self::getDataGenerator()->create_user();
Línea 4569... Línea 4750...
4569
        $user2 = self::getDataGenerator()->create_user();
4750
        $user2 = self::getDataGenerator()->create_user();
4570
 
4751
 
Línea 4578... Línea 4759...
4578
    }
4759
    }
Línea 4579... Línea 4760...
4579
 
4760
 
4580
    /**
4761
    /**
4581
     * Test the get_received_contact_requests_count() function.
4762
     * Test the get_received_contact_requests_count() function.
4582
     */
4763
     */
-
 
4764
    public function test_get_received_contact_requests_count(): void {
-
 
4765
        $this->resetAfterTest();
4583
    public function test_get_received_contact_requests_count() {
4766
 
4584
        $user1 = self::getDataGenerator()->create_user();
4767
        $user1 = self::getDataGenerator()->create_user();
4585
        $user2 = self::getDataGenerator()->create_user();
4768
        $user2 = self::getDataGenerator()->create_user();
4586
        $user3 = self::getDataGenerator()->create_user();
4769
        $user3 = self::getDataGenerator()->create_user();
Línea 4602... Línea 4785...
4602
    }
4785
    }
Línea 4603... Línea 4786...
4603
 
4786
 
4604
    /**
4787
    /**
4605
     * Test the get_received_contact_requests_count() function when the user has blocked the sender of the request.
4788
     * Test the get_received_contact_requests_count() function when the user has blocked the sender of the request.
4606
     */
4789
     */
-
 
4790
    public function test_get_received_contact_requests_count_blocked_sender(): void {
-
 
4791
        $this->resetAfterTest();
4607
    public function test_get_received_contact_requests_count_blocked_sender() {
4792
 
4608
        $user1 = self::getDataGenerator()->create_user();
4793
        $user1 = self::getDataGenerator()->create_user();
Línea 4609... Línea 4794...
4609
        $user2 = self::getDataGenerator()->create_user();
4794
        $user2 = self::getDataGenerator()->create_user();
4610
 
4795
 
Línea 4619... Línea 4804...
4619
    }
4804
    }
Línea 4620... Línea 4805...
4620
 
4805
 
4621
    /**
4806
    /**
4622
     * Test the get_contact_requests_between_users() function.
4807
     * Test the get_contact_requests_between_users() function.
4623
     */
4808
     */
-
 
4809
    public function test_get_contact_requests_between_users(): void {
-
 
4810
        $this->resetAfterTest();
4624
    public function test_get_contact_requests_between_users() {
4811
 
4625
        $user1 = self::getDataGenerator()->create_user();
4812
        $user1 = self::getDataGenerator()->create_user();
4626
        $user2 = self::getDataGenerator()->create_user();
4813
        $user2 = self::getDataGenerator()->create_user();
4627
        $user3 = self::getDataGenerator()->create_user();
4814
        $user3 = self::getDataGenerator()->create_user();
Línea 4667... Línea 4854...
4667
    }
4854
    }
Línea 4668... Línea 4855...
4668
 
4855
 
4669
    /**
4856
    /**
4670
     * Test the user in conversation check.
4857
     * Test the user in conversation check.
4671
     */
4858
     */
-
 
4859
    public function test_is_user_in_conversation(): void {
-
 
4860
        $this->resetAfterTest();
4672
    public function test_is_user_in_conversation() {
4861
 
4673
        $user1 = self::getDataGenerator()->create_user();
4862
        $user1 = self::getDataGenerator()->create_user();
Línea 4674... Línea 4863...
4674
        $user2 = self::getDataGenerator()->create_user();
4863
        $user2 = self::getDataGenerator()->create_user();
4675
 
4864
 
Línea 4686... Línea 4875...
4686
    }
4875
    }
Línea 4687... Línea 4876...
4687
 
4876
 
4688
    /**
4877
    /**
4689
     * Test the user in conversation check when they are not.
4878
     * Test the user in conversation check when they are not.
4690
     */
4879
     */
-
 
4880
    public function test_is_user_in_conversation_when_not(): void {
-
 
4881
        $this->resetAfterTest();
4691
    public function test_is_user_in_conversation_when_not() {
4882
 
4692
        $user1 = self::getDataGenerator()->create_user();
4883
        $user1 = self::getDataGenerator()->create_user();
4693
        $user2 = self::getDataGenerator()->create_user();
4884
        $user2 = self::getDataGenerator()->create_user();
Línea 4694... Línea 4885...
4694
        $user3 = self::getDataGenerator()->create_user();
4885
        $user3 = self::getDataGenerator()->create_user();
Línea 4706... Línea 4897...
4706
    }
4897
    }
Línea 4707... Línea 4898...
4707
 
4898
 
4708
    /**
4899
    /**
4709
     * Test can create a group conversation.
4900
     * Test can create a group conversation.
4710
     */
4901
     */
4711
    public function test_can_create_group_conversation() {
4902
    public function test_can_create_group_conversation(): void {
-
 
4903
        global $CFG;
Línea 4712... Línea 4904...
4712
        global $CFG;
4904
        $this->resetAfterTest();
4713
 
4905
 
4714
        $student = self::getDataGenerator()->create_user();
4906
        $student = self::getDataGenerator()->create_user();
Línea 4735... Línea 4927...
4735
    }
4927
    }
Línea 4736... Línea 4928...
4736
 
4928
 
4737
    /**
4929
    /**
4738
     * Test creating an individual conversation.
4930
     * Test creating an individual conversation.
4739
     */
4931
     */
-
 
4932
    public function test_create_conversation_individual(): void {
-
 
4933
        $this->resetAfterTest();
4740
    public function test_create_conversation_individual() {
4934
 
4741
        $user1 = self::getDataGenerator()->create_user();
4935
        $user1 = self::getDataGenerator()->create_user();
Línea 4742... Línea 4936...
4742
        $user2 = self::getDataGenerator()->create_user();
4936
        $user2 = self::getDataGenerator()->create_user();
4743
 
4937
 
Línea 4767... Línea 4961...
4767
    }
4961
    }
Línea 4768... Línea 4962...
4768
 
4962
 
4769
    /**
4963
    /**
4770
     * Test creating a group conversation.
4964
     * Test creating a group conversation.
4771
     */
4965
     */
-
 
4966
    public function test_create_conversation_group(): void {
-
 
4967
        $this->resetAfterTest();
4772
    public function test_create_conversation_group() {
4968
 
4773
        $user1 = self::getDataGenerator()->create_user();
4969
        $user1 = self::getDataGenerator()->create_user();
4774
        $user2 = self::getDataGenerator()->create_user();
4970
        $user2 = self::getDataGenerator()->create_user();
Línea 4775... Línea 4971...
4775
        $user3 = self::getDataGenerator()->create_user();
4971
        $user3 = self::getDataGenerator()->create_user();
Línea 4805... Línea 5001...
4805
    }
5001
    }
Línea 4806... Línea 5002...
4806
 
5002
 
4807
    /**
5003
    /**
4808
     * Test creating an invalid conversation.
5004
     * Test creating an invalid conversation.
4809
     */
5005
     */
4810
    public function test_create_conversation_invalid() {
5006
    public function test_create_conversation_invalid(): void {
4811
        $this->expectException('moodle_exception');
5007
        $this->expectException('moodle_exception');
4812
        api::create_conversation(3, [1, 2, 3]);
5008
        api::create_conversation(3, [1, 2, 3]);
Línea 4813... Línea 5009...
4813
    }
5009
    }
4814
 
5010
 
4815
    /**
5011
    /**
4816
     * Test creating an individual conversation with too many members.
5012
     * Test creating an individual conversation with too many members.
4817
     */
5013
     */
4818
    public function test_create_conversation_individual_too_many_members() {
5014
    public function test_create_conversation_individual_too_many_members(): void {
4819
        $this->expectException('moodle_exception');
5015
        $this->expectException('moodle_exception');
Línea 4820... Línea 5016...
4820
        api::create_conversation(api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, [1, 2, 3]);
5016
        api::create_conversation(api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, [1, 2, 3]);
4821
    }
5017
    }
4822
 
5018
 
4823
    /**
5019
    /**
-
 
5020
     * Test create message conversation with area.
-
 
5021
     */
4824
     * Test create message conversation with area.
5022
    public function test_create_conversation_with_area(): void {
4825
     */
5023
        $this->resetAfterTest();
4826
    public function test_create_conversation_with_area() {
5024
 
4827
        $contextid = 111;
5025
        $contextid = 111;
4828
        $itemid = 222;
5026
        $itemid = 222;
Línea 4846... Línea 5044...
4846
    }
5044
    }
Línea 4847... Línea 5045...
4847
 
5045
 
4848
    /**
5046
    /**
4849
     * Test get_conversation_by_area.
5047
     * Test get_conversation_by_area.
4850
     */
5048
     */
-
 
5049
    public function test_get_conversation_by_area(): void {
-
 
5050
        $this->resetAfterTest();
4851
    public function test_get_conversation_by_area() {
5051
 
4852
        $contextid = 111;
5052
        $contextid = 111;
4853
        $itemid = 222;
5053
        $itemid = 222;
4854
        $name = 'Name of conversation';
5054
        $name = 'Name of conversation';
4855
        $createconversation = api::create_conversation(
5055
        $createconversation = api::create_conversation(
Línea 4873... Línea 5073...
4873
    }
5073
    }
Línea 4874... Línea 5074...
4874
 
5074
 
4875
    /**
5075
    /**
4876
     * Test enable_conversation.
5076
     * Test enable_conversation.
4877
     */
5077
     */
4878
    public function test_enable_conversation() {
5078
    public function test_enable_conversation(): void {
-
 
5079
        global $DB;
Línea 4879... Línea 5080...
4879
        global $DB;
5080
        $this->resetAfterTest();
Línea 4880... Línea 5081...
4880
 
5081
 
4881
        $name = 'Name of conversation';
5082
        $name = 'Name of conversation';
Línea 4894... Línea 5095...
4894
    }
5095
    }
Línea 4895... Línea 5096...
4895
 
5096
 
4896
    /**
5097
    /**
4897
     * Test disable_conversation.
5098
     * Test disable_conversation.
4898
     */
5099
     */
4899
    public function test_disable_conversation() {
5100
    public function test_disable_conversation(): void {
-
 
5101
        global $DB;
-
 
5102
        $this->resetAfterTest();
Línea 4900... Línea 5103...
4900
        global $DB;
5103
 
Línea 4901... Línea 5104...
4901
 
5104
 
4902
        $name = 'Name of conversation';
5105
        $name = 'Name of conversation';
Línea 4915... Línea 5118...
4915
    }
5118
    }
Línea 4916... Línea 5119...
4916
 
5119
 
4917
    /**
5120
    /**
4918
     * Test update_conversation_name.
5121
     * Test update_conversation_name.
4919
     */
5122
     */
4920
    public function test_update_conversation_name() {
5123
    public function test_update_conversation_name(): void {
-
 
5124
        global $DB;
Línea 4921... Línea 5125...
4921
        global $DB;
5125
        $this->resetAfterTest();
Línea 4922... Línea 5126...
4922
 
5126
 
4923
        $conversation = api::create_conversation(api::MESSAGE_CONVERSATION_TYPE_GROUP, []);
5127
        $conversation = api::create_conversation(api::MESSAGE_CONVERSATION_TYPE_GROUP, []);
Línea 4932... Línea 5136...
4932
    }
5136
    }
Línea 4933... Línea 5137...
4933
 
5137
 
4934
    /**
5138
    /**
4935
     * Test returning members in a conversation with no contact requests.
5139
     * Test returning members in a conversation with no contact requests.
4936
     */
5140
     */
-
 
5141
    public function test_get_conversation_members(): void {
-
 
5142
        $this->resetAfterTest();
4937
    public function test_get_conversation_members() {
5143
 
4938
        $lastaccess = new \stdClass();
5144
        $lastaccess = new \stdClass();
Línea 4939... Línea 5145...
4939
        $lastaccess->lastaccess = time();
5145
        $lastaccess->lastaccess = time();
4940
 
5146
 
Línea 5003... Línea 5209...
5003
    }
5209
    }
Línea 5004... Línea 5210...
5004
 
5210
 
5005
    /**
5211
    /**
5006
     * Test returning members in a conversation with contact requests.
5212
     * Test returning members in a conversation with contact requests.
5007
     */
5213
     */
-
 
5214
    public function test_get_conversation_members_with_contact_requests(): void {
-
 
5215
        $this->resetAfterTest();
5008
    public function test_get_conversation_members_with_contact_requests() {
5216
 
5009
        $lastaccess = new \stdClass();
5217
        $lastaccess = new \stdClass();
Línea 5010... Línea 5218...
5010
        $lastaccess->lastaccess = time();
5218
        $lastaccess->lastaccess = time();
5011
 
5219
 
Línea 5094... Línea 5302...
5094
    }
5302
    }
Línea 5095... Línea 5303...
5095
 
5303
 
5096
    /**
5304
    /**
5097
     * Test returning members of a self conversation.
5305
     * Test returning members of a self conversation.
5098
     */
5306
     */
-
 
5307
    public function test_get_conversation_members_with_self_conversation(): void {
-
 
5308
        $this->resetAfterTest();
5099
    public function test_get_conversation_members_with_self_conversation() {
5309
 
5100
        $lastaccess = new \stdClass();
5310
        $lastaccess = new \stdClass();
Línea 5101... Línea 5311...
5101
        $lastaccess->lastaccess = time();
5311
        $lastaccess->lastaccess = time();
Línea 5121... Línea 5331...
5121
    }
5331
    }
Línea 5122... Línea 5332...
5122
 
5332
 
5123
    /**
5333
    /**
5124
     * Test verifying that messages can be sent to existing individual conversations.
5334
     * Test verifying that messages can be sent to existing individual conversations.
5125
     */
5335
     */
-
 
5336
    public function test_send_message_to_conversation_individual_conversation(): void {
-
 
5337
        $this->resetAfterTest();
5126
    public function test_send_message_to_conversation_individual_conversation() {
5338
 
5127
        // Get a bunch of conversations, some group, some individual and in different states.
5339
        // Get a bunch of conversations, some group, some individual and in different states.
5128
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
5340
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 5129... Línea 5341...
5129
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
5341
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 5171... Línea 5383...
5171
    }
5383
    }
Línea 5172... Línea 5384...
5172
 
5384
 
5173
    /**
5385
    /**
5174
     * Test verifying that messages can be sent to existing group conversations.
5386
     * Test verifying that messages can be sent to existing group conversations.
5175
     */
5387
     */
-
 
5388
    public function test_send_message_to_conversation_group_conversation(): void {
5176
    public function test_send_message_to_conversation_group_conversation() {
5389
        $this->resetAfterTest();
5177
        // Get a bunch of conversations, some group, some individual and in different states.
5390
        // Get a bunch of conversations, some group, some individual and in different states.
5178
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
5391
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 5179... Línea 5392...
5179
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
5392
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 5221... Línea 5434...
5221
    }
5434
    }
Línea 5222... Línea 5435...
5222
 
5435
 
5223
    /**
5436
    /**
5224
     * Test verifying that messages can be sent to existing linked group conversations.
5437
     * Test verifying that messages can be sent to existing linked group conversations.
5225
     */
5438
     */
5226
    public function test_send_message_to_conversation_linked_group_conversation() {
5439
    public function test_send_message_to_conversation_linked_group_conversation(): void {
-
 
5440
        global $CFG, $PAGE;
Línea 5227... Línea 5441...
5227
        global $CFG, $PAGE;
5441
        $this->resetAfterTest();
5228
 
5442
 
5229
        // Create some users.
5443
        // Create some users.
5230
        $user1 = self::getDataGenerator()->create_user();
5444
        $user1 = self::getDataGenerator()->create_user();
Línea 5284... Línea 5498...
5284
    }
5498
    }
Línea 5285... Línea 5499...
5285
 
5499
 
5286
    /**
5500
    /**
5287
     * Test verifying that messages cannot be sent to conversations that don't exist.
5501
     * Test verifying that messages cannot be sent to conversations that don't exist.
5288
     */
5502
     */
-
 
5503
    public function test_send_message_to_conversation_non_existent_conversation(): void {
-
 
5504
        $this->resetAfterTest();
5289
    public function test_send_message_to_conversation_non_existent_conversation() {
5505
 
5290
        // Get a bunch of conversations, some group, some individual and in different states.
5506
        // Get a bunch of conversations, some group, some individual and in different states.
5291
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
5507
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 5292... Línea 5508...
5292
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
5508
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 5296... Línea 5512...
5296
    }
5512
    }
Línea 5297... Línea 5513...
5297
 
5513
 
5298
    /**
5514
    /**
5299
     * Test verifying that messages cannot be sent to conversations by users who are not members.
5515
     * Test verifying that messages cannot be sent to conversations by users who are not members.
5300
     */
5516
     */
-
 
5517
    public function test_send_message_to_conversation_non_member(): void {
-
 
5518
        $this->resetAfterTest();
5301
    public function test_send_message_to_conversation_non_member() {
5519
 
5302
        // Get a bunch of conversations, some group, some individual and in different states.
5520
        // Get a bunch of conversations, some group, some individual and in different states.
5303
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
5521
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 5304... Línea 5522...
5304
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
5522
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 5315... Línea 5533...
5315
    }
5533
    }
Línea 5316... Línea 5534...
5316
 
5534
 
5317
    /**
5535
    /**
5318
     * Test verifying that messages cannot be sent to conversations by users who are not members.
5536
     * Test verifying that messages cannot be sent to conversations by users who are not members.
5319
     */
5537
     */
-
 
5538
    public function test_send_message_to_conversation_blocked_user(): void {
-
 
5539
        $this->resetAfterTest();
5320
    public function test_send_message_to_conversation_blocked_user() {
5540
 
5321
        // Get a bunch of conversations, some group, some individual and in different states.
5541
        // Get a bunch of conversations, some group, some individual and in different states.
5322
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
5542
        list($user1, $user2, $user3, $user4, $ic1, $ic2, $ic3,
Línea 5323... Línea 5543...
5323
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
5543
            $gc1, $gc2, $gc3, $gc4, $gc5, $gc6) = $this->create_conversation_test_data();
Línea 5341... Línea 5561...
5341
    }
5561
    }
Línea 5342... Línea 5562...
5342
 
5562
 
5343
    /**
5563
    /**
5344
     * Test the get_conversation() function with a muted conversation.
5564
     * Test the get_conversation() function with a muted conversation.
5345
     */
5565
     */
5346
    public function test_get_conversation_with_muted_conversation() {
5566
    public function test_get_conversation_with_muted_conversation(): void {
Línea 5347... Línea 5567...
5347
        $this->resetAfterTest();
5567
        $this->resetAfterTest();
5348
 
5568
 
Línea 5747... Línea 5967...
5747
        $deletemessages,
5967
        $deletemessages,
5748
        $arguments,
5968
        $arguments,
5749
        $expectedcounts,
5969
        $expectedcounts,
5750
        $expectedunreadcounts,
5970
        $expectedunreadcounts,
5751
        $deletedusers
5971
        $deletedusers
5752
    ) {
5972
    ): void {
-
 
5973
        $this->resetAfterTest();
-
 
5974
 
5753
        $generator = $this->getDataGenerator();
5975
        $generator = $this->getDataGenerator();
5754
        $users = [
5976
        $users = [
5755
            $generator->create_user(),
5977
            $generator->create_user(),
5756
            $generator->create_user(),
5978
            $generator->create_user(),
5757
            $generator->create_user(),
5979
            $generator->create_user(),
Línea 5824... Línea 6046...
5824
    }
6046
    }
Línea 5825... Línea 6047...
5825
 
6047
 
5826
    /**
6048
    /**
5827
     * Test the count_contacts() function.
6049
     * Test the count_contacts() function.
5828
     */
6050
     */
-
 
6051
    public function test_count_contacts(): void {
-
 
6052
        $this->resetAfterTest();
5829
    public function test_count_contacts() {
6053
 
5830
        $user1 = self::getDataGenerator()->create_user();
6054
        $user1 = self::getDataGenerator()->create_user();
5831
        $user2 = self::getDataGenerator()->create_user();
6055
        $user2 = self::getDataGenerator()->create_user();
Línea 5832... Línea 6056...
5832
        $user3 = self::getDataGenerator()->create_user();
6056
        $user3 = self::getDataGenerator()->create_user();
Línea 5870... Línea 6094...
5870
        $deletemessages,
6094
        $deletemessages,
5871
        $arguments,
6095
        $arguments,
5872
        $expectedcounts,
6096
        $expectedcounts,
5873
        $expectedunreadcounts,
6097
        $expectedunreadcounts,
5874
        $deletedusers
6098
        $deletedusers
5875
    ) {
6099
    ): void {
5876
        $this->resetAfterTest();
6100
        $this->resetAfterTest();
5877
        $generator = $this->getDataGenerator();
6101
        $generator = $this->getDataGenerator();
5878
        $users = [
6102
        $users = [
5879
            $generator->create_user(),
6103
            $generator->create_user(),
5880
            $generator->create_user(),
6104
            $generator->create_user(),
Línea 5935... Línea 6159...
5935
            $counts['types'][api::MESSAGE_CONVERSATION_TYPE_GROUP]);
6159
            $counts['types'][api::MESSAGE_CONVERSATION_TYPE_GROUP]);
5936
        $this->assertEquals($expectedunreadcounts['types'][api::MESSAGE_CONVERSATION_TYPE_SELF],
6160
        $this->assertEquals($expectedunreadcounts['types'][api::MESSAGE_CONVERSATION_TYPE_SELF],
5937
            $counts['types'][api::MESSAGE_CONVERSATION_TYPE_SELF]);
6161
            $counts['types'][api::MESSAGE_CONVERSATION_TYPE_SELF]);
5938
    }
6162
    }
Línea 5939... Línea 6163...
5939
 
6163
 
5940
    public function test_delete_all_conversation_data() {
6164
    public function test_delete_all_conversation_data(): void {
Línea 5941... Línea 6165...
5941
        global $DB;
6165
        global $DB;
Línea 5942... Línea 6166...
5942
 
6166
 
Línea 6047... Línea 6271...
6047
    }
6271
    }
Línea 6048... Línea 6272...
6048
 
6272
 
6049
    /**
6273
    /**
6050
     * Tests the user can delete message for all users as a teacher.
6274
     * Tests the user can delete message for all users as a teacher.
6051
     */
6275
     */
6052
    public function test_can_delete_message_for_all_users_teacher() {
6276
    public function test_can_delete_message_for_all_users_teacher(): void {
6053
        global $DB;
6277
        global $DB;
Línea 6054... Línea 6278...
6054
        $this->resetAfterTest(true);
6278
        $this->resetAfterTest(true);
6055
 
6279
 
Línea 6075... Línea 6299...
6075
    }
6299
    }
Línea 6076... Línea 6300...
6076
 
6300
 
6077
    /**
6301
    /**
6078
     * Tests the user can delete message for all users as a student.
6302
     * Tests the user can delete message for all users as a student.
6079
     */
6303
     */
6080
    public function test_can_delete_message_for_all_users_student() {
6304
    public function test_can_delete_message_for_all_users_student(): void {
Línea 6081... Línea 6305...
6081
        $this->resetAfterTest(true);
6305
        $this->resetAfterTest(true);
6082
 
6306
 
Línea 6098... Línea 6322...
6098
    }
6322
    }
Línea 6099... Línea 6323...
6099
 
6323
 
6100
    /**
6324
    /**
6101
     * Tests tdelete message for all users in group conversation.
6325
     * Tests tdelete message for all users in group conversation.
6102
     */
6326
     */
6103
    public function test_delete_message_for_all_users_group_conversation() {
6327
    public function test_delete_message_for_all_users_group_conversation(): void {
6104
        global $DB;
6328
        global $DB;
Línea 6105... Línea 6329...
6105
        $this->resetAfterTest(true);
6329
        $this->resetAfterTest(true);
6106
 
6330
 
Línea 6144... Línea 6368...
6144
    }
6368
    }
Línea 6145... Línea 6369...
6145
 
6369
 
6146
    /**
6370
    /**
6147
     * Tests delete message for all users in private conversation.
6371
     * Tests delete message for all users in private conversation.
6148
     */
6372
     */
6149
    public function test_delete_message_for_all_users_individual_conversation() {
6373
    public function test_delete_message_for_all_users_individual_conversation(): void {
6150
        global $DB;
6374
        global $DB;
Línea 6151... Línea 6375...
6151
        $this->resetAfterTest(true);
6375
        $this->resetAfterTest(true);
6152
 
6376
 
Línea 6177... Línea 6401...
6177
 
6401
 
6178
    /**
6402
    /**
6179
     * Test retrieving conversation messages by providing a timefrom higher than last message timecreated. It should return no
6403
     * Test retrieving conversation messages by providing a timefrom higher than last message timecreated. It should return no
6180
     * messages but keep the return structure to not break when called from the ws.
6404
     * messages but keep the return structure to not break when called from the ws.
6181
     */
6405
     */
-
 
6406
    public function test_get_conversation_messages_timefrom_higher_than_last_timecreated(): void {
-
 
6407
        $this->resetAfterTest();
6182
    public function test_get_conversation_messages_timefrom_higher_than_last_timecreated() {
6408
 
6183
        // Create some users.
6409
        // Create some users.
6184
        $user1 = self::getDataGenerator()->create_user();
6410
        $user1 = self::getDataGenerator()->create_user();
6185
        $user2 = self::getDataGenerator()->create_user();
6411
        $user2 = self::getDataGenerator()->create_user();
6186
        $user3 = self::getDataGenerator()->create_user();
6412
        $user3 = self::getDataGenerator()->create_user();