ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilChatroomUserTest Class Reference

Class ilChatroomUserTest. More...

+ Inheritance diagram for ilChatroomUserTest:
+ Collaboration diagram for ilChatroomUserTest:

Public Member Functions

 testConstructor ()
 
 testGetUserIdIfNotAnonymous ()
 
 testGetUserIdFromSessionIfAnonymous ()
 
 testGetUserIdRandomGeneratedIfAnonymous ()
 
 testSetUsername ($username, $expected)
 @dataProvider usernameDataProvider More...
 
 testGetUsernameFromSession ()
 
 testGetUsernameFromIlObjUser ()
 
 testBuildAnonymousName ()
 
 testBuildLogin ()
 
 testBuildFullname ()
 
 testBuildShortname ()
 
 testGetChatNameSuggestionsIfAnonymous ()
 
 testGetChatNameSuggestionsIfNotAnonymous ()
 
 usernameDataProvider ()
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $ilUserMock
 
 $ilChatroomMock
 
 $user
 

Detailed Description

Class ilChatroomUserTest.

Author
Thomas Joußen tjous.nosp@m.sen@.nosp@m.gmx.d.nosp@m.e

Definition at line 7 of file class.ilChatroomUserTest.php.

Member Function Documentation

◆ setUp()

ilChatroomUserTest::setUp ( )
protected

Definition at line 25 of file class.ilChatroomUserTest.php.

26 {
27 if (defined('ILIAS_PHPUNIT_CONTEXT')) {
28 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
29 ilUnitUtil::performInitialisation();
30 } else {
31 chdir(dirname(__FILE__));
32 chdir('../../../');
33 }
34
35 require_once './Modules/Chatroom/classes/class.ilChatroomUser.php';
36 //require_once 'Services/User/classes/class.ilObjUser.php';
37 $this->ilUserMock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->setMethods(
38 array('getId', 'isAnonymous', 'getLogin', 'getPublicName', 'getFirstname', 'getLastname')
39 )->getMock();
40 $this->ilChatroomMock = $this->getMockBuilder('ilChatroom')->disableOriginalConstructor()->setMethods(
41 array('getRoomId', 'getSetting')
42 )->getMock();
43
44 $this->user = new ilChatroomUser($this->ilUserMock, $this->ilChatroomMock);
45 }
user()
Definition: user.php:4
Class ilChatroomUser.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27

References defined, and user().

+ Here is the call graph for this function:

◆ testBuildAnonymousName()

ilChatroomUserTest::testBuildAnonymousName ( )

Definition at line 129 of file class.ilChatroomUserTest.php.

130 {
131 $this->ilChatroomMock->expects($this->any())->method('getSetting')->will($this->returnValue('#_anonymous'));
132
133 $firstName = $this->user->buildAnonymousName();
134 $secondName = $this->user->buildAnonymousName();
135
136 $this->assertNotEquals($firstName, $secondName);
137 }

References user().

+ Here is the call graph for this function:

◆ testBuildFullname()

ilChatroomUserTest::testBuildFullname ( )

Definition at line 147 of file class.ilChatroomUserTest.php.

148 {
149 $fullname = 'John Doe';
150 $this->ilUserMock->expects($this->once())->method('getPublicName')->will($this->returnValue($fullname));
151
152 $this->assertEquals($fullname, $this->user->buildFullname());
153 }

References user().

+ Here is the call graph for this function:

◆ testBuildLogin()

ilChatroomUserTest::testBuildLogin ( )

Definition at line 139 of file class.ilChatroomUserTest.php.

140 {
141 $username = 'username';
142 $this->ilUserMock->expects($this->once())->method('getLogin')->will($this->returnValue($username));
143
144 $this->assertEquals($username, $this->user->buildLogin());
145 }

References user().

+ Here is the call graph for this function:

◆ testBuildShortname()

ilChatroomUserTest::testBuildShortname ( )

Definition at line 155 of file class.ilChatroomUserTest.php.

156 {
157 $firstname = 'John';
158 $lastname = 'Doe';
159 $this->ilUserMock->expects($this->once())->method('getFirstname')->will($this->returnValue($firstname));
160 $this->ilUserMock->expects($this->once())->method('getLastname')->will($this->returnValue($lastname));
161
162 $this->assertEquals('J. Doe', $this->user->buildShortname());
163 }

References user().

+ Here is the call graph for this function:

◆ testConstructor()

ilChatroomUserTest::testConstructor ( )

Definition at line 47 of file class.ilChatroomUserTest.php.

48 {
49 $this->assertInstanceOf('ilChatroomUser', $this->user);
50 }

References user().

+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfAnonymous ( )

Definition at line 165 of file class.ilChatroomUserTest.php.

166 {
167 $this->ilUserMock->expects($this->any())->method('isAnonymous')->will($this->returnValue(true));
168 $this->ilChatroomMock->expects($this->any())->method('getSetting')->will($this->returnValue('#_anonymous'));
169
170 $first = $this->user->getChatNameSuggestions();
171 $second = $this->user->getChatNameSuggestions();
172
173 $this->assertNotEquals($first, $second);
174 }

References user().

+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfNotAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfNotAnonymous ( )

Definition at line 176 of file class.ilChatroomUserTest.php.

177 {
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'));
184
185 $suggestions = $this->user->getChatNameSuggestions();
186
187 $this->assertEquals('John Doe', $suggestions['fullname']);
188 $this->assertEquals('J. Doe', $suggestions['shortname']);
189 $this->assertEquals('jdoe', $suggestions['login']);
190 }

References user().

+ Here is the call graph for this function:

◆ testGetUserIdFromSessionIfAnonymous()

ilChatroomUserTest::testGetUserIdFromSessionIfAnonymous ( )

Definition at line 62 of file class.ilChatroomUserTest.php.

63 {
64 $userId = 6;
65 $roomId = 99;
66
67 $this->ilUserMock->expects($this->once())->method('getId')->will($this->returnValue($userId));
68 $this->ilUserMock->expects($this->once())->method('isAnonymous')->will($this->returnValue(true));
69
70 $this->ilChatroomMock->expects($this->any())->method('getRoomId')->will($this->returnValue($roomId));
71
72 $_SESSION['chat'] = array(
73 $roomId => array(
74 'user_id' => $userId,
75 ),
76 );
77
78 $this->assertEquals($userId, $this->user->getUserId());
79 }
$_SESSION["AccountId"]

References $_SESSION, and user().

+ Here is the call graph for this function:

◆ testGetUserIdIfNotAnonymous()

ilChatroomUserTest::testGetUserIdIfNotAnonymous ( )

Definition at line 52 of file class.ilChatroomUserTest.php.

53 {
54 $userId = 6;
55
56 $this->ilUserMock->expects($this->once())->method('getId')->will($this->returnValue($userId));
57 $this->ilUserMock->expects($this->once())->method('isAnonymous')->will($this->returnValue(false));
58
59 $this->assertEquals($userId, $this->user->getUserId());
60 }

References user().

+ Here is the call graph for this function:

◆ testGetUserIdRandomGeneratedIfAnonymous()

ilChatroomUserTest::testGetUserIdRandomGeneratedIfAnonymous ( )

Definition at line 81 of file class.ilChatroomUserTest.php.

82 {
83 $this->ilUserMock->expects($this->once())->method('getId')->will($this->returnValue(null));
84 $this->ilUserMock->expects($this->once())->method('isAnonymous')->will($this->returnValue(true));
85
86 $this->ilChatroomMock->expects($this->any())->method('getRoomId')->will($this->returnValue(99));
87
88 $this->assertNotNull($this->user->getUserId());
89 }

References user().

+ 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 117 of file class.ilChatroomUserTest.php.

118 {
119 $username = 'login';
120 $roomId = 99;
121 $_SESSION['chat'][$roomId]['username'] = ''; // Fix missing key warning
122
123 $this->ilUserMock->expects($this->once())->method('getLogin')->will($this->returnValue($username));
124 $this->ilChatroomMock->expects($this->any())->method('getRoomId')->will($this->returnValue($roomId));
125
126 $this->assertEquals($username, $this->user->getUsername());
127 }

References $_SESSION, and user().

+ Here is the call graph for this function:

◆ testGetUsernameFromSession()

ilChatroomUserTest::testGetUsernameFromSession ( )

Definition at line 102 of file class.ilChatroomUserTest.php.

103 {
104 $username = 'username';
105 $roomId = 99;
106 $_SESSION['chat'][$roomId]['username'] = $username;
107
108 $this->ilChatroomMock->expects($this->any())->method('getRoomId')->will($this->returnValue(99));
109
110 $this->assertEquals($username, $this->user->getUsername());
111 }

References $_SESSION, and user().

+ Here is the call graph for this function:

◆ testSetUsername()

ilChatroomUserTest::testSetUsername (   $username,
  $expected 
)

@dataProvider usernameDataProvider

Parameters
string$username
string$expected

Definition at line 96 of file class.ilChatroomUserTest.php.

97 {
98 $this->user->setUsername($username);
99 $this->assertEquals($expected, $this->user->getUsername());
100 }

References user().

+ Here is the call graph for this function:

◆ usernameDataProvider()

ilChatroomUserTest::usernameDataProvider ( )
Returns
array

Definition at line 195 of file class.ilChatroomUserTest.php.

196 {
197 return array(
198 array('username', 'username'),
199 array('>username<', '&gt;username&lt;'),
200 );
201 }

Field Documentation

◆ $ilChatroomMock

ilChatroomUserTest::$ilChatroomMock
protected

Definition at line 18 of file class.ilChatroomUserTest.php.

◆ $ilUserMock

ilChatroomUserTest::$ilUserMock
protected

Definition at line 13 of file class.ilChatroomUserTest.php.

◆ $user

ilChatroomUserTest::$user
protected

Definition at line 23 of file class.ilChatroomUserTest.php.


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