27 if (
defined(
'ILIAS_PHPUNIT_CONTEXT')) {
28 include_once(
"./Services/PHPUnit/classes/class.ilUnitUtil.php");
29 ilUnitUtil::performInitialisation();
31 chdir(dirname(__FILE__));
35 require_once
'./Modules/Chatroom/classes/class.ilChatroomUser.php';
37 $this->ilUserMock = $this->getMockBuilder(
'ilObjUser')->disableOriginalConstructor()->setMethods(
38 array(
'getId',
'isAnonymous',
'getLogin',
'getPublicName',
'getFirstname',
'getLastname')
40 $this->ilChatroomMock = $this->getMockBuilder(
'ilChatroom')->disableOriginalConstructor()->setMethods(
41 array(
'getRoomId',
'getSetting')
49 $this->assertInstanceOf(
'ilChatroomUser', $this->
user);
56 $this->ilUserMock->expects($this->once())->method(
'getId')->will($this->returnValue($userId));
57 $this->ilUserMock->expects($this->once())->method(
'isAnonymous')->will($this->returnValue(
false));
59 $this->assertEquals($userId, $this->
user->getUserId());
67 $this->ilUserMock->expects($this->once())->method(
'getId')->will($this->returnValue($userId));
68 $this->ilUserMock->expects($this->once())->method(
'isAnonymous')->will($this->returnValue(
true));
70 $this->ilChatroomMock->expects($this->any())->method(
'getRoomId')->will($this->returnValue($roomId));
78 $this->assertEquals($userId, $this->
user->getUserId());
83 $this->ilUserMock->expects($this->once())->method(
'getId')->will($this->returnValue(null));
84 $this->ilUserMock->expects($this->once())->method(
'isAnonymous')->will($this->returnValue(
true));
86 $this->ilChatroomMock->expects($this->any())->method(
'getRoomId')->will($this->returnValue(99));
88 $this->assertNotNull($this->
user->getUserId());
98 $this->
user->setUsername($username);
99 $this->assertEquals($expected, $this->
user->getUsername());
104 $username =
'username';
106 $_SESSION[
'chat'][$roomId][
'username'] = $username;
108 $this->ilChatroomMock->expects($this->any())->method(
'getRoomId')->will($this->returnValue(99));
110 $this->assertEquals($username, $this->
user->getUsername());
121 $_SESSION[
'chat'][$roomId][
'username'] =
'';
123 $this->ilUserMock->expects($this->once())->method(
'getLogin')->will($this->returnValue($username));
124 $this->ilChatroomMock->expects($this->any())->method(
'getRoomId')->will($this->returnValue($roomId));
126 $this->assertEquals($username, $this->
user->getUsername());
131 $this->ilChatroomMock->expects($this->any())->method(
'getSetting')->will($this->returnValue(
'#_anonymous'));
133 $firstName = $this->
user->buildAnonymousName();
134 $secondName = $this->
user->buildAnonymousName();
136 $this->assertNotEquals($firstName, $secondName);
141 $username =
'username';
142 $this->ilUserMock->expects($this->once())->method(
'getLogin')->will($this->returnValue($username));
144 $this->assertEquals($username, $this->
user->buildLogin());
149 $fullname =
'John Doe';
150 $this->ilUserMock->expects($this->once())->method(
'getPublicName')->will($this->returnValue($fullname));
152 $this->assertEquals($fullname, $this->
user->buildFullname());
159 $this->ilUserMock->expects($this->once())->method(
'getFirstname')->will($this->returnValue($firstname));
160 $this->ilUserMock->expects($this->once())->method(
'getLastname')->will($this->returnValue($lastname));
162 $this->assertEquals(
'J. Doe', $this->
user->buildShortname());
167 $this->ilUserMock->expects($this->any())->method(
'isAnonymous')->will($this->returnValue(
true));
168 $this->ilChatroomMock->expects($this->any())->method(
'getSetting')->will($this->returnValue(
'#_anonymous'));
170 $first = $this->
user->getChatNameSuggestions();
171 $second = $this->
user->getChatNameSuggestions();
173 $this->assertNotEquals($first, $second);
178 $this->ilUserMock->expects($this->any())->method(
'isAnonymous')->will($this->returnValue(
false));
179 $this->ilUserMock->expects($this->once())->method(
'getFirstname')->will($this->returnValue(
'John'));
180 $this->ilUserMock->expects($this->once())->method(
'getLastname')->will($this->returnValue(
'Doe'));
181 $this->ilUserMock->expects($this->once())->method(
'getPublicName')->will($this->returnValue(
'John Doe'));
182 $this->ilUserMock->expects($this->once())->method(
'getLogin')->will($this->returnValue(
'jdoe'));
183 $this->ilChatroomMock->expects($this->any())->method(
'getSetting')->will($this->returnValue(
'#_anonymous'));
185 $suggestions = $this->
user->getChatNameSuggestions();
187 $this->assertEquals(
'John Doe', $suggestions[
'fullname']);
188 $this->assertEquals(
'J. Doe', $suggestions[
'shortname']);
189 $this->assertEquals(
'jdoe', $suggestions[
'login']);
198 array(
'username',
'username'),
199 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()