ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilChatroomAbstractTaskTest.php
Go to the documentation of this file.
1<?php
2
3require_once 'class.ilChatroomAbstractTest.php';
4
10{
14 const TEST_REF_ID = 99;
15
19 protected $gui;
20
25
29 protected $object;
30
31 protected function setUp()
32 {
33 parent::setUp();
34
35 if (!defined('ROOT_FOLDER_ID')) {
36 define('ROOT_FOLDER_ID', time());
37 }
38 }
39
40 protected function createGlobalIlLanguageMock()
41 {
42 require_once './Services/Language/classes/class.ilLanguage.php';
43 $GLOBALS['lng'] = $this->getMockBuilder('ilLanguage')->disableOriginalConstructor()->setMethods(
44 array('loadLanguageModule', 'txt')
45 )->getMock();
46
47 $GLOBALS['lng']->expects($this->any())->method('loadLanguageModule')->with($this->logicalOr($this->equalTo('chatroom'), $this->equalTo('meta')));
48 $GLOBALS['lng']->expects($this->any())->method('txt');
49
50 return $GLOBALS['lng'];
51 }
52
53 protected function createGlobalRbacSystemMock()
54 {
55 require_once './Services/AccessControl/classes/class.ilRbacSystem.php';
56 $GLOBALS['rbacsystem'] = $this->getMockBuilder('ilRbacSystem')->disableOriginalConstructor()->setMethods(
57 array('checkAccess')
58 )->getMock();
59
60 return $GLOBALS['rbacsystem'];
61 }
62
68 protected function createGlobalRbacSystemCheckAccessMock($permission, $result, $times = null)
69 {
70 if ($times == null) {
71 $times = $this->any();
72 }
73
74 return $GLOBALS['rbacsystem']->expects($times)->method('checkAccess')->with($this->equalTo($permission))->will(
75 $this->returnValue($result)
76 );
77 }
78
79 protected function createGlobalIlCtrlMock()
80 {
81 require_once './Services/UICore/classes/class.ilCtrl.php';
82
83 $GLOBALS['ilCtrl'] = $this->getMockBuilder('ilCtrl')->disableOriginalConstructor()->setMethods(
84 array('setParameterByClass', 'redirectByClass', 'forwardCommand')
85 )->getMock();
86 $GLOBALS['ilCtrl']->expects($this->any())->method('setParameterByClass');
87 $GLOBALS['ilCtrl']->expects($this->any())->method('redirectByClass');
88
89 return $GLOBALS['ilCtrl'];
90 }
91
92 protected function createGlobalIlUserMock()
93 {
94 require_once 'Services/User/classes/class.ilObjUser.php';
95
96 $GLOBALS['ilUser'] = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->setMethods(
97 array()
98 )->getMock();
99
100 return $GLOBALS['ilUser'];
101 }
102
104 {
105 require_once './Modules/Chatroom/classes/class.ilObjChatroomGUI.php';
106
107 $this->gui = $this->getMockBuilder('ilObjChatroomGUI')->disableOriginalConstructor()->disableArgumentCloning()->setMethods(
108 array('getRefId', 'getConnector', 'switchToVisibleMode')
109 )->getMock();
110 $this->gui->ref_id = self::TEST_REF_ID;
111 $this->gui->object = $object;
112
113 return $this->gui;
114 }
115
116 protected function createIlObjChatroomGUIGetConnectorMock($returnValue)
117 {
118 $this->gui->expects($this->any())->method('getConnector')->will($this->returnValue($returnValue));
119 }
120
127 protected function createIlChatroomIsOwnerOfPrivateRoomMock($userId, $subRoomId, $result)
128 {
129 return $this->ilChatroomMock->expects($this->at(0))->method('isOwnerOfPrivateRoom')->with(
130 $this->equalTo($userId),
131 $this->equalTo($subRoomId)
132 )->will($this->returnValue($result));
133 }
134
135 protected function createIlChatroomUserGetUserIdMock($userId)
136 {
137 return $this->ilChatroomUserMock->expects($this->any())->method('getUserId')->will($this->returnValue($userId));
138 }
139
144 protected function createIlChatroomServerConnectorMock($settings)
145 {
146 require_once './Modules/Chatroom/classes/class.ilChatroomServerConnector.php';
147
148 $this->ilChatroomServerConnectorMock = $this->getMockBuilder('ilChatroomServerConnector')->setConstructorArgs(
149 array($settings)
150 )->setMethods(array('file_get_contents'))->getMock();
151
153 }
154
156 {
157 return $this->ilChatroomServerConnectorMock->expects($this->any())->method('file_get_contents')->will(
158 $this->returnValue($returnValue)
159 );
160 }
161
162 protected function createIlObjChatroomMock($id)
163 {
164 require_once './Modules/Chatroom/classes/class.ilObjChatroom.php';
165
166 $this->object = $this->getMockBuilder('ilObjChatroom')->disableOriginalConstructor()->setMethods(
167 array('getId')
168 )->getMock();
169 $this->object->expects($this->any())->method('getId')->will($this->returnValue($id));
170
171 return $this->object;
172 }
173
174 protected function createSendResponseMock($mock, $response)
175 {
176 $mock->expects($this->once())->method('sendResponse')->with(
177 $this->equalTo($response)
178 )->will(
179 $this->returnCallback(
180 function () {
181 throw new Exception('Exit', 0);
182 }
183 )
184 );
185 }
186}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomAbstractTaskTest.
createIlChatroomIsOwnerOfPrivateRoomMock($userId, $subRoomId, $result)
createGlobalRbacSystemCheckAccessMock($permission, $result, $times=null)
Class ilChatroomAbstractTest.
Class ilChatroomServerConnectorMock.
if(!array_key_exists('StateId', $_REQUEST)) $id
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$response