ILIAS  release_8 Revision v8.24
Base.php
Go to the documentation of this file.
1<?php
2
19require_once("libs/composer/vendor/autoload.php");
20
21require_once(__DIR__ . "/Renderer/ilIndependentTemplate.php");
22require_once(__DIR__ . "/../../Services/Language/classes/class.ilLanguage.php");
23
25use ILIAS\UI\Component\Component as IComponent;
26use ILIAS\UI\Implementaiton\Component as I;
39use PHPUnit\Framework\TestCase;
41use PHPUnit\Framework\MockObject\MockObject;
43use ILIAS\Data\Factory as DataFactory;
44
46{
47 public function getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks): Render\Template
48 {
49 return new ilIndependentGlobalTemplate($path, $purge_unfilled_vars, $purge_unused_blocks);
50 }
51}
52
53class NoUIFactory implements Factory
54{
55 public function counter(): C\Counter\Factory
56 {
57 }
58 public function button(): C\Button\Factory
59 {
60 }
61 public function card(): C\Card\Factory
62 {
63 }
64 public function deck(array $cards): C\Deck\Deck
65 {
66 }
67 public function listing(): C\Listing\Factory
68 {
69 }
70 public function image(): C\Image\Factory
71 {
72 }
73 public function legacy(string $content): C\Legacy\Legacy
74 {
75 }
76 public function panel(): C\Panel\Factory
77 {
78 }
79 public function modal(): C\Modal\Factory
80 {
81 }
82 public function dropzone(): C\Dropzone\Factory
83 {
84 }
85 public function popover(): C\Popover\Factory
86 {
87 }
88 public function divider(): C\Divider\Factory
89 {
90 }
91 public function link(): C\Link\Factory
92 {
93 }
94 public function dropdown(): C\Dropdown\Factory
95 {
96 }
97 public function item(): C\Item\Factory
98 {
99 }
100 public function viewControl(): C\ViewControl\Factory
101 {
102 }
103 public function breadcrumbs(array $crumbs): C\Breadcrumbs\Breadcrumbs
104 {
105 }
106 public function chart(): C\Chart\Factory
107 {
108 }
109 public function input(): C\Input\Factory
110 {
111 }
112 public function table(): C\Table\Factory
113 {
114 }
115 public function messageBox(): C\MessageBox\Factory
116 {
117 }
118 public function layout(): C\Layout\Factory
119 {
120 }
121 public function mainControls(): C\MainControls\Factory
122 {
123 }
124 public function tree(): C\Tree\Factory
125 {
126 }
127 public function menu(): C\Menu\Factory
128 {
129 }
130 public function symbol(): C\Symbol\Factory
131 {
132 }
133 public function toast(): C\Toast\Factory
134 {
135 }
136 public function player(): C\Player\Factory
137 {
138 }
139}
140
142{
143 public $resources = array();
144
145 public function register(string $name): void
146 {
147 $this->resources[] = $name;
148 }
149}
150
152{
153 public array $requested = array();
154
155 public function __construct()
156 {
157 }
158
159 public function txt($a_topic, $a_default_lang_fallback_mod = ""): string
160 {
161 $this->requested[] = $a_topic;
162 return $a_topic;
163 }
164
165 public function toJS($a_lang_key, ilGlobalTemplateInterface $a_tpl = null): void
166 {
167 }
168
169 public string $lang_module = 'common';
170
171 public function loadLanguageModule(string $a_module): void
172 {
173 }
174
175 public function getLangKey(): string
176 {
177 return "en";
178 }
179}
180
182{
183 public array $on_load_code = array();
184 public array $ids = array();
185 private int $count = 0;
186
187 public function createId(): string
188 {
189 $this->count++;
190 $id = "id_" . $this->count;
191 $this->ids[] = $id;
192 return $id;
193 }
194
195 public function addOnLoadCode($code): void
196 {
197 $this->on_load_code[] = $code;
198 }
199
200 public function getOnLoadCodeAsync(): string
201 {
202 return "";
203 }
204}
205
207{
208 protected array $with_stub_renderings = [];
209
211 {
212 $this->with_stub_renderings = array_map(function ($component) {
213 return get_class($component);
216 }
217
218 public function _getRendererFor(IComponent $component): Render\ComponentRenderer
219 {
220 return $this->getRendererFor($component);
221 }
222
223 public function getRendererFor(IComponent $component): Render\ComponentRenderer
224 {
225 if (in_array(get_class($component), $this->with_stub_renderings)) {
226 return new TestDummyRenderer();
227 }
228 return parent::getRendererFor($component);
229 }
230
231 public function _getContexts(): array
232 {
233 return $this->getContexts();
234 }
235}
236
238{
239 public function __construct()
240 {
241 }
242
243 public function render(ILIAS\UI\Component\Component $component, ILIAS\UI\Renderer $default_renderer): string
244 {
245 return $component->getCanonicalName();
246 }
247
248 public function registerResources(ResourceRegistry $registry): void
249 {
250 // TODO: Implement registerResources() method.
251 }
252}
253
255{
256 private $manipulate = false;
257
258 public function manipulate(): void
259 {
260 $this->manipulate = true;
261 }
262
263 protected function manipulateRendering($component, Renderer $root): ?string
264 {
265 if ($this->manipulate) {
266 return "This content was manipulated";
267 } else {
268 return null;
269 }
270 }
271}
272
274{
275 protected int $id = 0;
276
277 protected function createId(): string
278 {
279 return 'signal_' . ++$this->id;
280 }
281}
282
284{
285}
286
287class DummyComponent implements IComponent
288{
289 public function getCanonicalName(): string
290 {
291 return "DummyComponent";
292 }
293}
294
298abstract class ILIAS_UI_TestBase extends TestCase
299{
300 public function setUp(): void
301 {
302 assert_options(ASSERT_WARNING, 0);
303 }
304
305 public function tearDown(): void
306 {
307 assert_options(ASSERT_WARNING, 1);
308 }
309
310 public function getUIFactory(): NoUIFactory
311 {
312 return new NoUIFactory();
313 }
314
316 {
317 return new ilIndependentTemplateFactory();
318 }
319
321 {
322 return new LoggingRegistry();
323 }
324
325 public function getLanguage(): ilLanguageMock
326 {
327 return new ilLanguageMock();
328 }
329
331 {
332 return new LoggingJavaScriptBinding();
333 }
334
338 public function getRefinery()
339 {
340 return $this->getMockBuilder(\ILIAS\Refinery\Factory::class)
341 ->disableOriginalConstructor()
342 ->getMock();
343 }
344
346 {
347 return new ilImagePathResolver();
348 }
349
350 public function getDataFactory(): DataFactory
351 {
352 return $this->createMock(DataFactory::class);
353 }
354
355 public function getDefaultRenderer(
356 JavaScriptBinding $js_binding = null,
357 array $with_stub_renderings = []
359 $ui_factory = $this->getUIFactory();
360 $tpl_factory = $this->getTemplateFactory();
361 $resource_registry = $this->getResourceRegistry();
362 $lng = $this->getLanguage();
363 if (!$js_binding) {
364 $js_binding = $this->getJavaScriptBinding();
365 }
366
367 $refinery = $this->getRefinery();
368 $image_path_resolver = $this->getImagePathResolver();
369 $data_factory = $this->getDataFactory();
370
371 $component_renderer_loader = new Render\LoaderCachingWrapper(
373 $resource_registry,
374 new Render\FSLoader(
376 $ui_factory,
377 $tpl_factory,
378 $lng,
379 $js_binding,
380 $refinery,
381 $image_path_resolver,
382 $data_factory
383 ),
385 $ui_factory,
386 $tpl_factory,
387 $lng,
388 $js_binding,
389 $refinery,
390 $image_path_resolver,
391 $data_factory
392 ),
394 $ui_factory,
395 $tpl_factory,
396 $lng,
397 $js_binding,
398 $refinery,
399 $image_path_resolver,
400 $data_factory
401 ),
403 $ui_factory,
404 $tpl_factory,
405 $lng,
406 $js_binding,
407 $refinery,
408 $image_path_resolver,
409 $data_factory
410 )
411 )
412 )
413 );
414 return new TestDefaultRenderer($component_renderer_loader, $with_stub_renderings);
415 }
416
417 public function getDecoratedRenderer(Renderer $default)
418 {
419 return new TestDecoratedRenderer($default);
420 }
421
422 public function normalizeHTML(string $html): string
423 {
424 return trim(str_replace(["\n", "\r"], "", $html));
425 }
426
427 public function assertHTMLEquals(string $expected_html_as_string, string $html_as_string): void
428 {
429 $html = new DOMDocument();
430 $html->formatOutput = true;
431 $html->preserveWhiteSpace = false;
432 $expected = new DOMDocument();
433 $expected->formatOutput = true;
434 $expected->preserveWhiteSpace = false;
435 $html->loadXML($this->normalizeHTML($html_as_string));
436 $expected->loadXML($this->normalizeHTML($expected_html_as_string));
437 $this->assertEquals($expected->saveHTML(), $html->saveHTML());
438 }
439
444 protected function brutallyTrimHTML(string $html): string
445 {
446 $html = str_replace(["\n", "\r", "\t"], "", $html);
447 $html = preg_replace('# {2,}#', " ", $html);
448 $html = preg_replace('/<!--(.|\s)*?-->/', '', $html);
449 $html = preg_replace("/>(\s+)</", "><", $html);
450 $html = str_replace(" >", ">", $html);
451 $html = str_replace(" <", "<", $html);
452 return trim($html);
453 }
454
459 protected function brutallyTrimSignals(string $html): string
460 {
461 $html = preg_replace('/il_signal_(\w+)/', "il_signal...", $html);
462 return $html;
463 }
464}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getCanonicalName()
Get the canonical name of the component.
Definition: Base.php:289
Builds data types.
Definition: Factory.php:21
Renderer that dispatches rendering of UI components to a Renderer found in the same namespace as the ...
getContexts()
Get the contexts that are added via withAdditionalContext where most recently added contexts come las...
Loads renderers for components from the file system.
Definition: FSLoader.php:40
Registers resources for retreived renderers at a ResourceRegistry.
Provides common functionality for UI tests.
Definition: Base.php:299
getJavaScriptBinding()
Definition: Base.php:330
getImagePathResolver()
Definition: Base.php:345
getDecoratedRenderer(Renderer $default)
Definition: Base.php:417
normalizeHTML(string $html)
Definition: Base.php:422
getTemplateFactory()
Definition: Base.php:315
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
brutallyTrimSignals(string $html)
A naive replacement of all il_signal-ids with dots to ease comparisons of rendered output.
Definition: Base.php:459
getResourceRegistry()
Definition: Base.php:320
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
createId()
Create a fresh unique id.
Definition: Base.php:187
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.
Definition: Base.php:200
card()
Definition: Base.php:61
image()
Definition: Base.php:70
dropzone()
Definition: Base.php:82
listing()
Definition: Base.php:67
symbol()
Definition: Base.php:130
panel()
Definition: Base.php:76
link()
Definition: Base.php:91
item()
Definition: Base.php:97
modal()
Definition: Base.php:79
legacy(string $content)
Definition: Base.php:73
deck(array $cards)
Definition: Base.php:64
divider()
Definition: Base.php:88
player()
Definition: Base.php:136
counter()
Definition: Base.php:55
button()
Definition: Base.php:58
dropdown()
Definition: Base.php:94
popover()
Definition: Base.php:85
messageBox()
Definition: Base.php:115
viewControl()
Definition: Base.php:100
breadcrumbs(array $crumbs)
Definition: Base.php:103
layout()
Definition: Base.php:118
mainControls()
Definition: Base.php:121
manipulateRendering($component, Renderer $root)
Manipulates the rendering of one or multiple components by appending, prepending or exchanging their ...
Definition: Base.php:263
__construct(Render\Loader $component_renderer_loader, array $with_stub_renderings=[])
Definition: Base.php:210
_getRendererFor(IComponent $component)
Definition: Base.php:218
array $with_stub_renderings
Definition: Base.php:208
getRendererFor(IComponent $component)
Definition: Base.php:223
registerResources(ResourceRegistry $registry)
Definition: Base.php:248
render(ILIAS\UI\Component\Component $component, ILIAS\UI\Renderer $default_renderer)
Definition: Base.php:243
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template instance.
Definition: Base.php:47
toJS($a_lang_key, ilGlobalTemplateInterface $a_tpl=null)
Transfer text to Javascript.
Definition: Base.php:165
txt($a_topic, $a_default_lang_fallback_mod="")
Definition: Base.php:159
string $lang_module
Definition: Base.php:169
array $requested
Definition: Base.php:153
loadLanguageModule(string $a_module)
Load language module.
Definition: Base.php:171
getLangKey()
Return lang key.
Definition: Base.php:175
language handling
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Provides methods to interface with javascript.
Loads renderers for components.
Definition: Loader.php:30
Registry for resources required by rendered output like Javascript or CSS.
Interface for a factory that provides templates.
Interface to templating as it is used in the UI framework.
Definition: Template.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32
if($format !==null) $name
Definition: metadata.php:247
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Refinery Factory $refinery
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$lng