ILIAS  release_8 Revision v8.23
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)
 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

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

References ILIAS\Repository\user().

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.
+ Here is the call graph for this function:

◆ testBuildAnonymousName()

ilChatroomUserTest::testBuildAnonymousName ( )

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

References ILIAS\Repository\user().

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  }
+ Here is the call graph for this function:

◆ testBuildFullname()

ilChatroomUserTest::testBuildFullname ( )

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

References ILIAS\Repository\user().

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  }
+ Here is the call graph for this function:

◆ testBuildLogin()

ilChatroomUserTest::testBuildLogin ( )

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

References ILIAS\Repository\user().

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  }
+ Here is the call graph for this function:

◆ testBuildShortname()

ilChatroomUserTest::testBuildShortname ( )

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

References ILIAS\Repository\user().

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  }
+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfAnonymous ( )

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

References ILIAS\Repository\user().

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  }
+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfNotAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfNotAnonymous ( )

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

References ILIAS\Repository\user().

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  }
+ Here is the call graph for this function:

◆ testGetUserIdFromSessionIfAnonymous()

ilChatroomUserTest::testGetUserIdFromSessionIfAnonymous ( )

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

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

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  }
$session
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

◆ testGetUserIdIfNotAnonymous()

ilChatroomUserTest::testGetUserIdIfNotAnonymous ( )

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

References ILIAS\Repository\user().

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  }
+ Here is the call graph for this function:

◆ testGetUserIdRandomGeneratedIfAnonymous()

ilChatroomUserTest::testGetUserIdRandomGeneratedIfAnonymous ( )

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

References ILIAS\Repository\user().

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  }
+ 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.

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

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  }
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

◆ testGetUsernameFromSession()

ilChatroomUserTest::testGetUsernameFromSession ( )

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

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

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  }
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

◆ testSetUsername()

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

usernameDataProvider

Parameters
string$username
string$expected

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

References ILIAS\Repository\user().

78  : void
79  {
80  $this->user->setUsername($username);
81  $this->assertSame($expected, $this->user->getUsername());
82  }
+ 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: