ILIAS  release_8 Revision v8.24
ilChatroomUserTest Class Reference

Class ilChatroomUserTest. More...

+ Inheritance diagram for ilChatroomUserTest:
+ Collaboration diagram for ilChatroomUserTest:

Public Member Functions

 testGetUserIdIfNotAnonymous ()
 
 testGetUserIdFromSessionIfAnonymous ()
 
 testGetUserIdRandomGeneratedIfAnonymous ()
 
 testSetUsername (string $username, string $expected)
 @dataProvider usernameDataProvider More...
 
 testGetUsernameFromSession ()
 
 testGetUsernameFromIlObjUser ()
 
 testBuildAnonymousName ()
 
 testBuildLogin ()
 
 testBuildFullname ()
 
 testBuildShortname ()
 
 testGetChatNameSuggestionsIfAnonymous ()
 
 testGetChatNameSuggestionsIfNotAnonymous ()
 
 usernameDataProvider ()
 

Protected Member Functions

 setUp ()
 
- Protected Member Functions inherited from ilChatroomAbstractTest
 setUp ()
 
 tearDown ()
 
 createIlChatroomMock ()
 
 createIlChatroomUserMock ()
 
 createGlobalIlDBMock ()
 
 setGlobalVariable (string $name, $value)
 

Protected Attributes

ilObjUser $ilUserMock
 
ilChatroomUser $user
 
- Protected Attributes inherited from ilChatroomAbstractTest
 $ilChatroomMock
 
 $ilChatroomUserMock
 

Detailed Description

Class ilChatroomUserTest.

Author
Thomas Joußen tjous.nosp@m.sen@.nosp@m.gmx.d.nosp@m.e

Definition at line 27 of file class.ilChatroomUserTest.php.

Member Function Documentation

◆ setUp()

ilChatroomUserTest::setUp ( )
protected

Reimplemented from ilChatroomAbstractTest.

Definition at line 194 of file class.ilChatroomUserTest.php.

194 : void
195 {
196 parent::setUp();
197
198 $this->ilUserMock = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
199 ['getId', 'isAnonymous', 'getLogin', 'getPublicName', 'getFirstname', 'getLastname']
200 )->getMock();
201 $this->ilChatroomMock = $this->getMockBuilder(ilChatroom::class)->disableOriginalConstructor()->onlyMethods(
202 ['getRoomId', 'getSetting']
203 )->getMock();
204
205 $this->user = new ilChatroomUser($this->ilUserMock, $this->ilChatroomMock);
206 }
Class ilChatroomUser.

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testBuildAnonymousName()

ilChatroomUserTest::testBuildAnonymousName ( )

Definition at line 120 of file class.ilChatroomUserTest.php.

120 : void
121 {
122 $this->ilChatroomMock->method('getSetting')->willReturn('#_anonymous');
123
124 $firstName = $this->user->buildAnonymousName();
125 $secondName = $this->user->buildAnonymousName();
126
127 $this->assertNotEquals($firstName, $secondName);
128 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testBuildFullname()

ilChatroomUserTest::testBuildFullname ( )

Definition at line 138 of file class.ilChatroomUserTest.php.

138 : void
139 {
140 $fullname = 'John Doe';
141 $this->ilUserMock->expects($this->once())->method('getPublicName')->willReturn($fullname);
142
143 $this->assertSame($fullname, $this->user->buildFullname());
144 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testBuildLogin()

ilChatroomUserTest::testBuildLogin ( )

Definition at line 130 of file class.ilChatroomUserTest.php.

130 : void
131 {
132 $username = 'username';
133 $this->ilUserMock->expects($this->once())->method('getLogin')->willReturn($username);
134
135 $this->assertSame($username, $this->user->buildLogin());
136 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testBuildShortname()

ilChatroomUserTest::testBuildShortname ( )

Definition at line 146 of file class.ilChatroomUserTest.php.

146 : void
147 {
148 $firstname = 'John';
149 $lastname = 'Doe';
150 $this->ilUserMock->expects($this->once())->method('getFirstname')->willReturn($firstname);
151 $this->ilUserMock->expects($this->once())->method('getLastname')->willReturn($lastname);
152
153 $this->assertSame('J. Doe', $this->user->buildShortname());
154 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfAnonymous ( )

Definition at line 156 of file class.ilChatroomUserTest.php.

156 : void
157 {
158 $this->ilUserMock->method('isAnonymous')->willReturn(true);
159 $this->ilChatroomMock->method('getSetting')->willReturn('#_anonymous');
160
161 $first = $this->user->getChatNameSuggestions();
162 $second = $this->user->getChatNameSuggestions();
163
164 $this->assertNotEquals($first, $second);
165 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfNotAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfNotAnonymous ( )

Definition at line 167 of file class.ilChatroomUserTest.php.

167 : void
168 {
169 $this->ilUserMock->method('isAnonymous')->willReturn(false);
170 $this->ilUserMock->expects($this->once())->method('getFirstname')->willReturn('John');
171 $this->ilUserMock->expects($this->once())->method('getLastname')->willReturn('Doe');
172 $this->ilUserMock->expects($this->once())->method('getPublicName')->willReturn('John Doe');
173 $this->ilUserMock->expects($this->once())->method('getLogin')->willReturn('jdoe');
174 $this->ilChatroomMock->method('getSetting')->willReturn('#_anonymous');
175
176 $suggestions = $this->user->getChatNameSuggestions();
177
178 $this->assertSame('John Doe', $suggestions['fullname']);
179 $this->assertSame('J. Doe', $suggestions['shortname']);
180 $this->assertSame('jdoe', $suggestions['login']);
181 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testGetUserIdFromSessionIfAnonymous()

ilChatroomUserTest::testGetUserIdFromSessionIfAnonymous ( )

Definition at line 43 of file class.ilChatroomUserTest.php.

43 : void
44 {
45 $userId = 6;
46 $roomId = 99;
47
48 $this->ilUserMock->expects($this->once())->method('getId')->willReturn($userId);
49 $this->ilUserMock->expects($this->once())->method('isAnonymous')->willReturn(true);
50
51 $this->ilChatroomMock->method('getRoomId')->willReturn($roomId);
52
53 $session = [
54 $roomId => [
55 'user_id' => $userId,
56 ],
57 ];
58 ilSession::set('chat', $session);
59
60 $this->assertSame($userId, $this->user->getUserId());
61 }
static set(string $a_var, $a_val)
Set a value.
$session

References $session, ilSession\set(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testGetUserIdIfNotAnonymous()

ilChatroomUserTest::testGetUserIdIfNotAnonymous ( )

Definition at line 33 of file class.ilChatroomUserTest.php.

33 : void
34 {
35 $userId = 6;
36
37 $this->ilUserMock->expects($this->once())->method('getId')->willReturn($userId);
38 $this->ilUserMock->expects($this->once())->method('isAnonymous')->willReturn(false);
39
40 $this->assertSame($userId, $this->user->getUserId());
41 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testGetUserIdRandomGeneratedIfAnonymous()

ilChatroomUserTest::testGetUserIdRandomGeneratedIfAnonymous ( )

Definition at line 63 of file class.ilChatroomUserTest.php.

63 : void
64 {
65 $this->ilUserMock->expects($this->once())->method('getId')->willReturn(0);
66 $this->ilUserMock->expects($this->once())->method('isAnonymous')->willReturn(true);
67
68 $this->ilChatroomMock->method('getRoomId')->willReturn(99);
69
70 $this->assertNotNull($this->user->getUserId());
71 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testGetUsernameFromIlObjUser()

ilChatroomUserTest::testGetUsernameFromIlObjUser ( )
Todo:
if required session value is not set, there will be a warning. Need to check if required value isset.

Definition at line 104 of file class.ilChatroomUserTest.php.

104 : void
105 {
106 $username = 'login';
107 $roomId = 99;
108 ilSession::set('chat', [
109 $roomId => [
110 'username' => '',
111 ],
112 ]);
113
114 $this->ilUserMock->expects($this->once())->method('getLogin')->willReturn($username);
115 $this->ilChatroomMock->method('getRoomId')->willReturn($roomId);
116
117 $this->assertSame($username, $this->user->getUsername());
118 }

References ilSession\set(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testGetUsernameFromSession()

ilChatroomUserTest::testGetUsernameFromSession ( )

Definition at line 84 of file class.ilChatroomUserTest.php.

84 : void
85 {
86 $username = 'username';
87 $roomId = 99;
88
89 ilSession::set('chat', [
90 $roomId => [
91 'username' => $username,
92 ],
93 ]);
94
95 $this->ilChatroomMock->method('getRoomId')->willReturn(99);
96
97 $this->assertSame($username, $this->user->getUsername());
98 }

References ilSession\set(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testSetUsername()

ilChatroomUserTest::testSetUsername ( string  $username,
string  $expected 
)

@dataProvider usernameDataProvider

Parameters
string$username
string$expected

Definition at line 78 of file class.ilChatroomUserTest.php.

78 : void
79 {
80 $this->user->setUsername($username);
81 $this->assertSame($expected, $this->user->getUsername());
82 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ usernameDataProvider()

ilChatroomUserTest::usernameDataProvider ( )
Returns
array

Definition at line 186 of file class.ilChatroomUserTest.php.

186 : array
187 {
188 return [
189 ['username', 'username'],
190 ['>username<', '&gt;username&lt;'],
191 ];
192 }

Field Documentation

◆ $ilUserMock

ilObjUser ilChatroomUserTest::$ilUserMock
protected

Definition at line 30 of file class.ilChatroomUserTest.php.

◆ $user

ilChatroomUser ilChatroomUserTest::$user
protected

Definition at line 31 of file class.ilChatroomUserTest.php.


The documentation for this class was generated from the following file: