ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 ()
 

Static Public Member Functions

static usernameDataProvider ()
 

Protected Member Functions

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

Protected Attributes

ilObjUser $ilUserMock
 
ilChatroomUser $user
 
- Protected Attributes inherited from ilChatroomAbstractTestBase
 $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 ilChatroomUserTest.php.

Member Function Documentation

◆ setUp()

ilChatroomUserTest::setUp ( )
protected

Definition at line 189 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

189  : void
190  {
191  parent::setUp();
192 
193  $this->ilUserMock = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
194  ['getId', 'isAnonymous', 'getLogin', 'getPublicName', 'getFirstname', 'getLastname']
195  )->getMock();
196  $this->ilChatroomMock = $this->getMockBuilder(ilChatroom::class)->disableOriginalConstructor()->onlyMethods(
197  ['getRoomId', 'getSetting']
198  )->getMock();
199 
200  $this->user = new ilChatroomUser($this->ilUserMock, $this->ilChatroomMock);
201  }
Class ilChatroomUser.
+ Here is the call graph for this function:

◆ testBuildAnonymousName()

ilChatroomUserTest::testBuildAnonymousName ( )

Definition at line 118 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

118  : void
119  {
120  $this->ilChatroomMock->method('getSetting')->willReturn('#_anonymous');
121 
122  $firstName = $this->user->buildAnonymousName();
123  $secondName = $this->user->buildAnonymousName();
124 
125  $this->assertNotEquals($firstName, $secondName);
126  }
+ Here is the call graph for this function:

◆ testBuildFullname()

ilChatroomUserTest::testBuildFullname ( )

Definition at line 136 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

136  : void
137  {
138  $fullname = 'John Doe';
139  $this->ilUserMock->expects($this->once())->method('getPublicName')->willReturn($fullname);
140 
141  $this->assertSame($fullname, $this->user->buildFullname());
142  }
+ Here is the call graph for this function:

◆ testBuildLogin()

ilChatroomUserTest::testBuildLogin ( )

Definition at line 128 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

128  : void
129  {
130  $username = 'username';
131  $this->ilUserMock->expects($this->once())->method('getLogin')->willReturn($username);
132 
133  $this->assertSame($username, $this->user->buildLogin());
134  }
+ Here is the call graph for this function:

◆ testBuildShortname()

ilChatroomUserTest::testBuildShortname ( )

Definition at line 144 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

144  : void
145  {
146  $firstname = 'John';
147  $lastname = 'Doe';
148  $this->ilUserMock->expects($this->once())->method('getFirstname')->willReturn($firstname);
149  $this->ilUserMock->expects($this->once())->method('getLastname')->willReturn($lastname);
150 
151  $this->assertSame('J. Doe', $this->user->buildShortname());
152  }
+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfAnonymous ( )

Definition at line 154 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

154  : void
155  {
156  $this->ilUserMock->method('isAnonymous')->willReturn(true);
157  $this->ilChatroomMock->method('getSetting')->willReturn('#_anonymous');
158 
159  $first = $this->user->getChatNameSuggestions();
160  $second = $this->user->getChatNameSuggestions();
161 
162  $this->assertNotEquals($first, $second);
163  }
+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfNotAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfNotAnonymous ( )

Definition at line 165 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

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

◆ testGetUserIdFromSessionIfAnonymous()

ilChatroomUserTest::testGetUserIdFromSessionIfAnonymous ( )

Definition at line 43 of file ilChatroomUserTest.php.

References 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  }
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 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 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 102 of file ilChatroomUserTest.php.

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

102  : void
103  {
104  $username = 'login';
105  $roomId = 99;
106  ilSession::set('chat', [
107  $roomId => [
108  'username' => '',
109  ],
110  ]);
111 
112  $this->ilUserMock->expects($this->once())->method('getPublicName')->willReturn($username);
113  $this->ilChatroomMock->method('getRoomId')->willReturn($roomId);
114 
115  $this->assertSame($username, $this->user->getUsername());
116  }
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

◆ testGetUsernameFromSession()

ilChatroomUserTest::testGetUsernameFromSession ( )

Definition at line 82 of file ilChatroomUserTest.php.

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

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

Definition at line 76 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

76  : void
77  {
78  $this->user->setUsername($username);
79  $this->assertSame($expected, $this->user->getUsername());
80  }
+ Here is the call graph for this function:

◆ usernameDataProvider()

static ilChatroomUserTest::usernameDataProvider ( )
static

Definition at line 181 of file ilChatroomUserTest.php.

181  : array
182  {
183  return [
184  ['username', 'username'],
185  ['>username<', '&gt;username&lt;'],
186  ];
187  }

Field Documentation

◆ $ilUserMock

ilObjUser ilChatroomUserTest::$ilUserMock
protected

Definition at line 30 of file ilChatroomUserTest.php.

◆ $user

ilChatroomUser ilChatroomUserTest::$user
protected

Definition at line 31 of file ilChatroomUserTest.php.


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