|
1
|
|
|
<?php |
|
2
|
|
|
namespace tests\codeception\unit; |
|
3
|
|
|
|
|
4
|
|
|
use jones\wschat\components\ChatRoom; |
|
5
|
|
|
use jones\wschat\components\User; |
|
6
|
|
|
use yii\codeception\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class UserTest |
|
10
|
|
|
* @package tests\codeception\unit |
|
11
|
|
|
*/ |
|
12
|
|
|
class UserTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
protected $rid = 1; |
|
15
|
|
|
protected $id = 1; |
|
16
|
|
|
|
|
17
|
|
|
public function testInit() |
|
18
|
|
|
{ |
|
19
|
|
|
$user = new User($this->id); |
|
20
|
|
|
$this->assertInstanceOf('jones\wschat\components\User', $user, |
|
21
|
|
|
'User should be instance of jones\wschat\components\User'); |
|
22
|
|
|
$this->assertEquals($this->id, $user->getId(), 'Id\'s should match'); |
|
23
|
|
|
$user->setRid($this->rid); |
|
24
|
|
|
$this->assertEquals($this->rid, $user->getRid(), 'Resource id\'s should match'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testUserChat() |
|
28
|
|
|
{ |
|
29
|
|
|
$user = new User($this->id); |
|
30
|
|
|
$user->setChat(new ChatRoom()); |
|
31
|
|
|
$chat = $user->getChat(); |
|
32
|
|
|
$this->assertInstanceOf('jones\wschat\components\ChatRoom', $chat, |
|
33
|
|
|
'Chat should be instance of jones\wschat\components\ChatRoom'); |
|
34
|
|
|
$users = $chat->getUsers(); |
|
35
|
|
|
$this->assertEquals(1, count($users), 'Chat should contain only one user'); |
|
36
|
|
|
$this->assertTrue(isset($users[$this->id]), 'User should be in chat'); |
|
37
|
|
|
$this->assertInstanceOf('jones\wschat\components\User', $users[$this->id], |
|
38
|
|
|
'Chat user should be instance of jones\wschat\components\User'); |
|
39
|
|
|
} |
|
40
|
|
|
} |