ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
AddLanguageEntryTestFixture.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
28trait AddLanguageEntryTestFixture
29{
33 protected function spyReplaceLangEntry(array &$calls): \Closure
34 {
35 return static function (
36 string $module,
37 string $identifier,
38 string $lang_key,
39 string $value,
40 string $local_change,
41 string $remarks
42 ) use (&$calls): bool {
43 $calls['replace'][] = [$module, $identifier, $lang_key, $value, $local_change, $remarks];
44 return true;
45 };
46 }
47
51 protected function spyUpdateModuleCache(array &$calls): \Closure
52 {
53 return static function (
54 string $lang_key,
55 string $module,
56 string $identifier,
57 string $value,
58 string $remarks = ''
59 ) use (&$calls): void {
60 $calls['cache'][] = [$lang_key, $module, $identifier, $value];
61 };
62 }
63
73 protected function createActivity(
74 array $installed_languages,
75 ?\ilRbacSystem $rbac = null,
76 ?Language $language = null,
77 ?InstalledLanguageRepository $installed_language_repository = null,
78 int $language_folder_ref_id = 0,
79 ?\Closure $replace_lang_entry = null,
80 ?\Closure $update_module_cache = null,
81 ?\Closure $user_login = null,
82 ?\Closure $languages_without_plural_form = null,
83 ?\Closure $duplicates_of = null,
84 ?\Closure $has_unreadable_content = null,
85 ): AddLanguageEntry {
86 // no-op defaults; tests proving a closure is never called pass a throwing one
87 $replace_lang_entry ??= static fn(
88 string $module,
89 string $identifier,
90 string $lang_key,
91 string $value,
92 string $local_change,
93 string $remarks
94 ): bool => true;
95 $update_module_cache ??= static fn(
96 string $lang_key,
97 string $module,
98 string $identifier,
99 string $value,
100 string $remarks = ''
101 ): bool => true;
102 $user_login ??= static fn(int $usr_id): string => 'default-login';
103 $languages_without_plural_form ??= static fn(string $module, string $identifier, array $lang_keys): array => [];
104 $duplicates_of ??= static fn(string $module, string $identifier): array => [];
105 $has_unreadable_content ??= static fn(string $lang_key, string $module): bool => false;
106 $installed_language_repository ??= new FakeInstalledLanguageRepository(static fn(): array => $installed_languages);
107
108 $repository = $this->createStub(RepositoryProvider::class);
109 $repository->method('getInstalledLanguages')->willReturnCallback(
110 static fn(): array => $installed_language_repository->getInstalledLanguages()
111 );
112 $repository->method('replaceLangEntry')->willReturnCallback($replace_lang_entry);
113 $repository->method('updateModuleCache')->willReturnCallback(
114 static fn(
115 string $lang_key,
116 string $module,
117 string $identifier,
118 string $value,
119 string $remarks = ''
120 ): bool => $update_module_cache($lang_key, $module, $identifier, $value, $remarks) ?? true
121 );
122 $repository->method('lookupLogin')->willReturnCallback($user_login);
123 $repository->method('hasUnreadableContent')->willReturnCallback($has_unreadable_content);
124 $repository->method('languagesWithoutPluralForm')->willReturnCallback($languages_without_plural_form);
125 $repository->method('findDuplicatesOf')->willReturnCallback($duplicates_of);
126
127 return new AddLanguageEntry(
128 $language ?? $this->createStub(Language::class),
129 $this->rbacOf($rbac ?? $this->createStub(\ilRbacSystem::class)),
130 $this->languageFolder($language_folder_ref_id),
131 $repository,
132 );
133 }
134}
Every legacy and repository access of the runtime language activities.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
if(!isset($arguments[0])) if(count( $arguments) > 3) if(! $remove_from_lang &&isset($arguments[2]) &&!is_dir($arguments[2])) $module
Read-only access to the installed languages (database) and the available or valid language files (fil...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createActivity(\Closure $lng_objects, \Closure $obj_language_factory, ?\ilRbacSystem $rbac=null, int $language_folder_ref_id=0, ?RepositoryProvider $repository=null,)