MDL-78738 core_communication: Set avatar from a stored_file
[moodle.git] / communication / provider / matrix / tests / matrix_events_manager_test.php
blob32bb3757e56922ec21a86c7a9eae8ad3f8ba57cd
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 namespace communication_matrix;
19 defined('MOODLE_INTERNAL') || die();
21 require_once(__DIR__ . '/matrix_test_helper_trait.php');
23 /**
24 * Class matrix_events_manager_test to test the matrix events endpoint.
26 * @package communication_matrix
27 * @category test
28 * @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 * @coversDefaultClass \communication_matrix\matrix_events_manager
32 class matrix_events_manager_test extends \advanced_testcase {
34 use matrix_test_helper_trait;
36 public function setUp(): void {
37 parent::setUp();
38 $this->initialise_mock_server();
41 /**
42 * Test the api endpoints url's for matrix.
44 * @return void
45 * @covers ::get_token
46 * @covers ::get_update_avatar_endpoint
47 * @covers ::get_update_room_topic_endpoint
48 * @covers ::get_update_room_name_endpoint
49 * @covers ::get_create_room_endpoint
50 * @covers ::get_delete_room_endpoint
51 * @covers ::get_upload_content_endpoint
53 public function test_matrix_api_endpoints(): void {
54 $this->resetAfterTest();
55 $mockroomid = 'sampleroomid';
56 $mockuserid = 'sampleuserid';
58 $matrixeventsmanager = new matrix_events_manager($mockroomid);
60 // Test the endpoints and information.
61 $this->assertEquals($this->get_matrix_access_token(), $matrixeventsmanager->get_token());
63 $this->assertEquals($this->get_matrix_server_url() . '/' . '_matrix/client/r0/createRoom',
64 $matrixeventsmanager->get_create_room_endpoint());
66 $this->assertEquals($this->get_matrix_server_url() . '/' . '_matrix/client/r0/rooms' .
67 '/' . urlencode($mockroomid) . '/' . 'state/m.room.topic/',
68 $matrixeventsmanager->get_update_room_topic_endpoint());
70 $this->assertEquals($this->get_matrix_server_url(). '/' . '_matrix/client/r0/rooms' .
71 '/' . urlencode($mockroomid) . '/' . 'state/m.room.name/',
72 $matrixeventsmanager->get_update_room_name_endpoint());
74 $this->assertEquals($this->get_matrix_server_url(). '/' . '_synapse/admin/v1/rooms' .
75 '/' . urlencode($mockroomid), $matrixeventsmanager->get_room_info_endpoint());
77 $this->assertEquals($this->get_matrix_server_url() . '/' . '_synapse/admin/v1/rooms/' . urlencode($mockroomid),
78 $matrixeventsmanager->get_delete_room_endpoint());
80 $this->assertEquals($this->get_matrix_server_url() . '/' . '_matrix/media/r0/upload/',
81 $matrixeventsmanager->get_upload_content_endpoint());
83 $this->assertEquals($this->get_matrix_server_url() . '/' . '_matrix/client/r0/rooms' .
84 '/' . urlencode($mockroomid) . '/' . 'state/m.room.avatar/',
85 $matrixeventsmanager->get_update_avatar_endpoint());
87 $this->assertEquals($this->get_matrix_server_url() . '/' . '_matrix/client/r0/rooms' .
88 '/' . urlencode($mockroomid) . '/' . 'joined_members',
89 $matrixeventsmanager->get_room_membership_joined_endpoint());
91 $this->assertEquals($this->get_matrix_server_url() . '/' . '_synapse/admin/v1/join' .
92 '/' . urlencode($mockroomid),
93 $matrixeventsmanager->get_room_membership_join_endpoint());
95 $this->assertEquals($this->get_matrix_server_url() . '/' . '_matrix/client/r0/rooms' .
96 '/' . urlencode($mockroomid) . '/' . 'kick',
97 $matrixeventsmanager->get_room_membership_kick_endpoint());
99 $this->assertEquals($this->get_matrix_server_url() . '/' . '_synapse/admin/v2/users/' . urlencode($mockuserid),
100 $matrixeventsmanager->get_create_user_endpoint($mockuserid));
102 $this->assertEquals($this->get_matrix_server_url() . '/' . '_synapse/admin/v2/users/' . urlencode($mockuserid),
103 $matrixeventsmanager->get_user_info_endpoint($mockuserid));