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)
 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.

References array, defined, and user().

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
Create styles array
The data for the language used.
Class ilChatroomUser.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
+ Here is the call graph for this function:

◆ testBuildAnonymousName()

ilChatroomUserTest::testBuildAnonymousName ( )

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

References user().

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  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ testBuildFullname()

ilChatroomUserTest::testBuildFullname ( )

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

References user().

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  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ testBuildLogin()

ilChatroomUserTest::testBuildLogin ( )

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

References user().

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  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ testBuildShortname()

ilChatroomUserTest::testBuildShortname ( )

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

References user().

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  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ testConstructor()

ilChatroomUserTest::testConstructor ( )

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

References user().

51  {
52  $this->assertInstanceOf('ilChatroomUser', $this->user);
53  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfAnonymous ( )

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

References user().

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  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ testGetChatNameSuggestionsIfNotAnonymous()

ilChatroomUserTest::testGetChatNameSuggestionsIfNotAnonymous ( )

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

References user().

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  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ testGetUserIdFromSessionIfAnonymous()

ilChatroomUserTest::testGetUserIdFromSessionIfAnonymous ( )

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

References $_SESSION, array, and user().

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"]
user()
Definition: user.php:4
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testGetUserIdIfNotAnonymous()

ilChatroomUserTest::testGetUserIdIfNotAnonymous ( )

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

References user().

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  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ testGetUserIdRandomGeneratedIfAnonymous()

ilChatroomUserTest::testGetUserIdRandomGeneratedIfAnonymous ( )

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

References user().

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  }
user()
Definition: user.php:4
+ 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.

References $_SESSION, and user().

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  }
$_SESSION["AccountId"]
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ testGetUsernameFromSession()

ilChatroomUserTest::testGetUsernameFromSession ( )

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

References $_SESSION, and user().

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  }
$_SESSION["AccountId"]
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ testSetUsername()

ilChatroomUserTest::testSetUsername (   $username,
  $expected 
)

usernameDataProvider

Parameters
string$username
string$expected

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

References user().

100  {
101  $this->user->setUsername($username);
102  $this->assertEquals($expected, $this->user->getUsername());
103  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ usernameDataProvider()

ilChatroomUserTest::usernameDataProvider ( )
Returns
array

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

References array.

199  {
200  return array(
201  array('username', 'username'),
202  array('>username<', '&gt;username&lt;'),
203  );
204  }
Create styles array
The data for the language used.

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: