19 declare(strict_types=1);
33 $this->ilUserMock->expects($this->once())->method(
'getId')->willReturn($userId);
34 $this->ilUserMock->expects($this->once())->method(
'isAnonymous')->willReturn(
false);
36 $this->assertSame($userId, $this->
user->getUserId());
44 $this->ilUserMock->expects($this->once())->method(
'getId')->willReturn($userId);
45 $this->ilUserMock->expects($this->once())->method(
'isAnonymous')->willReturn(
true);
47 $this->ilChatroomMock->method(
'getRoomId')->willReturn($roomId);
56 $this->assertSame($userId, $this->
user->getUserId());
61 $this->ilUserMock->expects($this->once())->method(
'getId')->willReturn(0);
62 $this->ilUserMock->expects($this->once())->method(
'isAnonymous')->willReturn(
true);
64 $this->ilChatroomMock->method(
'getRoomId')->willReturn(99);
66 $this->assertNotNull($this->
user->getUserId());
69 #[DataProvider('usernameDataProvider')] 72 $this->
user->setUsername($username);
73 $this->assertSame($expected, $this->
user->getUsername());
78 $username =
'username';
83 'username' => $username,
87 $this->ilChatroomMock->method(
'getRoomId')->willReturn(99);
89 $this->assertSame($username, $this->
user->getUsername());
106 $this->ilUserMock->expects($this->once())->method(
'getPublicName')->willReturn($username);
107 $this->ilChatroomMock->method(
'getRoomId')->willReturn($roomId);
109 $this->assertSame($username, $this->
user->getUsername());
114 $this->ilChatroomMock->method(
'getSetting')->willReturn(
'#_anonymous');
116 $firstName = $this->
user->buildAnonymousName();
117 $secondName = $this->
user->buildAnonymousName();
119 $this->assertNotEquals($firstName, $secondName);
124 $username =
'username';
125 $this->ilUserMock->expects($this->once())->method(
'getLogin')->willReturn($username);
127 $this->assertSame($username, $this->
user->buildLogin());
132 $fullname =
'John Doe';
133 $this->ilUserMock->expects($this->once())->method(
'getPublicName')->willReturn($fullname);
135 $this->assertSame($fullname, $this->
user->buildFullname());
142 $this->ilUserMock->expects($this->once())->method(
'getFirstname')->willReturn($firstname);
143 $this->ilUserMock->expects($this->once())->method(
'getLastname')->willReturn($lastname);
145 $this->assertSame(
'J. Doe', $this->
user->buildShortname());
150 $this->ilUserMock->method(
'isAnonymous')->willReturn(
true);
151 $this->ilChatroomMock->method(
'getSetting')->willReturn(
'#_anonymous');
153 $first = $this->
user->getChatNameSuggestions();
154 $second = $this->
user->getChatNameSuggestions();
156 $this->assertNotEquals($first, $second);
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');
168 $suggestions = $this->
user->getChatNameSuggestions();
170 $this->assertSame(
'John Doe', $suggestions[
'fullname']);
171 $this->assertSame(
'J. Doe', $suggestions[
'shortname']);
172 $this->assertSame(
'jdoe', $suggestions[
'login']);
178 [
'username',
'username'],
179 [
'>username<',
'>username<'],
187 $this->ilUserMock = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->onlyMethods(
188 [
'getId',
'isAnonymous',
'getLogin',
'getPublicName',
'getFirstname',
'getLastname']
190 $this->ilChatroomMock = $this->getMockBuilder(ilChatroom::class)->disableOriginalConstructor()->onlyMethods(
191 [
'getRoomId',
'getSetting']
testSetUsername(string $username, string $expected)
testGetUsernameFromIlObjUser()
testGetUserIdRandomGeneratedIfAnonymous()
testGetUserIdIfNotAnonymous()
ilObjUser &MockObject $ilUserMock
testGetChatNameSuggestionsIfAnonymous()
testGetUsernameFromSession()
testGetChatNameSuggestionsIfNotAnonymous()
testGetUserIdFromSessionIfAnonymous()
static set(string $a_var, $a_val)
Set a value.
static usernameDataProvider()