27 if(
defined(
'ILIAS_PHPUNIT_CONTEXT'))
29 include_once(
"./Services/PHPUnit/classes/class.ilUnitUtil.php");
30 ilUnitUtil::performInitialisation();
34 chdir(dirname(__FILE__));
38 require_once
'./Modules/Chatroom/classes/class.ilChatroomUser.php';
40 $this->ilUserMock = $this->getMockBuilder(
'ilObjUser')->disableOriginalConstructor()->setMethods(
41 array(
'getId',
'isAnonymous',
'getLogin',
'getPublicName',
'getFirstname',
'getLastname')
43 $this->ilChatroomMock = $this->getMockBuilder(
'ilChatroom')->disableOriginalConstructor()->setMethods(
44 array(
'getRoomId',
'getSetting')
52 $this->assertInstanceOf(
'ilChatroomUser', $this->
user);
59 $this->ilUserMock->expects($this->once())->method(
'getId')->will($this->returnValue($userId));
60 $this->ilUserMock->expects($this->once())->method(
'isAnonymous')->will($this->returnValue(
false));
62 $this->assertEquals($userId, $this->
user->getUserId());
70 $this->ilUserMock->expects($this->once())->method(
'getId')->will($this->returnValue($userId));
71 $this->ilUserMock->expects($this->once())->method(
'isAnonymous')->will($this->returnValue(
true));
73 $this->ilChatroomMock->expects($this->any())->method(
'getRoomId')->will($this->returnValue($roomId));
81 $this->assertEquals($userId, $this->
user->getUserId());
86 $this->ilUserMock->expects($this->once())->method(
'getId')->will($this->returnValue(null));
87 $this->ilUserMock->expects($this->once())->method(
'isAnonymous')->will($this->returnValue(
true));
89 $this->ilChatroomMock->expects($this->any())->method(
'getRoomId')->will($this->returnValue(99));
91 $this->assertNotNull($this->
user->getUserId());
101 $this->
user->setUsername($username);
102 $this->assertEquals($expected, $this->
user->getUsername());
107 $username =
'username';
109 $_SESSION[
'chat'][$roomId][
'username'] = $username;
111 $this->ilChatroomMock->expects($this->any())->method(
'getRoomId')->will($this->returnValue(99));
113 $this->assertEquals($username, $this->
user->getUsername());
124 $_SESSION[
'chat'][$roomId][
'username'] =
'';
126 $this->ilUserMock->expects($this->once())->method(
'getLogin')->will($this->returnValue($username));
127 $this->ilChatroomMock->expects($this->any())->method(
'getRoomId')->will($this->returnValue($roomId));
129 $this->assertEquals($username, $this->
user->getUsername());
134 $this->ilChatroomMock->expects($this->any())->method(
'getSetting')->will($this->returnValue(
'#_anonymous'));
136 $firstName = $this->
user->buildAnonymousName();
137 $secondName = $this->
user->buildAnonymousName();
139 $this->assertNotEquals($firstName, $secondName);
144 $username =
'username';
145 $this->ilUserMock->expects($this->once())->method(
'getLogin')->will($this->returnValue($username));
147 $this->assertEquals($username, $this->
user->buildLogin());
152 $fullname =
'John Doe';
153 $this->ilUserMock->expects($this->once())->method(
'getPublicName')->will($this->returnValue($fullname));
155 $this->assertEquals($fullname, $this->
user->buildFullname());
162 $this->ilUserMock->expects($this->once())->method(
'getFirstname')->will($this->returnValue($firstname));
163 $this->ilUserMock->expects($this->once())->method(
'getLastname')->will($this->returnValue($lastname));
165 $this->assertEquals(
'J. Doe', $this->
user->buildShortname());
170 $this->ilUserMock->expects($this->any())->method(
'isAnonymous')->will($this->returnValue(
true));
171 $this->ilChatroomMock->expects($this->any())->method(
'getSetting')->will($this->returnValue(
'#_anonymous'));
173 $first = $this->
user->getChatNameSuggestions();
174 $second = $this->
user->getChatNameSuggestions();
176 $this->assertNotEquals($first, $second);
181 $this->ilUserMock->expects($this->any())->method(
'isAnonymous')->will($this->returnValue(
false));
182 $this->ilUserMock->expects($this->once())->method(
'getFirstname')->will($this->returnValue(
'John'));
183 $this->ilUserMock->expects($this->once())->method(
'getLastname')->will($this->returnValue(
'Doe'));
184 $this->ilUserMock->expects($this->once())->method(
'getPublicName')->will($this->returnValue(
'John Doe'));
185 $this->ilUserMock->expects($this->once())->method(
'getLogin')->will($this->returnValue(
'jdoe'));
186 $this->ilChatroomMock->expects($this->any())->method(
'getSetting')->will($this->returnValue(
'#_anonymous'));
188 $suggestions = $this->
user->getChatNameSuggestions();
190 $this->assertEquals(
'John Doe', $suggestions[
'fullname']);
191 $this->assertEquals(
'J. Doe', $suggestions[
'shortname']);
192 $this->assertEquals(
'jdoe', $suggestions[
'login']);
201 array(
'username',
'username'),
202 array(
'>username<',
'>username<'),
testGetUsernameFromIlObjUser()
Class ilChatroomUserTest.
testGetUserIdRandomGeneratedIfAnonymous()
testSetUsername($username, $expected)
usernameDataProvider
testGetUserIdIfNotAnonymous()
testGetChatNameSuggestionsIfAnonymous()
Create styles array
The data for the language used.
testGetUsernameFromSession()
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
testGetChatNameSuggestionsIfNotAnonymous()
testGetUserIdFromSessionIfAnonymous()