ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
29 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
30 ilUnitUtil::performInitialisation();
31 }
32 else
33 {
34 chdir(dirname(__FILE__));
35 chdir('../../../');
36 }
37
38 require_once './Modules/Chatroom/classes/class.ilChatroomUser.php';
39 //require_once 'Services/User/classes/class.ilObjUser.php';
40 $this->ilUserMock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->setMethods(
41 array('getId', 'isAnonymous', 'getLogin', 'getPublicName', 'getFirstname', 'getLastname')
42 )->getMock();
43 $this->ilChatroomMock = $this->getMockBuilder('ilChatroom')->disableOriginalConstructor()->setMethods(
44 array('getRoomId', 'getSetting')
45 )->getMock();
46
47 $this->user = new ilChatroomUser($this->ilUserMock, $this->ilChatroomMock);
48 }
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 132 of file class.ilChatroomUserTest.php.

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

References user().

+ Here is the call graph for this function:

◆ testBuildFullname()

ilChatroomUserTest::testBuildFullname ( )

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

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

References user().

+ Here is the call graph for this function:

◆ testBuildLogin()

ilChatroomUserTest::testBuildLogin ( )

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

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

References user().

+ Here is the call graph for this function:

◆ testBuildShortname()

ilChatroomUserTest::testBuildShortname ( )

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

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

References user().

+ Here is the call graph for this function:

◆ testConstructor()

ilChatroomUserTest::testConstructor ( )

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

51 {
52 $this->assertInstanceOf('ilChatroomUser', $this->user);
53 }

References user().

+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfAnonymous ( )

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

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

References user().

+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfNotAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfNotAnonymous ( )

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

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

References user().

+ Here is the call graph for this function:

◆ testGetUserIdFromSessionIfAnonymous()

ilChatroomUserTest::testGetUserIdFromSessionIfAnonymous ( )

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

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

References $_SESSION, and user().

+ Here is the call graph for this function:

◆ testGetUserIdIfNotAnonymous()

ilChatroomUserTest::testGetUserIdIfNotAnonymous ( )

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

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

References user().

+ Here is the call graph for this function:

◆ testGetUserIdRandomGeneratedIfAnonymous()

ilChatroomUserTest::testGetUserIdRandomGeneratedIfAnonymous ( )

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

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

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

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

References $_SESSION, and user().

+ Here is the call graph for this function:

◆ testGetUsernameFromSession()

ilChatroomUserTest::testGetUsernameFromSession ( )

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

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

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

100 {
101 $this->user->setUsername($username);
102 $this->assertEquals($expected, $this->user->getUsername());
103 }

References user().

+ Here is the call graph for this function:

◆ usernameDataProvider()

ilChatroomUserTest::usernameDataProvider ( )
Returns
array

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

199 {
200 return array(
201 array('username', 'username'),
202 array('>username<', '&gt;username&lt;'),
203 );
204 }

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: