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 \
ILIAS\
Mail\TemplateEngine\TemplateEngineFactoryInterface::class,
431 $this->createMock(\
ILIAS\
Mail\TemplateEngine\TemplateEngineFactoryInterface::class)
438 new ILIAS\FileDelivery\
Token\Signer\Key\Secret\SecretKeyRotation(
439 new ILIAS\FileDelivery\
Token\Signer\Key\Secret\SecretKey(
'blup')
442 $http_mock = $this->createMock(HTTPServices::class);
443 $response_builder_mock = $this->createMock(\
ILIAS\FileDelivery\Delivery\ResponseBuilder\ResponseBuilder::class);
444 return new \ILIAS\FileDelivery\Services(
445 new ILIAS\FileDelivery\Delivery\StreamDelivery(
448 $response_builder_mock,
449 $response_builder_mock
451 new \
ILIAS\FileDelivery\Delivery\LegacyDelivery(
453 $response_builder_mock,
454 $response_builder_mock
463 return $this->createConfiguredMock(ilObjTest::class, [
470 $local_dic_mock = $this->getMockBuilder(
ILIAS\
Test\TestDIC::class)
471 ->onlyMethods([])->getMock();
472 $local_dic_mock[
'question.general_properties.repository'] = fn(Pimple\
Container $c)
473 => $this->createMock(
474 ILIAS\TestQuestionPool\Questions\GeneralQuestionPropertiesRepository::class
476 $local_dic_mock[
'request_data_collector'] = fn(Pimple\
Container $c)
477 => $this->createMock(
480 $local_dic_mock[
'participant.access_filter.factory'] = fn(Pimple\
Container $c)
481 => $this->createMock(
482 \ilTestParticipantAccessFilterFactory::class
484 $local_dic_mock[
'logging.logger'] = fn(Pimple\
Container $c)
485 => $this->createMock(
488 $local_dic_mock[
'logging.viewer'] = fn(Pimple\
Container $c)
489 => $this->createMock(
492 $local_dic_mock[
'shuffler'] = fn(Pimple\
Container $c)
493 => $this->createMock(
494 \ilTestShuffler::class
496 $local_dic_mock[
'results.presentation.factory'] = fn(Pimple\
Container $c)
497 => $this->createMock(
498 ILIAS\
Test\Results\Presentation\Factory::class
500 $local_dic_mock[
'results.data.factory'] = fn(Pimple\
Container $c)
501 => $this->createMock(
504 $local_dic_mock[
'results.toplist.repository'] = fn(Pimple\
Container $c)
505 => $this->createMock(
506 ILIAS\
Test\Results\Toplist\TestTopListRepository::class
508 $local_dic_mock[
'results.data.repository'] = fn(Pimple\
Container $c)
509 => $this->createMock(
510 \
ILIAS\
Test\Results\Data\Repository::class
512 $local_dic_mock[
'questions.properties.repository'] = fn(Pimple\
Container $c)
513 => $this->createMock(
514 ILIAS\
Test\Questions\Properties\Repository::class
516 return $local_dic_mock;
521 $reflection_function =
new ReflectionFunction($adapt);
522 if ($reflection_function->getNumberOfParameters() !== 1) {
523 throw new \Exception(
'Callable must have exactly one parameter of type MockObject.');
526 if (isset($this->services[$service_name])) {
528 if (!isset(
$DIC[$this->services[$service_name]])) {
529 $DIC[$this->services[$service_name]] = $this->createMock($service_name);
532 $adapt(
$DIC[$this->services[$service_name]]);
541 $this->dic[
'tpl']->expects($this->once())->method(
'setContent')->with($expected_content);
546 $this->dic[
'ilCtrl']->method(
'getCmd')->willReturn($command);
551 $this->dic[
'ilCtrl']->expects($expects)->method(
'redirect')->with($this->anything(), $this->equalTo($method));
554 public function mockPostRequest(array $properties, array $query_parameters = []): void
556 $this->
mockRequest(
'POST', $properties, $query_parameters);
564 private function mockRequest(
string $request_method, array $properties, array $query_parameters): void
566 $_SERVER[
'REQUEST_METHOD'] = $request_method;
567 $request = $this->createConfiguredMock(ServerRequestInterface::class, [
568 'getServerParams' => [
'REQUEST_METHOD' => $request_method],
569 'getParsedBody' => $properties,
570 'getQueryParams' => $query_parameters
572 $this->dic[
'http']->method(
'request')->willReturn($request);
573 $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.
RFC 822 Email address list validation Utility.