ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilChatroomUserTest Class Reference
+ Inheritance diagram for ilChatroomUserTest:
+ Collaboration diagram for ilChatroomUserTest:

Public Member Functions

 testGetUserIdIfNotAnonymous ()
 
 testGetUserIdFromSessionIfAnonymous ()
 
 testGetUserIdRandomGeneratedIfAnonymous ()
 
 testSetUsername (string $username, string $expected)
 
 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 &MockObject $ilUserMock
 
ilChatroomUser $user
 
- Protected Attributes inherited from ilChatroomAbstractTestBase
MockObject &ilChatroom $ilChatroomMock
 
MockObject &ilChatroomUser $ilChatroomUserMock
 

Detailed Description

Definition at line 24 of file ilChatroomUserTest.php.

Member Function Documentation

◆ setUp()

ilChatroomUserTest::setUp ( )
protected

Definition at line 183 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

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

◆ testBuildAnonymousName()

ilChatroomUserTest::testBuildAnonymousName ( )

Definition at line 112 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

112  : void
113  {
114  $this->ilChatroomMock->method('getSetting')->willReturn('#_anonymous');
115 
116  $firstName = $this->user->buildAnonymousName();
117  $secondName = $this->user->buildAnonymousName();
118 
119  $this->assertNotEquals($firstName, $secondName);
120  }
+ Here is the call graph for this function:

◆ testBuildFullname()

ilChatroomUserTest::testBuildFullname ( )

Definition at line 130 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

130  : void
131  {
132  $fullname = 'John Doe';
133  $this->ilUserMock->expects($this->once())->method('getPublicName')->willReturn($fullname);
134 
135  $this->assertSame($fullname, $this->user->buildFullname());
136  }
+ Here is the call graph for this function:

◆ testBuildLogin()

ilChatroomUserTest::testBuildLogin ( )

Definition at line 122 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

122  : void
123  {
124  $username = 'username';
125  $this->ilUserMock->expects($this->once())->method('getLogin')->willReturn($username);
126 
127  $this->assertSame($username, $this->user->buildLogin());
128  }
+ Here is the call graph for this function:

◆ testBuildShortname()

ilChatroomUserTest::testBuildShortname ( )

Definition at line 138 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

138  : void
139  {
140  $firstname = 'John';
141  $lastname = 'Doe';
142  $this->ilUserMock->expects($this->once())->method('getFirstname')->willReturn($firstname);
143  $this->ilUserMock->expects($this->once())->method('getLastname')->willReturn($lastname);
144 
145  $this->assertSame('J. Doe', $this->user->buildShortname());
146  }
+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfAnonymous ( )

Definition at line 148 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

148  : void
149  {
150  $this->ilUserMock->method('isAnonymous')->willReturn(true);
151  $this->ilChatroomMock->method('getSetting')->willReturn('#_anonymous');
152 
153  $first = $this->user->getChatNameSuggestions();
154  $second = $this->user->getChatNameSuggestions();
155 
156  $this->assertNotEquals($first, $second);
157  }
+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfNotAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfNotAnonymous ( )

Definition at line 159 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

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

◆ testGetUserIdFromSessionIfAnonymous()

ilChatroomUserTest::testGetUserIdFromSessionIfAnonymous ( )

Definition at line 39 of file ilChatroomUserTest.php.

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

39  : void
40  {
41  $userId = 6;
42  $roomId = 99;
43 
44  $this->ilUserMock->expects($this->once())->method('getId')->willReturn($userId);
45  $this->ilUserMock->expects($this->once())->method('isAnonymous')->willReturn(true);
46 
47  $this->ilChatroomMock->method('getRoomId')->willReturn($roomId);
48 
49  $session = [
50  $roomId => [
51  'user_id' => $userId,
52  ],
53  ];
54  ilSession::set('chat', $session);
55 
56  $this->assertSame($userId, $this->user->getUserId());
57  }
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

◆ testGetUserIdIfNotAnonymous()

ilChatroomUserTest::testGetUserIdIfNotAnonymous ( )

Definition at line 29 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

29  : void
30  {
31  $userId = 6;
32 
33  $this->ilUserMock->expects($this->once())->method('getId')->willReturn($userId);
34  $this->ilUserMock->expects($this->once())->method('isAnonymous')->willReturn(false);
35 
36  $this->assertSame($userId, $this->user->getUserId());
37  }
+ Here is the call graph for this function:

◆ testGetUserIdRandomGeneratedIfAnonymous()

ilChatroomUserTest::testGetUserIdRandomGeneratedIfAnonymous ( )

Definition at line 59 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

59  : void
60  {
61  $this->ilUserMock->expects($this->once())->method('getId')->willReturn(0);
62  $this->ilUserMock->expects($this->once())->method('isAnonymous')->willReturn(true);
63 
64  $this->ilChatroomMock->method('getRoomId')->willReturn(99);
65 
66  $this->assertNotNull($this->user->getUserId());
67  }
+ 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 96 of file ilChatroomUserTest.php.

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

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

◆ testGetUsernameFromSession()

ilChatroomUserTest::testGetUsernameFromSession ( )

Definition at line 76 of file ilChatroomUserTest.php.

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

76  : void
77  {
78  $username = 'username';
79  $roomId = 99;
80 
81  ilSession::set('chat', [
82  $roomId => [
83  'username' => $username,
84  ],
85  ]);
86 
87  $this->ilChatroomMock->method('getRoomId')->willReturn(99);
88 
89  $this->assertSame($username, $this->user->getUsername());
90  }
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 
)

Definition at line 70 of file ilChatroomUserTest.php.

References ILIAS\Repository\user().

70  : void
71  {
72  $this->user->setUsername($username);
73  $this->assertSame($expected, $this->user->getUsername());
74  }
+ Here is the call graph for this function:

◆ usernameDataProvider()

static ilChatroomUserTest::usernameDataProvider ( )
static

Definition at line 175 of file ilChatroomUserTest.php.

175  : array
176  {
177  return [
178  ['username', 'username'],
179  ['>username<', '&gt;username&lt;'],
180  ];
181  }

Field Documentation

◆ $ilUserMock

ilObjUser& MockObject ilChatroomUserTest::$ilUserMock
protected

Definition at line 26 of file ilChatroomUserTest.php.

◆ $user

ilChatroomUser ilChatroomUserTest::$user
protected

Definition at line 27 of file ilChatroomUserTest.php.


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