ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilChatroomAbstractTaskTestBase.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
26 {
27  protected MockObject&ilChatroomObjectGUI $gui;
29  protected MockObject&ilObjChatroom $object;
30 
31  protected function setUp(): void
32  {
33  parent::setUp();
34 
35  if (!defined('ROOT_FOLDER_ID')) {
36  define('ROOT_FOLDER_ID', time());
37  }
38  }
39 
40  protected function createGlobalIlLanguageMock(): ilLanguage
41  {
42  $lng = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->onlyMethods(
43  ['loadLanguageModule', 'txt']
44  )->getMock();
45 
46  $lng->method('loadLanguageModule')->with(
47  $this->logicalOr(
48  $this->equalTo('chatroom'),
49  $this->equalTo('meta')
50  )
51  );
52  $lng->method('txt');
53 
54  $this->setGlobalVariable('lng', $lng);
55 
56  return $lng;
57  }
58 
60  {
61  $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods(
62  ['checkAccess']
63  )->getMock();
64 
65  $this->setGlobalVariable('rbacsystem', $rbacsystem);
66 
67  return $rbacsystem;
68  }
69 
71  string $permission,
72  bool $result,
73  ?InvocationOrder $times = null
74  ) {
75  if ($times === null) {
76  $times = $this->any();
77  }
78 
79  return $GLOBALS['rbacsystem']->expects($times)
80  ->method('checkAccess')
81  ->with($this->equalTo($permission))->willReturn(
82  $result
83  );
84  }
85 
87  {
88  $ctrl = $this->createMock(ilCtrlInterface::class);
89 
90  $this->setGlobalVariable('ilCtrl', $ctrl);
91 
92  return $GLOBALS['ilCtrl'];
93  }
94 
95  protected function createGlobalIlUserMock(): ilObjUser
96  {
97  $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
98 
99  $this->setGlobalVariable('ilUser', $user);
100 
101  return $user;
102  }
103 
104  protected function createIlObjChatroomGUIGetConnectorMock($returnValue): void
105  {
106  $this->gui->method('getConnector')->willReturn($returnValue);
107  }
108 
110  int $userId,
111  int $subRoomId,
112  bool $result
113  ): InvocationMocker {
114  return $this->ilChatroomMock->method('isOwnerOfPrivateRoom')->with(
115  $this->equalTo($userId),
116  $this->equalTo($subRoomId)
117  )->willReturn($result);
118  }
119 
120  protected function createIlChatroomUserGetUserIdMock(int $userId): InvocationMocker
121  {
122  return $this->ilChatroomUserMock->method('getUserId')->willReturn($userId);
123  }
124 
126  ilChatroomServerSettings $settings
128  $this->ilChatroomServerConnectorMock = $this->getMockBuilder(ilChatroomServerConnector::class)->setConstructorArgs(
129  [$settings]
130  )->onlyMethods(['file_get_contents'])->getMock();
131 
133  }
134 
135  protected function createIlChatroomServerConnectorFileGetContentsMock($returnValue): InvocationMocker
136  {
137  return $this->ilChatroomServerConnectorMock->method('file_get_contents')->willReturn(
138  $returnValue
139  );
140  }
141 
142  protected function createIlObjChatroomMock(int $id): ilObjChatroom
143  {
144  $this->object = $this->getMockBuilder(ilObjChatroom::class)->disableOriginalConstructor()->onlyMethods(
145  ['getId']
146  )->getMock();
147  $this->object->method('getId')->willReturn($id);
148 
149  return $this->object;
150  }
151 
152  protected function createSendResponseMock(MockObject $mock, $response): void
153  {
154  $mock->expects($this->once())->method('sendResponse')->with(
155  $this->equalTo($response)
156  )->willReturnCallback(
157  static function (): never {
158  throw new Exception('Exit', 0);
159  }
160  );
161  }
162 }
$response
Definition: xapitoken.php:93
createIlChatroomServerConnectorMock(ilChatroomServerSettings $settings)
createGlobalRbacSystemCheckAccessMock(string $permission, bool $result, ?InvocationOrder $times=null)
MockObject &ilChatroomServerConnector $ilChatroomServerConnectorMock
createSendResponseMock(MockObject $mock, $response)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$GLOBALS["DIC"]
Definition: wac.php:53
Class ilChatroomServerConnector.
MockObject &ilChatroomObjectGUI $gui
createIlChatroomIsOwnerOfPrivateRoomMock(int $userId, int $subRoomId, bool $result)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
global $lng
Definition: privfeed.php:31