ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Base.php
Go to the documentation of this file.
1<?php
2
19require_once(__DIR__ . '/../../../../vendor/composer/vendor/autoload.php');
20
21require_once(__DIR__ . '/Renderer/ilIndependentTemplate.php');
22require_once(__DIR__ . '/../../Language/classes/class.ilLanguage.php');
23
25use ILIAS\UI\Component\Component as IComponent;
38use PHPUnit\Framework\TestCase;
40use PHPUnit\Framework\MockObject\MockObject;
42use ILIAS\UI\Implementation\Component\ComponentHelper;
43use ILIAS\Data\Factory as DataFactory;
49
51{
52 public function getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks): Render\Template
53 {
54 return new ilIndependentGlobalTemplate($path, $purge_unfilled_vars, $purge_unused_blocks);
55 }
56}
57
59{
60 public function counter(): I\Counter\Factory
61 {
62 }
63 public function button(): I\Button\Factory
64 {
65 }
66 public function card(): I\Card\Factory
67 {
68 }
69 public function deck(array $cards): I\Deck\Deck
70 {
71 }
72 public function listing(): I\Listing\Factory
73 {
74 }
75 public function image(): I\Image\Factory
76 {
77 }
78 public function legacy(): I\Legacy\Factory
79 {
80 }
81 public function panel(): I\Panel\Factory
82 {
83 }
84 public function modal(): I\Modal\Factory
85 {
86 }
87 public function progress(): I\Progress\Factory
88 {
89 }
90 public function dropzone(): I\Dropzone\Factory
91 {
92 }
93 public function popover(): I\Popover\Factory
94 {
95 }
96 public function divider(): I\Divider\Factory
97 {
98 }
99 public function link(): I\Link\Factory
100 {
101 }
102 public function dropdown(): I\Dropdown\Factory
103 {
104 }
105 public function item(): I\Item\Factory
106 {
107 }
108 public function viewControl(): I\ViewControl\Factory
109 {
110 }
111 public function breadcrumbs(array $crumbs): I\Breadcrumbs\Breadcrumbs
112 {
113 }
114 public function chart(): I\Chart\Factory
115 {
116 }
117 public function input(): I\Input\Factory
118 {
119 }
120 public function table(): I\Table\Factory
121 {
122 }
123 public function messageBox(): I\MessageBox\Factory
124 {
125 }
126 public function layout(): I\Layout\Factory
127 {
128 }
129 public function mainControls(): I\MainControls\Factory
130 {
131 }
132 public function tree(): I\Tree\Factory
133 {
134 }
135 public function menu(): I\Menu\Factory
136 {
137 }
138 public function symbol(): I\Symbol\Factory
139 {
140 }
141 public function toast(): I\Toast\Factory
142 {
143 }
144 public function player(): I\Player\Factory
145 {
146 }
147 public function launcher(): I\Launcher\Factory
148 {
149 }
150 public function helpTopics(string ...$topic): array
151 {
152 }
153 public function entity(): I\Entity\Factory
154 {
155 }
156 public function prompt(): I\Prompt\Factory
157 {
158 }
159 public function navigation(): I\Navigation\Factory
160 {
161 }
162}
163
165{
166 public $resources = array();
167
168 public function register(string $name): void
169 {
170 $this->resources[] = $name;
171 }
172}
173
175{
176 public array $requested = array();
177
178 public function __construct()
179 {
180 }
181
182 public function txt($a_topic, $a_default_lang_fallback_mod = ""): string
183 {
184 $this->requested[] = $a_topic;
185 return $a_topic;
186 }
187
188 public function toJS($a_lang_key, ?ilGlobalTemplateInterface $a_tpl = null): void
189 {
190 }
191
192 public string $lang_module = 'common';
193
194 public function loadLanguageModule(string $a_module): void
195 {
196 }
197
198 public function getLangKey(): string
199 {
200 return "en";
201 }
202}
203
205{
206 public array $on_load_code = array();
207 public array $ids = array();
208 private int $count = 0;
209
210 public function createId(): string
211 {
212 $this->count++;
213 $id = "id_" . $this->count;
214 $this->ids[] = $id;
215 return $id;
216 }
217
218 public function addOnLoadCode($code): void
219 {
220 $this->on_load_code[] = $code;
221 }
222
223 public function getOnLoadCodeAsync(): string
224 {
225 return "";
226 }
227}
228
230{
231 protected array $with_stub_renderings = [];
232
233 public function __construct(
234 Render\Loader $component_renderer_loader,
235 JavaScriptBinding $java_script_binding,
236 \ILIAS\Language\Language $language,
237 array $with_stub_renderings = [],
238 protected array $with_additional_contexts = [],
239 ) {
240 $this->with_stub_renderings = array_map(function ($component) {
241 return get_class($component);
243
244 array_walk($this->with_additional_contexts, fn(Component $c) => $this->pushContext($c));
245
246 parent::__construct($component_renderer_loader, $java_script_binding, $language);
247 }
248
249 public function _getRendererFor(IComponent $component): Render\ComponentRenderer
250 {
251 return $this->getRendererFor($component);
252 }
253
254 public function getRendererFor(IComponent $component): Render\ComponentRenderer
255 {
256 if (in_array(get_class($component), $this->with_stub_renderings)) {
257 return new TestDummyRenderer();
258 }
259 return parent::getRendererFor($component);
260 }
261
262 public function _getContexts(): array
263 {
264 return $this->getContexts();
265 }
266
267 public function getComponentCanonicalNameAttribute(IComponent $component): string
268 {
269 return str_replace(' ', '-', strtolower($component->getCanonicalName()));
270 }
271}
272
274{
275 public function __construct()
276 {
277 }
278
279 public function render(ILIAS\UI\Component\Component $component, ILIAS\UI\Renderer $default_renderer): string
280 {
281 return $component->getCanonicalName();
282 }
283
284 public function registerResources(ResourceRegistry $registry): void
285 {
286 // TODO: Implement registerResources() method.
287 }
288}
289
291{
292 private $manipulate = false;
293
294 public function manipulate(): void
295 {
296 $this->manipulate = true;
297 }
298
299 protected function manipulateRendering($component, Renderer $root): ?string
300 {
301 if ($this->manipulate) {
302 return "This content was manipulated";
303 } else {
304 return null;
305 }
306 }
307}
308
310{
311 protected int $id = 0;
312
313 protected function createId(): string
314 {
315 return 'signal_' . ++$this->id;
316 }
317}
318
320{
321}
322
323class DummyComponent implements IComponent
324{
325 use ComponentHelper;
326
327 public function getCanonicalName(): string
328 {
329 return "DummyComponent";
330 }
331}
332
336abstract class ILIAS_UI_TestBase extends TestCase
337{
338 use BaseUITestTrait;
339}
340
341trait BaseUITestTrait
342{
343 public function getUIFactory(): NoUIFactory
344 {
345 return new NoUIFactory();
346 }
347
348 public function getTemplateFactory(): ilIndependentTemplateFactory
349 {
350 return new ilIndependentTemplateFactory();
351 }
352
353 public function getResourceRegistry(): LoggingRegistry
354 {
355 return new LoggingRegistry();
356 }
357
358 public function getLanguage(): LanguageMock
359 {
360 return new LanguageMock();
361 }
362
363 public function getJavaScriptBinding(): LoggingJavaScriptBinding
364 {
365 return new LoggingJavaScriptBinding();
366 }
367
371 public function getRefinery()
372 {
373 return $this->getMockBuilder(\ILIAS\Refinery\Factory::class)
374 ->disableOriginalConstructor()
375 ->getMock();
376 }
377
378 public function getImagePathResolver(): ilImagePathResolver
379 {
380 return new ilImagePathResolver();
381 }
382
383 public function getDataFactory(): DataFactory
384 {
385 return $this->createMock(DataFactory::class);
386 }
387
388 public function getHelpTextRetriever(): HelpTextRetriever
389 {
390 return new Help\TextRetriever\Echoing();
391 }
392
393 public function getUploadLimitResolver(): UploadLimitResolver
394 {
395 return $this->createMock(UploadLimitResolver::class);
396 }
397
402 public function getDefaultRenderer(
403 ?JavaScriptBinding $js_binding = null,
404 array $with_stub_renderings = [],
405 array $with_additional_contexts = [],
407 $ui_factory = $this->getUIFactory();
408 $tpl_factory = $this->getTemplateFactory();
409 $resource_registry = $this->getResourceRegistry();
410 $lng = $this->getLanguage();
411 if (!$js_binding) {
412 $js_binding = $this->getJavaScriptBinding();
413 }
414
415 $image_path_resolver = $this->getImagePathResolver();
416 $data_factory = $this->getDataFactory();
417 $help_text_retriever = $this->getHelpTextRetriever();
418
419 $component_renderer_loader = new Render\LoaderCachingWrapper(
421 $resource_registry,
422 new Render\FSLoader(
424 $ui_factory,
425 $tpl_factory,
426 $lng,
427 $js_binding,
428 $image_path_resolver,
429 $data_factory,
430 $help_text_retriever,
431 $this->getUploadLimitResolver()
432 ),
434 $ui_factory,
435 $tpl_factory,
436 $lng,
437 $js_binding,
438 $image_path_resolver,
439 $data_factory,
440 $help_text_retriever,
441 $this->getUploadLimitResolver()
442 ),
444 $ui_factory,
445 $tpl_factory,
446 $lng,
447 $js_binding,
448 $image_path_resolver,
449 $data_factory,
450 $help_text_retriever,
451 $this->getUploadLimitResolver()
452 ),
454 $ui_factory,
455 $tpl_factory,
456 $lng,
457 $js_binding,
458 $image_path_resolver,
459 $data_factory,
460 $help_text_retriever,
461 $this->getUploadLimitResolver()
462 ),
464 $ui_factory,
465 $tpl_factory,
466 $lng,
467 $js_binding,
468 $image_path_resolver,
469 $data_factory,
470 $help_text_retriever,
471 $this->getUploadLimitResolver()
472 ),
473 new I\Menu\MenuRendererFactory(
474 $ui_factory,
475 $tpl_factory,
476 $lng,
477 $js_binding,
478 $image_path_resolver,
479 $data_factory,
480 $help_text_retriever,
481 $this->getUploadLimitResolver(),
482 )
483 )
484 )
485 );
486 return new TestDefaultRenderer($component_renderer_loader, $js_binding, $lng, $with_stub_renderings, $with_additional_contexts);
487 }
488
489 public function getDecoratedRenderer(Renderer $default)
490 {
491 return new TestDecoratedRenderer($default);
492 }
493
494 public function normalizeHTML(string $html): string
495 {
496 return trim(str_replace(["\n", "\r"], "", $html));
497 }
498
504 public function assertHTMLEquals(string $expected_html_as_string, string $html_as_string): void
505 {
506 $html = new DOMDocument();
507 $html->formatOutput = true;
508 $html->preserveWhiteSpace = false;
509 $expected = new DOMDocument();
510 $expected->formatOutput = true;
511 $expected->preserveWhiteSpace = false;
512 $html->loadXML($this->normalizeHTML($html_as_string));
513 $expected->loadXML($this->normalizeHTML($expected_html_as_string));
514 $this->assertEquals($expected->saveHTML(), $html->saveHTML());
515 }
516
521 protected function brutallyTrimHTML(string $html): string
522 {
523 $html = str_replace(["\n", "\r", "\t"], "", $html);
524 $html = preg_replace('# {2,}#', " ", $html);
525 $html = preg_replace('/<!--(.|\s)*?-->/', '', $html);
526 $html = preg_replace("/>(\s+)</", "><", $html);
527 $html = str_replace(" >", ">", $html);
528 $html = str_replace(" <", "<", $html);
529 return trim($html);
530 }
531
536 protected function brutallyTrimSignals(string $html): string
537 {
538 $html = preg_replace('/il_signal_(\w+)/', "il_signal...", $html);
539 return $html;
540 }
541}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getCanonicalName()
Get the canonical name of the component.
Definition: Base.php:327
Builds data types.
Definition: Factory.php:36
Renderer that dispatches rendering of UI components to a Renderer found in the same namespace as the ...
getContexts()
Returns the current context stack, where most recently added components are last.
pushContext(Component $component)
Adds a component to the current context stack.
Loads renderers for components from the file system.
Definition: FSLoader.php:43
Registers resources for retreived renderers at a ResourceRegistry.
Definition: UI.php:24
Provides common functionality for UI tests.
Definition: Base.php:337
toJS($a_lang_key, ?ilGlobalTemplateInterface $a_tpl=null)
Transfer text to Javascript.
Definition: Base.php:188
array $requested
Definition: Base.php:176
getLangKey()
Return lang key.
Definition: Base.php:198
txt($a_topic, $a_default_lang_fallback_mod="")
Definition: Base.php:182
loadLanguageModule(string $a_module)
Load language module.
Definition: Base.php:194
__construct()
Definition: Base.php:178
string $lang_module
Definition: Base.php:192
createId()
Create a fresh unique id.
Definition: Base.php:210
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.
Definition: Base.php:223
card()
Definition: Base.php:66
entity()
Definition: Base.php:153
image()
Definition: Base.php:75
dropzone()
Definition: Base.php:90
listing()
Definition: Base.php:72
helpTopics(string ... $topic)
Definition: Base.php:150
symbol()
Definition: Base.php:138
navigation()
Definition: Base.php:159
legacy()
Definition: Base.php:78
panel()
Definition: Base.php:81
link()
Definition: Base.php:99
modal()
Definition: Base.php:84
progress()
Definition: Base.php:87
deck(array $cards)
Definition: Base.php:69
divider()
Definition: Base.php:96
player()
Definition: Base.php:144
counter()
Definition: Base.php:60
button()
Definition: Base.php:63
launcher()
Definition: Base.php:147
dropdown()
Definition: Base.php:102
prompt()
Definition: Base.php:156
popover()
Definition: Base.php:93
messageBox()
Definition: Base.php:123
viewControl()
Definition: Base.php:108
breadcrumbs(array $crumbs)
Definition: Base.php:111
layout()
Definition: Base.php:126
mainControls()
Definition: Base.php:129
manipulateRendering($component, Renderer $root)
Manipulates the rendering of one or multiple components by appending, prepending or exchanging their ...
Definition: Base.php:299
_getRendererFor(IComponent $component)
Definition: Base.php:249
getComponentCanonicalNameAttribute(IComponent $component)
Definition: Base.php:267
array $with_stub_renderings
Definition: Base.php:231
__construct(Render\Loader $component_renderer_loader, JavaScriptBinding $java_script_binding, \ILIAS\Language\Language $language, array $with_stub_renderings=[], protected array $with_additional_contexts=[],)
Definition: Base.php:233
getRendererFor(IComponent $component)
Definition: Base.php:254
registerResources(ResourceRegistry $registry)
Definition: Base.php:284
render(ILIAS\UI\Component\Component $component, ILIAS\UI\Renderer $default_renderer)
Definition: Base.php:279
getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template instance.
Definition: Base.php:52
language handling
$c
Definition: deliver.php:25
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This describes a symbol.
Definition: Symbol.php:30
This describes a facility that the UI framework can use to retrieve some help text.
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
$path
Definition: ltiservices.php:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
getLanguage()