mantis-matrix-integration – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 <?php
2  
3 namespace MatrixPhp\Tests;
4  
5 use MatrixPhp\Exceptions\MatrixException;
6 use MatrixPhp\Exceptions\MatrixHttpLibException;
7 use MatrixPhp\Exceptions\ValidationException;
8 use GuzzleHttp\Client;
9 use GuzzleHttp\Psr7\Response;
10 use GuzzleHttp\Psr7\Request;
11 use MatrixPhp\MatrixClient;
12 use MatrixPhp\Room;
13 use MatrixPhp\User;
14  
15 class UserTest extends BaseTestCase {
16 const HOSTNAME = "http://localhost";
17 protected $userId = "@test:localhost";
18 protected $roomId = '!test:localhost';
19  
20 protected MatrixClient $client;
21  
22 protected User $user;
23  
24 protected Room $room;
25  
26 protected function setUp(): void
27 {
28 parent::setUp();
29 $this->client = new MatrixClient(self::HOSTNAME);
30 $this->user = new User($this->client->api(), $this->userId);
31 $this->room = $this->invokePrivateMethod($this->client, 'mkRoom', [$this->roomId]);
32 }
33  
34 public function testDisplayName() {
35 // No displayname
36 $displayname = 'test';
37 $this->assertEquals($this->user->userId(), $this->user->getDisplayName($this->room));
38 $container = [];
39 $handler = $this->getMockClientHandler([new Response(200, [], '{}')], $container);
40 $this->client->api()->setClient(new Client(['handler' => $handler]));
41 $this->assertEquals($this->user->userId(), $this->user->getDisplayName());
42 $this->assertEquals(1, count($container));
43  
44  
45 // $mapi->whoami();
46 // /** @var Request $req */
47 // $req = array_get($container, '0.request');
48 }
49  
50 public function testDisplayNameGlobal() {
51 $displayname = 'test';
52  
53 // Get global displayname
54 $container = [];
55 $str = sprintf('{"displayname": "%s"}', $displayname);
56 $handler = $this->getMockClientHandler([new Response(200, [], $str)], $container);
57 $this->client->api()->setClient(new Client(['handler' => $handler]));
58 $this->assertEquals($displayname, $this->user->getDisplayName());
59 $this->assertEquals(1, count($container));
60  
61 }
62 }