ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilChatroomTaskHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
3 require_once dirname(__FILE__) . '/class.ilChatroomAbstractTaskTest.php';
4 
10 {
11 
15  protected $handler;
16 
17  protected function setUp()
18  {
19  parent::setUp();
20 
22  $this->createGlobalIlCtrlMock();
23  $this->createGlobalIlUserMock();
25  $this->createIlObjChatroomMock(15);
26  $this->createIlObjChatroomGUIMock($this->object);
27 
28  require_once './Modules/Chatroom/test/mocks/class.ilChatroomTaskHandlerMock.php';
29  $this->handler = new ilChatroomGUIHandlerMock($this->gui);
30  }
31 
32  public function testExecuteDefault()
33  {
34  $this->assertEquals('default', $this->handler->executeDefault('default'));
35  }
36 
37  public function testExecuteWithMethodExit()
38  {
39  $this->assertTrue($this->handler->execute('testFunc'));
40  }
41 
42  public function testExecuteWithMethodNotExit()
43  {
44  $this->assertEquals('nonExistingFunc', $this->handler->execute('nonExistingFunc'));
45  }
46 
47  public function testIsSuccessfull()
48  {
49  $response = array('success' => true);
50  $this->assertTrue($this->handler->isSuccessful(json_encode($response)));
51 
52  $response = array('success' => false);
53  $this->assertFalse($this->handler->isSuccessful(json_encode($response)));
54 
55  $response = array('failed' => false);
56  $this->assertFalse($this->handler->isSuccessful(json_encode($response)));
57 
58  $response = 'nonJson';
59  $this->assertFalse($this->handler->isSuccessful($response));
60  }
61 
68  public function testCanModerate($isOwnerOfPrivateRoomValue, $checkAccessValue, $result)
69  {
70  $userId = 6;
71  $subRoomId = 0;
72 
73  $this->createIlChatroomMock();
74  $this->createIlChatroomIsOwnerOfPrivateRoomMock($userId, $subRoomId, $isOwnerOfPrivateRoomValue);
75  $this->createGlobalRbacSystemCheckAccessMock('moderate', $checkAccessValue);
76 
77  $this->assertEquals($result, $this->handler->mockedCanModerate($this->ilChatroomMock, $subRoomId, $userId));
78  }
79 
80  public function testExitIfNoRoomExists()
81  {
82  $this->createIlChatroomMock();
83  $this->handler->mockedExitIfNoRoomExists($this->ilChatroomMock);
84 
85  $this->setExpectedException(
86  'Exception',
87  json_encode(
88  array(
89  'success' => false,
90  'reason' => 'unkown room',
91  )
92  )
93  );
94  $this->handler->mockedExitIfNoRoomExists(null);
95  }
96 
98  {
99  $userId = 6;
100  $subRoomId = 0;
101 
102  $this->createIlChatroomMock();
103  $this->createIlChatroomIsOwnerOfPrivateRoomMock($userId, $subRoomId, true);
104  $this->createIlChatroomUserMock();
105  $this->createIlChatroomUserGetUserIdMock($userId);
106  $this->createGlobalRbacSystemCheckAccessMock('moderate', true);
107 
108  $this->handler->mockedExitIfNoRoomPermission($this->ilChatroomMock, $subRoomId, $this->ilChatroomUserMock);
109  }
110 
112  {
113  $userId = 6;
114  $subRoomId = 0;
115 
116  $this->createIlChatroomMock();
117  $this->createIlChatroomIsOwnerOfPrivateRoomMock($userId, $subRoomId, false);
118  $this->createIlChatroomUserMock();
119  $this->createIlChatroomUserGetUserIdMock($userId);
120  $this->createGlobalRbacSystemCheckAccessMock('moderate', false);
121 
122  $this->setExpectedException(
123  'Exception',
124  json_encode(
125  array(
126  'success' => false,
127  'reason' => 'not owner of private room',
128  )
129  )
130  );
131 
132  $this->handler->mockedExitIfNoRoomPermission($this->ilChatroomMock, $subRoomId, $this->ilChatroomUserMock);
133  }
134 
138  public function testRedirectIfNoPermission()
139  {
140  $this->createGlobalRbacSystemCheckAccessMock('moderate', true, $this->at(0));
141  $this->createGlobalRbacSystemCheckAccessMock('user', false, $this->at(1));
142 
143  $this->handler->redirectIfNoPermission('moderate');
144  $this->handler->redirectIfNoPermission('user');
145  }
146 
150  public function canModerateDataProvider()
151  {
152  return array(
153  array(true, true, true),
154  array(true, false, false),
155  array(false, true, false),
156  );
157  }
158 }
$result
Class ilChatroomAbstractTaskTest.
createIlChatroomIsOwnerOfPrivateRoomMock($userId, $subRoomId, $result)
testCanModerate($isOwnerOfPrivateRoomValue, $checkAccessValue, $result)
canModerateDataProvider
createGlobalRbacSystemCheckAccessMock($permission, $result, $times=null)
Class ilChatroomTaskHandlerTest.
Create styles array
The data for the language used.