ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilObjLanguageFolderGUITestFixture.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25
27{
29
30 private function createGuiWithCollaborators(
31 InstallLanguage $install_language,
33 ilCtrl $ctrl,
37 $gui = $this->newGuiWithoutConstructor(ilObjLanguageFolderGUI::class);
38
39 $this->inject($gui, 'install_language', $install_language);
40 $this->inject($gui, 'current_user_id', 6);
41 $this->inject($gui, 'tpl', $tpl);
42 $this->inject($gui, 'ctrl', $ctrl);
43 $this->inject($gui, 'lng', $lng);
44 $this->inject($gui, 'activity_error_logger', $this->activityErrorLoggerForGui());
45 $this->inject($gui, 'ui_factory', $this->stubUiFactoryForMaybePerformAs());
46
47 return $gui;
48 }
49
51 private function emptyPerformResult(): array
52 {
53 return [
54 'installed_language_keys' => [],
55 'installed_with_local_language_keys' => [],
56 'already_installed_language_keys' => [],
57 'not_installed_language_keys' => [],
58 'invalid_local_language_files' => [],
59 ];
60 }
61
62 private function createGuiWithUpdateLanguageCollaborators(
63 UpdateLanguage $update_language,
65 ilCtrl $ctrl,
70
71 $this->inject($gui, 'update_language', $update_language);
72 $this->inject($gui, 'current_user_id', 6);
73 $this->inject($gui, 'tpl', $tpl);
74 $this->inject($gui, 'ctrl', $ctrl);
75 $this->inject($gui, 'lng', $lng);
76 $this->inject($gui, 'activity_error_logger', $this->activityErrorLoggerForGui());
77 $this->inject($gui, 'ui_factory', $this->stubUiFactoryForMaybePerformAs());
78
79 return $gui;
80 }
81
86 private function stubComponentRepositoryWithNoPlugins(): void
87 {
88 $repository = $this->createStub(ilComponentRepository::class);
89 $repository->method('getPlugins')->willReturn(new ArrayIterator([]));
90
91 $GLOBALS['DIC'] = new \ILIAS\DI\Container();
92 $GLOBALS['DIC']['component.repository'] = $repository;
93 }
94
95 private function createGuiWithUninstallLanguageCollaborators(
96 UninstallLanguage $uninstall_language,
98 ilCtrl $ctrl,
103
104 $this->inject($gui, 'uninstall_language', $uninstall_language);
105 $this->inject($gui, 'current_user_id', 6);
106 $this->inject($gui, 'tpl', $tpl);
107 $this->inject($gui, 'ctrl', $ctrl);
108 $this->inject($gui, 'lng', $lng);
109 $this->inject($gui, 'activity_error_logger', $this->activityErrorLoggerForGui());
110 $this->inject($gui, 'ui_factory', $this->stubUiFactoryForMaybePerformAs());
111
112 return $gui;
113 }
114
116 private function uninstallPerformResult(
117 array $uninstalled,
118 array $system,
119 array $user,
120 array $not_installed
121 ): array {
122 return [
123 'uninstalled_language_keys' => $uninstalled,
124 'system_language_keys' => $system,
125 'user_language_keys' => $user,
126 'not_installed_language_keys' => $not_installed,
127 ];
128 }
129
130 private function createGuiWithRemoveLocalLanguageChangesCollaborators(
131 RemoveLocalLanguageChanges $remove_local_language_changes,
133 ilCtrl $ctrl,
138
139 $this->inject($gui, 'remove_local_language_changes', $remove_local_language_changes);
140 $this->inject($gui, 'current_user_id', 6);
141 $this->inject($gui, 'tpl', $tpl);
142 $this->inject($gui, 'ctrl', $ctrl);
143 $this->inject($gui, 'lng', $lng);
144 $this->inject($gui, 'activity_error_logger', $this->activityErrorLoggerForGui());
145 $this->inject($gui, 'ui_factory', $this->stubUiFactoryForMaybePerformAs());
146
147 return $gui;
148 }
149
152 array $removed_local_changes,
153 array $invalid_language_file,
154 array $not_installed
155 ): array {
156 return [
157 'removed_local_changes_language_keys' => $removed_local_changes,
158 'invalid_language_file_keys' => $invalid_language_file,
159 'not_installed_language_keys' => $not_installed,
160 ];
161 }
162
170 private function stubObjDataCache(
171 array $types_by_id,
172 array $titles_by_id = [],
173 bool $expect_no_title_lookup = false
174 ): void {
175 if ($expect_no_title_lookup) {
176 $cache = $this->createMock(\ilObjectDataCache::class);
177 $cache->method('lookupType')->willReturnCallback(
178 static fn(int $id): string => $types_by_id[$id] ?? ''
179 );
180 $cache->expects($this->never())->method('lookupTitle');
181 } else {
182 $cache = $this->createStub(\ilObjectDataCache::class);
183 $cache->method('lookupType')->willReturnCallback(
184 static fn(int $id): string => $types_by_id[$id] ?? ''
185 );
186 $cache->method('lookupTitle')->willReturnCallback(
187 static fn(int $id): string => $titles_by_id[$id] ?? ''
188 );
189 }
190
191 if (!isset($GLOBALS['DIC'])) {
192 $GLOBALS['DIC'] = new \ILIAS\DI\Container();
193 }
194 $GLOBALS['DIC']['ilObjDataCache'] = $cache;
195 }
196
198 private function createLanguageMockWithFormatStrings(): ilLanguage&\PHPUnit\Framework\MockObject\Stub
199 {
200 $lng = $this->createStub(ilLanguage::class);
201 $lng->method('txt')->willReturnCallback(
202 static fn(string $topic): string => str_starts_with($topic, 'lng_') ? $topic . ': %s' : $topic
203 );
204
205 return $lng;
206 }
207
209 private function messageCollectingTemplate(array &$messages): ilGlobalTemplateInterface&\PHPUnit\Framework\MockObject\Stub
210 {
211 $tpl = $this->createStub(ilGlobalTemplateInterface::class);
212 $tpl->method('setOnScreenMessage')->willReturnCallback(
213 static function (string $type, string $message) use (&$messages): void {
214 $messages[] = [$type, $message];
215 }
216 );
217
218 return $tpl;
219 }
220}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilCtrl provides processing control methods.
language handling
Class ilObjLanguageFolderGUI.
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
stubObjDataCache(array $types_by_id, array $titles_by_id=[], bool $expect_no_title_lookup=false)
Stubs global $DIC["ilObjDataCache"], reusing an existing $GLOBALS['DIC'] (e.g.
stubComponentRepositoryWithNoPlugins()
refreshSelectedObject() calls the static ilObjLanguage::refreshPlugins() on every success path; an em...
messageCollectingTemplate(array &$messages)
trait ilObjLanguageFolderGUITestFixture
createLanguageMockWithFormatStrings()
Like createLanguageMockReturningTopicAsIs(), but the "lng_*" format strings carry a "%s" that makes t...
uninstallPerformResult(array $uninstalled, array $system, array $user, array $not_installed)
removeLocalChangesPerformResult(array $removed_local_changes, array $invalid_language_file, array $not_installed)
newGuiWithoutConstructor(string $class)
@template T of object
trait ilObjLanguageGuiTestSupport
Shared fixture of the ilObjLanguageFolderGUI*Test / ilObjLanguageExtGUI*Test classes.
stubUiFactoryForMaybePerformAs()
maybePerformAs() reads ui_factory->input(), whose typed property is otherwise uninitialized.
inject(object $gui, string $property_name, mixed $value)
For a mock the property is looked up on its declaring class: a plain ReflectionProperty on the mock c...
readonly ilGlobalTemplateInterface $tpl
global $lng
Definition: privfeed.php:26
if(!file_exists('../ilias.ini.php'))
$GLOBALS["DIC"]
Definition: wac.php:66