ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilTestBaseTestCaseTrait.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 use ILIAS\Refinery\Random\Group as RandomGroup;
30 
32 {
33  protected function defineGlobalConstants(): void
34  {
35  if (!defined('ILIAS_HTTP_PATH')) {
36  define('ILIAS_HTTP_PATH', 'http://localhost');
37  }
38  if (!defined('CLIENT_DATA_DIR')) {
39  define('CLIENT_DATA_DIR', '/var/iliasdata');
40  }
41  if (!defined('IL_INST_ID')) {
42  define('IL_INST_ID', '0');
43  }
44  if (!defined("ANONYMOUS_USER_ID")) {
45  define("ANONYMOUS_USER_ID", 13);
46  }
47  if (!defined('ANONYMOUS_USER_ID')) {
48  define('ANONYMOUS_USER_ID', 13);
49  }
50  if (!defined('ROOT_FOLDER_ID')) {
51  define('ROOT_FOLDER_ID', 8);
52  }
53  if (!defined('ILIAS_LOG_ENABLED')) {
54  define('ILIAS_LOG_ENABLED', true);
55  }
56  if (!defined('ILIAS_LOG_DIR')) {
57  define('ILIAS_LOG_DIR', '/var/log');
58  }
59  if (!defined('ILIAS_LOG_FILE')) {
60  define('ILIAS_LOG_FILE', '/var/log/ilias.log');
61  }
62  }
63 
68  protected function setGlobalVariable(string $name, $value): void
69  {
70  global $DIC;
71 
72  $GLOBALS[$name] = $value;
73 
74  unset($DIC[$name]);
75  $DIC[$name] = static function (Container $c) use ($value) {
76  return $value;
77  };
78  }
79 
83  protected function getGlobalTemplateMock()
84  {
85  return $this->getMockBuilder(ilTemplate::class)->disableOriginalConstructor()->getMock();
86  }
87 
91  protected function getDatabaseMock()
92  {
93  return $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock();
94  }
95 
99  protected function getIliasMock()
100  {
101  $mock = $this->getMockBuilder(ILIAS::class)->disableOriginalConstructor()->getMock();
102 
103  $account = new stdClass();
104  $account->id = 6;
105  $account->fullname = 'Esther Tester';
106 
107  $mock->account = $account;
108 
109  return $mock;
110  }
111 
112  protected function addGlobal_ilAccess(): void
113  {
114  $this->setGlobalVariable('ilAccess', $this->createMock(ilAccess::class));
115  }
116 
117  protected function addGlobal_ilUser(): void
118  {
119  $this->setGlobalVariable('ilUser', $this->createMock(ilObjUser::class));
120  }
121 
122  protected function addGlobal_objDefinition(): void
123  {
124  $this->setGlobalVariable('objDefinition', $this->createMock(ilObjectDefinition::class));
125  }
126 
127  protected function addGlobal_tree(): void
128  {
129  $this->setGlobalVariable('tree', $this->createMock(ilTree::class));
130  }
131 
132  protected function addGlobal_ilSetting(): void
133  {
134  $this->setGlobalVariable('ilSetting', $this->createMock(ilSetting::class));
135  }
136 
137  protected function addGlobal_rbacsystem(): void
138  {
139  $this->setGlobalVariable('rbacsystem', $this->createMock(ilRbacSystem::class));
140  }
141 
142  protected function addGlobal_ilRbacAdmin(): void
143  {
144  $this->setGlobalVariable('rbacadmin', $this->createMock(ilRbacAdmin::class));
145  }
146 
147  protected function addGlobal_ilCtrl(): void
148  {
149  $this->setGlobalVariable('ilCtrl', $this->createMock(ilCtrl::class));
150  }
151 
152  protected function addGlobal_lng(): void
153  {
154  $this->setGlobalVariable('lng', $this->createMock(ilLanguage::class));
155  }
156 
157  protected function addGlobal_filesystem(): void
158  {
159  $this->setGlobalVariable('filesystem', $this->createMock(Filesystems::class));
160  }
161 
162  protected function addGlobal_static_url(): void
163  {
164  $this->setGlobalVariable('static_url', $this->createMock(ILIAS\StaticURL\Services::class));
165  }
166 
167  protected function addGlobal_upload(): void
168  {
169  $this->setGlobalVariable('upload', $this->createMock(FileUpload::class));
170  }
171 
172  protected function addGlobal_ilDB(): void
173  {
174  $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
175  }
176 
177  protected function addGlobal_ilBench(): void
178  {
179  $this->setGlobalVariable('ilBench', $this->createMock(ilBenchmark::class));
180  }
181 
182  protected function addGlobal_ilLog(): void
183  {
184  $this->setGlobalVariable('ilLog', $this->createMock(ilLogger::class));
185  }
186 
187  protected function addGlobal_ilias(): void
188  {
189  $this->setGlobalVariable('ilias', $this->getIliasMock());
190  }
191 
192  protected function addGlobal_ilErr(): void
193  {
194  $this->setGlobalVariable('ilErr', $this->createMock(ilErrorHandling::class));
195  }
196 
197  protected function addGlobal_GlobalScreenService(): void
198  {
199  $this->setGlobalVariable('global_screen', $this->createMock(ILIAS\GlobalScreen\Services::class));
200  }
201 
202  protected function addGlobal_ilNavigationHistory(): void
203  {
204  $this->setGlobalVariable('ilNavigationHistory', $this->createMock(ilNavigationHistory::class));
205  }
206 
207  protected function addGlobal_ilAppEventHandler(): void
208  {
209  $this->setGlobalVariable('ilAppEventHandler', $this->createMock(ilAppEventHandler::class));
210  }
211 
212  protected function addGlobal_tpl(): void
213  {
214  $this->setGlobalVariable('tpl', $this->createMock(ilGlobalPageTemplate::class));
215  }
216 
217  protected function addGlobal_ilComponentRepository(): void
218  {
219  $this->setGlobalVariable('component.repository', $this->createMock(ilComponentRepository::class));
220  }
221 
222  protected function addGlobal_ilComponentFactory(): void
223  {
224  $this->setGlobalVariable('component.factory', $this->createMock(ilComponentFactory::class));
225  }
226 
227  protected function addGlobal_ilTabs(): void
228  {
229  $this->setGlobalVariable('ilTabs', $this->createMock(ilTabsGUI::class));
230  }
231 
232  protected function addGlobal_ilObjDataCache(): void
233  {
234  $this->setGlobalVariable('ilObjDataCache', $this->createMock(ilObjectDataCache::class));
235  }
236 
237  protected function addGlobal_ilLocator(): void
238  {
239  $this->setGlobalVariable('ilLocator', $this->createMock(ilLocatorGUI::class));
240  }
241 
242  protected function addGlobal_rbacreview(): void
243  {
244  $this->setGlobalVariable('rbacreview', $this->createMock(ilRbacReview::class));
245  }
246 
247  protected function addGlobal_ilToolbar(): void
248  {
249  $this->setGlobalVariable('ilToolbar', $this->createMock(ilToolbarGUI::class));
250  }
251 
252  protected function addGlobal_http(): void
253  {
254  $request_mock = $this->getMockBuilder(\Psr\Http\Message\ServerRequestInterface::class)
255  ->disableOriginalConstructor()
256  ->getMock();
257  $request_mock->method('getUri')
258  ->willReturn(new GuzzleURI('http://wwww.ilias.de'));
259  $http_mock = $this->getMockBuilder(HTTPServices::class)->disableOriginalConstructor()
260  ->getMock();
261  $http_mock->method('request')
262  ->willReturn($request_mock);
263  $this->setGlobalVariable('http', $http_mock);
264  }
265 
266  protected function addGlobal_ilIliasIniFile(): void
267  {
268  $this->setGlobalVariable('ilIliasIniFile', $this->createMock(ilIniFile::class));
269  }
270 
271  protected function addGlobal_ilLoggerFactory(): void
272  {
273  $this->setGlobalVariable('ilLoggerFactory', $this->createMock(ilLoggerFactory::class));
274  }
275 
276  protected function addGlobal_ilHelp(): void
277  {
278  $this->setGlobalVariable('ilHelp', $this->createMock(ilHelpGUI::class));
279  }
280 
281  protected function addGlobal_uiService(): void
282  {
283  $this->setGlobalVariable('uiService', $this->createMock(\ilUIService::class));
284  }
285 
286  protected function addGlobal_uiFactory(): void
287  {
288  $this->setGlobalVariable('ui.factory', $this->createMock(FactoryInternal::class));
289  }
290 
291  protected function addGlobal_uiRenderer(): void
292  {
293  $this->setGlobalVariable('ui.renderer', $this->createMock(ILIAS\UI\Implementation\DefaultRenderer::class));
294  }
295 
296  protected function addGlobal_refinery(): void
297  {
298  $refineryMock = $this->getMockBuilder(RefineryFactory::class)->disableOriginalConstructor()->getMock();
299  $refineryMock->expects(self::any())->method('random')->willReturn($this->getMockBuilder(RandomGroup::class)->getMock());
300  $this->setGlobalVariable('refinery', $refineryMock);
301  }
302 
303  protected function addGlobal_skillService(): void
304  {
305  $this->setGlobalVariable('skill', $this->createMock(ILIAS\Skill\Service\SkillService::class));
306  }
307 
308  protected function addGlobal_objectService(): void
309  {
310  global $DIC;
311  $DIC['object.customicons.factory'] = $this->getMockBuilder(ilObjectCustomIconFactory::class)->disableOriginalConstructor()->getMock();
312  $object_mock = $this->getMockBuilder(\ilObjectService::class)->disableOriginalConstructor()->getMock();
313 
314  $this->setGlobalVariable('object', $object_mock);
315  }
316 
317  protected function addGlobal_resourceStorage(): void
318  {
319  $this->setGlobalVariable('resource_storage', $this->createMock(\ILIAS\ResourceStorage\Services::class));
320  }
321 
322  protected function addGlobal_fileDelivery(): void
323  {
324  $this->setGlobalVariable(
325  'file_delivery',
326  $this->getFileDelivery()
327  );
328  }
329 
330  protected function addGlobal_uiUploadLimitResolver(): void
331  {
332  $this->setGlobalVariable('ui.upload_limit_resolver', $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class));
333  }
334 
335  protected function getFileDelivery(): \ILIAS\FileDelivery\Services
336  {
337  $data_signer = new ILIAS\FileDelivery\Token\DataSigner(
338  new ILIAS\FileDelivery\Token\Signer\Key\Secret\SecretKeyRotation(
339  new ILIAS\FileDelivery\Token\Signer\Key\Secret\SecretKey('blup')
340  )
341  );
342  $http_mock = $this->getMockBuilder(HTTPServices::class)->disableOriginalConstructor()->getMock();
343  $response_builder_mock = $this->createMock(\ILIAS\FileDelivery\Delivery\ResponseBuilder\ResponseBuilder::class);
344  return new \ILIAS\FileDelivery\Services(
345  new ILIAS\FileDelivery\Delivery\StreamDelivery(
346  $data_signer,
347  $http_mock,
348  $response_builder_mock,
349  $response_builder_mock
350  ),
351  new \ILIAS\FileDelivery\Delivery\LegacyDelivery(
352  $http_mock,
353  $response_builder_mock,
354  $response_builder_mock
355  ),
356  $data_signer,
357  $http_mock
358  );
359  }
360 
361  protected function getTestObjMock(): ilObjTest
362  {
363  $test_mock = $this->getMockBuilder(ilObjTest::class)->disableOriginalConstructor()->getMock();
364  $test_mock->method('getLocalDIC')->willReturn(
365  $this->buildLocalDICMock()
366  );
367  return $test_mock;
368  }
369 
370  protected function buildLocalDICMock(): ILIAS\Test\TestDIC
371  {
372  $local_dic_mock = $this->getMockBuilder(ILIAS\Test\TestDIC::class)
373  ->onlyMethods([])->getMock();
374  $local_dic_mock['question.general_properties.repository'] = fn(Pimple\Container $c)
375  => $this->createMock(
376  ILIAS\TestQuestionPool\Questions\GeneralQuestionPropertiesRepository::class
377  );
378  $local_dic_mock['request_data_collector'] = fn(Pimple\Container $c)
379  => $this->createMock(
380  \ILIAS\Test\RequestDataCollector::class
381  );
382  $local_dic_mock['participant.access_filter.factory'] = fn(Pimple\Container $c)
383  => $this->createMock(
384  \ilTestParticipantAccessFilterFactory::class
385  );
386  $local_dic_mock['logging.logger'] = fn(Pimple\Container $c)
387  => $this->createMock(
388  \ILIAS\Test\Logging\TestLogger::class
389  );
390  $local_dic_mock['logging.viewer'] = fn(Pimple\Container $c)
391  => $this->createMock(
392  \ILIAS\Test\Logging\TestLogViewer::class
393  );
394  $local_dic_mock['shuffler'] = fn(Pimple\Container $c)
395  => $this->createMock(
396  \ilTestShuffler::class
397  );
398  $local_dic_mock['results.presentation.factory'] = fn(Pimple\Container $c)
399  => $this->createMock(
400  ILIAS\Test\Results\Presentation\Factory::class
401  );
402  $local_dic_mock['results.data.factory'] = fn(Pimple\Container $c)
403  => $this->createMock(
404  ILIAS\Test\Results\Data\Factory::class
405  );
406  $local_dic_mock['results.toplist.repository'] = fn(Pimple\Container $c)
407  => $this->createMock(
408  ILIAS\Test\Results\Toplist\TestTopListRepository::class
409  );
410  $local_dic_mock['results.data.test_result_repository'] = fn(Pimple\Container $c)
411  => $this->createMock(
412  \ILIAS\Test\Results\Data\Repository::class
413  );
414  $local_dic_mock['questions.properties.repository'] = fn(Pimple\Container $c)
415  => $this->createMock(
416  ILIAS\Test\Questions\Properties\Repository::class
417  );
418  return $local_dic_mock;
419  }
420 }
Token
The string representation of these tokens must not occur in the names of metadata elements...
Definition: Token.php:27
Interface Observer Contains several chained tasks and infos about them.
$c
Definition: deliver.php:25
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$GLOBALS["DIC"]
Definition: wac.php:53
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...