Room unit tests
This commit is contained in:
parent
6f95fecff6
commit
b2a9e592a2
|
@ -84,13 +84,13 @@ class User {
|
||||||
/**
|
/**
|
||||||
* Set this users avatar.
|
* Set this users avatar.
|
||||||
*
|
*
|
||||||
* @param $avatarUrl mxc url from previously uploaded
|
* @param string $avatarUrl mxc url from previously uploaded
|
||||||
* @return mixed //FIXME: add proper type
|
* @return mixed //FIXME: add proper type
|
||||||
* @throws Exceptions\MatrixException
|
* @throws Exceptions\MatrixException
|
||||||
* @throws Exceptions\MatrixHttpLibException
|
* @throws Exceptions\MatrixHttpLibException
|
||||||
* @throws Exceptions\MatrixRequestException
|
* @throws Exceptions\MatrixRequestException
|
||||||
*/
|
*/
|
||||||
public function setAvatarUrl($avatarUrl) {
|
public function setAvatarUrl(string $avatarUrl) {
|
||||||
return $this->api->setAvatarUrl($this->userId, $avatarUrl);
|
return $this->api->setAvatarUrl($this->userId, $avatarUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
64
tests/UserTest.php
Normal file
64
tests/UserTest.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Aryess\PhpMatrixSdk;
|
||||||
|
|
||||||
|
use Aryess\PhpMatrixSdk\Exceptions\MatrixException;
|
||||||
|
use Aryess\PhpMatrixSdk\Exceptions\MatrixHttpLibException;
|
||||||
|
use Aryess\PhpMatrixSdk\Exceptions\ValidationException;
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Psr7\Response;
|
||||||
|
use GuzzleHttp\Psr7\Request;
|
||||||
|
|
||||||
|
class UserTest extends BaseTestCase {
|
||||||
|
const HOSTNAME = "http://localhost";
|
||||||
|
protected $userId = "@test:localhost";
|
||||||
|
protected $roomId = '!test:localhost';
|
||||||
|
/**
|
||||||
|
* @var MatrixClient
|
||||||
|
*/
|
||||||
|
protected $client;
|
||||||
|
/**
|
||||||
|
* @var User
|
||||||
|
*/
|
||||||
|
protected $user;
|
||||||
|
/**
|
||||||
|
* @var Room
|
||||||
|
*/
|
||||||
|
protected $room;
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
$this->client = new MatrixClient(self::HOSTNAME);
|
||||||
|
$this->user = new User($this->client->api(), $this->userId);
|
||||||
|
$this->room = $this->invokePrivateMethod($this->client, 'mkRoom', [$this->roomId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDisplayName() {
|
||||||
|
// No displayname
|
||||||
|
$displayname = 'test';
|
||||||
|
$this->assertEquals($this->user->userId(), $this->user->getDisplayName($this->room));
|
||||||
|
$container = [];
|
||||||
|
$handler = $this->getMockClientHandler([new Response(200, [], '{}')], $container);
|
||||||
|
$this->client->api()->setClient(new Client(['handler' => $handler]));
|
||||||
|
$this->assertEquals($this->user->userId(), $this->user->getDisplayName());
|
||||||
|
$this->assertEquals(1, count($container));
|
||||||
|
|
||||||
|
|
||||||
|
// $mapi->whoami();
|
||||||
|
// /** @var Request $req */
|
||||||
|
// $req = array_get($container, '0.request');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDisplayNameGlobal() {
|
||||||
|
$displayname = 'test';
|
||||||
|
|
||||||
|
// Get global displayname
|
||||||
|
$container = [];
|
||||||
|
$str = sprintf('{"displayname": "%s"}', $displayname);
|
||||||
|
$handler = $this->getMockClientHandler([new Response(200, [], $str)], $container);
|
||||||
|
$this->client->api()->setClient(new Client(['handler' => $handler]));
|
||||||
|
$this->assertEquals($displayname, $this->user->getDisplayName());
|
||||||
|
$this->assertEquals(1, count($container));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue