19declare(strict_types=1);
23use PHPUnit\Framework\MockObject\MockObject;
40use GuzzleHttp\Psr7\Uri as GuzzleURI;
41use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
45 private array $services = [
46 ilAccess::class =>
'ilAccess',
47 ilAccessHandler::class =>
'ilAccess',
48 ilOrgUnitPositionAndRBACAccessHandler::class =>
'ilAccess',
49 ilOrgUnitPositionAccessHandler::class =>
'ilAccess',
50 ilRBACAccessHandler::class =>
'ilAccess',
51 DataFactory::class =>
'DataFactory',
52 ilGlobalPageTemplate::class =>
'tpl',
53 ilGlobalTemplateInterface::class =>
'tpl',
54 ilDBInterface::class =>
'ilDB',
55 ilBenchmark::class =>
'ilBench',
56 ilObjUser::class =>
'ilUser',
57 ilErrorHandling::class =>
'ilErr',
58 ilTree::class =>
'tree',
59 ilLanguage::class =>
'lng',
60 Language::class =>
'lng',
61 ilAppEventHandler::class =>
'ilAppEventHandler',
62 ilObjectDefinition::class =>
'objDefinition',
63 RefineryFactory::class =>
'refinery',
64 ilRbacSystem::class =>
'rbacsystem',
65 ilRbacReview::class =>
'rbacreview',
66 ilRbacAdmin::class =>
'rbacadmin',
67 HTTPServices::class =>
'http',
68 GlobalHttpState::class =>
'http',
69 ilComponentFactory::class =>
'component.factory',
70 ilComponentRepository::class =>
'component.repository',
71 ImplementationFactory::class =>
'ui.factory',
72 UIFactory::class =>
'ui.factory',
73 ImplementationDefaultRenderer::class =>
'ui.renderer',
74 UIRenderer::class =>
'ui.renderer',
75 ilUIService::class =>
'uiService',
76 StaticURLServices::class =>
'static_url',
77 FileUpload::class =>
'upload',
78 ilLogger::class =>
'ilLog',
79 ilSetting::class =>
'ilSetting',
80 Setting::class =>
'ilSetting',
81 ilCtrl::class =>
'ilCtrl',
82 ilCtrlInterface::class =>
'ilCtrl',
83 ilObjectDataCache::class =>
'ilObjDataCache',
84 ilHelpGUI::class =>
'ilHelp',
85 ilCtrlBaseClassInterface::class =>
'ilHelp',
86 ilTabsGUI::class =>
'ilTabs',
87 ilLocatorGUI::class =>
'ilLocator',
88 ilToolbarGUI::class =>
'ilToolbar',
89 ilObjectCustomIconFactory::class =>
'object.customicons.factory',
90 Filesystems::class =>
'filesystem',
91 ilObjTest::class =>
'ilObjTest',
92 \ILIAS\Cache\Services::class =>
'global_cache',
97 if (!defined(
'ILIAS_HTTP_PATH')) {
98 define(
'ILIAS_HTTP_PATH',
'http://localhost');
100 if (!defined(
'CLIENT_DATA_DIR')) {
101 define(
'CLIENT_DATA_DIR',
'/var/iliasdata');
103 if (!defined(
'IL_INST_ID')) {
104 define(
'IL_INST_ID',
'0');
106 if (!defined(
'ANONYMOUS_USER_ID')) {
107 define(
'ANONYMOUS_USER_ID', 13);
109 if (!defined(
'ANONYMOUS_USER_ID')) {
110 define(
'ANONYMOUS_USER_ID', 13);
112 if (!defined(
'ROOT_FOLDER_ID')) {
113 define(
'ROOT_FOLDER_ID', 8);
115 if (!defined(
'ILIAS_LOG_ENABLED')) {
116 define(
'ILIAS_LOG_ENABLED',
true);
118 if (!defined(
'ILIAS_LOG_DIR')) {
119 define(
'ILIAS_LOG_DIR',
'/var/log');
121 if (!defined(
'ILIAS_LOG_FILE')) {
122 define(
'ILIAS_LOG_FILE',
'/var/log/ilias.log');
147 return $this->createMock(ilTemplate::class);
155 return $this->createMock(ilDBInterface::class);
163 $mock = $this->createMock(ILIAS::class);
165 $account =
new stdClass();
167 $account->fullname =
'Esther Tester';
169 $mock->account = $account;
170 $mock->ini_ilias = $this->createMock(ilIniFile::class);
192 $this->
setGlobalVariable(
'objDefinition', $this->createMock(ilObjectDefinition::class));
242 $db = $this->createMock(ilDBInterface::class);
244 ->method(
'loadModule')
245 ->willReturnCallback(
247 return match ($module) {
285 $this->
setGlobalVariable(
'ilNavigationHistory', $this->createMock(ilNavigationHistory::class));
290 $this->
setGlobalVariable(
'ilAppEventHandler', $this->createMock(ilAppEventHandler::class));
300 $this->
setGlobalVariable(
'component.repository', $this->createMock(ilComponentRepository::class));
305 $this->
setGlobalVariable(
'component.factory', $this->createMock(ilComponentFactory::class));
315 $this->
setGlobalVariable(
'ilObjDataCache', $this->createMock(ilObjectDataCache::class));
334 $request_mock = $this->getMockBuilder(\Psr\Http\Message\ServerRequestInterface::class)
335 ->disableOriginalConstructor()
337 $request_mock->method(
'getUri')
338 ->willReturn(
new GuzzleURI(
'http://wwww.ilias.de'));
339 $http_mock = $this->getMockBuilder(HTTPServices::class)->disableOriginalConstructor()
341 $http_mock->method(
'request')
342 ->willReturn($request_mock);
353 $this->
setGlobalVariable(
'ilLoggerFactory', $this->createMock(ilLoggerFactory::class));
368 $this->
setGlobalVariable(
'ui.factory', $this->createMock(FactoryInternal::class));
378 $refineryMock = $this->getMockBuilder(RefineryFactory::class)->disableOriginalConstructor()->getMock();
379 $refineryMock->expects(self::any())->method(
'random')->willReturn($this->getMockBuilder(RandomGroup::class)->getMock());
390 $this->
setGlobalVariable(
'learning_object_metadata', $this->createMock(
ILIAS\MetaData\Services\ServicesInterface::class));
395 $this->
setGlobalVariable(
'object.customicons.factory', $this->getMockBuilder(
ILIAS\ILIASObject\Properties\AdditionalProperties\Icon\Factory::class)->disableOriginalConstructor()->getMock());
396 $object_mock = $this->getMockBuilder(\ilObjectService::class)->disableOriginalConstructor()->getMock();
418 $this->createMock(PublicInterface::class)
430 new ILIAS\FileDelivery\
Token\Signer\Key\Secret\SecretKeyRotation(
431 new ILIAS\FileDelivery\
Token\Signer\Key\Secret\SecretKey(
'blup')
434 $http_mock = $this->createMock(HTTPServices::class);
435 $response_builder_mock = $this->createMock(\
ILIAS\FileDelivery\Delivery\ResponseBuilder\ResponseBuilder::class);
436 return new \ILIAS\FileDelivery\Services(
437 new ILIAS\FileDelivery\Delivery\StreamDelivery(
440 $response_builder_mock,
441 $response_builder_mock
443 new \
ILIAS\FileDelivery\Delivery\LegacyDelivery(
445 $response_builder_mock,
446 $response_builder_mock
455 return $this->createConfiguredMock(ilObjTest::class, [
462 $local_dic_mock = $this->getMockBuilder(
ILIAS\
Test\TestDIC::class)
463 ->onlyMethods([])->getMock();
464 $local_dic_mock[
'question.general_properties.repository'] = fn(Pimple\
Container $c)
465 => $this->createMock(
466 ILIAS\TestQuestionPool\Questions\GeneralQuestionPropertiesRepository::class
468 $local_dic_mock[
'request_data_collector'] = fn(Pimple\
Container $c)
469 => $this->createMock(
472 $local_dic_mock[
'participant.access_filter.factory'] = fn(Pimple\
Container $c)
473 => $this->createMock(
474 \ilTestParticipantAccessFilterFactory::class
476 $local_dic_mock[
'logging.logger'] = fn(Pimple\
Container $c)
477 => $this->createMock(
480 $local_dic_mock[
'logging.viewer'] = fn(Pimple\
Container $c)
481 => $this->createMock(
484 $local_dic_mock[
'shuffler'] = fn(Pimple\
Container $c)
485 => $this->createMock(
486 \ilTestShuffler::class
488 $local_dic_mock[
'results.presentation.factory'] = fn(Pimple\
Container $c)
489 => $this->createMock(
490 ILIAS\
Test\Results\Presentation\Factory::class
492 $local_dic_mock[
'results.data.factory'] = fn(Pimple\
Container $c)
493 => $this->createMock(
496 $local_dic_mock[
'results.toplist.repository'] = fn(Pimple\
Container $c)
497 => $this->createMock(
498 ILIAS\
Test\Results\Toplist\TestTopListRepository::class
500 $local_dic_mock[
'results.data.repository'] = fn(Pimple\
Container $c)
501 => $this->createMock(
502 \
ILIAS\
Test\Results\Data\Repository::class
504 $local_dic_mock[
'questions.properties.repository'] = fn(Pimple\
Container $c)
505 => $this->createMock(
506 ILIAS\
Test\Questions\Properties\Repository::class
508 return $local_dic_mock;
513 $reflection_function =
new ReflectionFunction($adapt);
514 if ($reflection_function->getNumberOfParameters() !== 1) {
515 throw new \Exception(
'Callable must have exactly one parameter of type MockObject.');
518 if (isset($this->services[$service_name])) {
520 if (!isset(
$DIC[$this->services[$service_name]])) {
521 $DIC[$this->services[$service_name]] = $this->createMock($service_name);
524 $adapt(
$DIC[$this->services[$service_name]]);
533 $this->dic[
'tpl']->expects($this->once())->method(
'setContent')->with($expected_content);
538 $this->dic[
'ilCtrl']->method(
'getCmd')->willReturn($command);
543 $this->dic[
'ilCtrl']->expects($expects)->method(
'redirect')->with($this->anything(), $this->equalTo($method));
546 public function mockPostRequest(array $properties, array $query_parameters = []): void
548 $this->
mockRequest(
'POST', $properties, $query_parameters);
556 private function mockRequest(
string $request_method, array $properties, array $query_parameters): void
558 $_SERVER[
'REQUEST_METHOD'] = $request_method;
559 $request = $this->createConfiguredMock(ServerRequestInterface::class, [
560 'getServerParams' => [
'REQUEST_METHOD' => $request_method],
561 'getParsedBody' => $properties,
562 'getQueryParams' => $query_parameters
564 $this->dic[
'http']->method(
'request')->willReturn($request);
565 $this->dic[
'http']->method(
'wrapper')->willReturn(
new WrapperFactory($request));
Customizing of pimple-DIC for ILIAS.
Builds a Color from either hex- or rgb values.
Renderer that dispatches rendering of UI components to a Renderer found in the same namespace as the ...
expectRedirect(InvocationOrder $expects, string $method)
mockPostRequest(array $properties, array $query_parameters=[])
addGlobal_objDefinition()
addGlobal_ilIliasIniFile()
adaptDICServiceMock(string $service_name, callable $adapt)
addGlobal_ilAppEventHandler()
mockRequest(string $request_method, array $properties, array $query_parameters)
addGlobal_ilNavigationHistory()
addGlobal_ilComponentFactory()
addGlobal_GlobalScreenService()
setGlobalVariable(string $name, mixed $value)
addGlobal_objectMetadata()
addGlobal_ilObjDataCache()
mockCommand(string $command)
mockGetRequest(array $query_parameters=[])
addGlobal_resourceStorage()
addGlobal_uiUploadLimitResolver()
addGlobal_ilComponentRepository()
addGlobal_ilLoggerFactory()
trait ilTestBaseTestCaseTrait
addGlobal_objectService()
expectTplContent(mixed $expected_content)
Expect that the template content will be set to the specified expected content.
The Filesystems interface defines the access methods which can be used to fetch the different filesys...
Interface GlobalHttpState.
An entity that renders components to a string output.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.