ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
Base.php
Go to the documentation of this file.
1 <?php
2 
19 require_once(__DIR__ . '/../../../../vendor/composer/vendor/autoload.php');
20 
21 require_once(__DIR__ . '/Renderer/ilIndependentTemplate.php');
22 require_once(__DIR__ . '/../../Language/classes/class.ilLanguage.php');
23 
24 use ILIAS\UI\Component as C;
26 use ILIAS\UI\Implementaiton\Component as I;
45 use ILIAS\UI\Help;
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 
58 class NoUIFactory implements Factory
59 {
60  public function counter(): C\Counter\Factory
61  {
62  }
63  public function button(): C\Button\Factory
64  {
65  }
66  public function card(): C\Card\Factory
67  {
68  }
69  public function deck(array $cards): C\Deck\Deck
70  {
71  }
72  public function listing(): C\Listing\Factory
73  {
74  }
75  public function image(): C\Image\Factory
76  {
77  }
78  public function legacy(string $content): C\Legacy\Legacy
79  {
80  }
81  public function panel(): C\Panel\Factory
82  {
83  }
84  public function modal(): C\Modal\Factory
85  {
86  }
87  public function progress(): C\Progress\Factory
88  {
89  }
90  public function dropzone(): C\Dropzone\Factory
91  {
92  }
93  public function popover(): C\Popover\Factory
94  {
95  }
96  public function divider(): C\Divider\Factory
97  {
98  }
99  public function link(): C\Link\Factory
100  {
101  }
102  public function dropdown(): C\Dropdown\Factory
103  {
104  }
105  public function item(): C\Item\Factory
106  {
107  }
108  public function viewControl(): C\ViewControl\Factory
109  {
110  }
111  public function breadcrumbs(array $crumbs): C\Breadcrumbs\Breadcrumbs
112  {
113  }
114  public function chart(): C\Chart\Factory
115  {
116  }
117  public function input(): C\Input\Factory
118  {
119  }
120  public function table(): C\Table\Factory
121  {
122  }
123  public function messageBox(): C\MessageBox\Factory
124  {
125  }
126  public function layout(): C\Layout\Factory
127  {
128  }
129  public function mainControls(): C\MainControls\Factory
130  {
131  }
132  public function tree(): C\Tree\Factory
133  {
134  }
135  public function menu(): C\Menu\Factory
136  {
137  }
138  public function symbol(): C\Symbol\Factory
139  {
140  }
141  public function toast(): C\Toast\Factory
142  {
143  }
144  public function player(): C\Player\Factory
145  {
146  }
147  public function launcher(): C\Launcher\Factory
148  {
149  }
150  public function helpTopics(string ...$topic): array
151  {
152  }
153  public function entity(): C\Entity\Factory
154  {
155  }
156  public function prompt(): C\Prompt\Factory
157  {
158  }
159 }
160 
162 {
163  public $resources = array();
164 
165  public function register(string $name): void
166  {
167  $this->resources[] = $name;
168  }
169 }
170 
172 {
173  public array $requested = array();
174 
175  public function __construct()
176  {
177  }
178 
179  public function txt($a_topic, $a_default_lang_fallback_mod = ""): string
180  {
181  $this->requested[] = $a_topic;
182  return $a_topic;
183  }
184 
185  public function toJS($a_lang_key, ilGlobalTemplateInterface $a_tpl = null): void
186  {
187  }
188 
189  public string $lang_module = 'common';
190 
191  public function loadLanguageModule(string $a_module): void
192  {
193  }
194 
195  public function getLangKey(): string
196  {
197  return "en";
198  }
199 }
200 
202 {
203  public array $on_load_code = array();
204  public array $ids = array();
205  private int $count = 0;
206 
207  public function createId(): string
208  {
209  $this->count++;
210  $id = "id_" . $this->count;
211  $this->ids[] = $id;
212  return $id;
213  }
214 
215  public function addOnLoadCode($code): void
216  {
217  $this->on_load_code[] = $code;
218  }
219 
220  public function getOnLoadCodeAsync(): string
221  {
222  return "";
223  }
224 }
225 
227 {
228  protected array $with_stub_renderings = [];
229 
230  public function __construct(
231  Render\Loader $component_renderer_loader,
232  JavaScriptBinding $java_script_binding,
233  array $with_stub_renderings = [],
234  protected array $with_additional_contexts = [],
235  ) {
236  $this->with_stub_renderings = array_map(function ($component) {
237  return get_class($component);
238  }, $with_stub_renderings);
239 
240  array_walk($this->with_additional_contexts, fn(Component $c) => $this->pushContext($c));
241 
242  parent::__construct($component_renderer_loader, $java_script_binding);
243  }
244 
245  public function _getRendererFor(IComponent $component): Render\ComponentRenderer
246  {
247  return $this->getRendererFor($component);
248  }
249 
250  public function getRendererFor(IComponent $component): Render\ComponentRenderer
251  {
252  if (in_array(get_class($component), $this->with_stub_renderings)) {
253  return new TestDummyRenderer();
254  }
255  return parent::getRendererFor($component);
256  }
257 
258  public function _getContexts(): array
259  {
260  return $this->getContexts();
261  }
262 
263  public function getComponentCanonicalNameAttribute(IComponent $component): string
264  {
265  return str_replace(' ', '-', strtolower($component->getCanonicalName()));
266  }
267 }
268 
269 class TestDummyRenderer implements Render\ComponentRenderer
270 {
271  public function __construct()
272  {
273  }
274 
275  public function render(ILIAS\UI\Component\Component $component, ILIAS\UI\Renderer $default_renderer): string
276  {
277  return $component->getCanonicalName();
278  }
279 
280  public function registerResources(ResourceRegistry $registry): void
281  {
282  // TODO: Implement registerResources() method.
283  }
284 }
285 
287 {
288  private $manipulate = false;
289 
290  public function manipulate(): void
291  {
292  $this->manipulate = true;
293  }
294 
295  protected function manipulateRendering($component, Renderer $root): ?string
296  {
297  if ($this->manipulate) {
298  return "This content was manipulated";
299  } else {
300  return null;
301  }
302  }
303 }
304 
306 {
307  protected int $id = 0;
308 
309  protected function createId(): string
310  {
311  return 'signal_' . ++$this->id;
312  }
313 }
314 
316 {
317 }
318 
319 class DummyComponent implements IComponent
320 {
321  public function getCanonicalName(): string
322  {
323  return "DummyComponent";
324  }
325 }
326 
330 abstract class ILIAS_UI_TestBase extends TestCase
331 {
332  use BaseUITestTrait;
333 }
334 
335 trait BaseUITestTrait
336 {
337  public function getUIFactory(): NoUIFactory
338  {
339  return new NoUIFactory();
340  }
341 
342  public function getTemplateFactory(): ilIndependentTemplateFactory
343  {
344  return new ilIndependentTemplateFactory();
345  }
346 
347  public function getResourceRegistry(): LoggingRegistry
348  {
349  return new LoggingRegistry();
350  }
351 
352  public function getLanguage(): LanguageMock
353  {
354  return new LanguageMock();
355  }
356 
357  public function getJavaScriptBinding(): LoggingJavaScriptBinding
358  {
359  return new LoggingJavaScriptBinding();
360  }
361 
365  public function getRefinery()
366  {
367  return $this->getMockBuilder(\ILIAS\Refinery\Factory::class)
368  ->disableOriginalConstructor()
369  ->getMock();
370  }
371 
372  public function getImagePathResolver(): ilImagePathResolver
373  {
374  return new ilImagePathResolver();
375  }
376 
377  public function getDataFactory(): DataFactory
378  {
379  return $this->createMock(DataFactory::class);
380  }
381 
382  public function getHelpTextRetriever(): HelpTextRetriever
383  {
384  return new Help\TextRetriever\Echoing();
385  }
386 
387  public function getUploadLimitResolver(): UploadLimitResolver
388  {
389  return $this->createMock(UploadLimitResolver::class);
390  }
391 
396  public function getDefaultRenderer(
397  JavaScriptBinding $js_binding = null,
398  array $with_stub_renderings = [],
399  array $with_additional_contexts = [],
401  $ui_factory = $this->getUIFactory();
402  $tpl_factory = $this->getTemplateFactory();
403  $resource_registry = $this->getResourceRegistry();
404  $lng = $this->getLanguage();
405  if (!$js_binding) {
406  $js_binding = $this->getJavaScriptBinding();
407  }
408 
409  $image_path_resolver = $this->getImagePathResolver();
410  $data_factory = $this->getDataFactory();
411  $help_text_retriever = $this->getHelpTextRetriever();
412 
413  $component_renderer_loader = new Render\LoaderCachingWrapper(
415  $resource_registry,
416  new Render\FSLoader(
418  $ui_factory,
419  $tpl_factory,
420  $lng,
421  $js_binding,
422  $image_path_resolver,
423  $data_factory,
424  $help_text_retriever,
425  $this->getUploadLimitResolver()
426  ),
428  $ui_factory,
429  $tpl_factory,
430  $lng,
431  $js_binding,
432  $image_path_resolver,
433  $data_factory,
434  $help_text_retriever,
435  $this->getUploadLimitResolver()
436  ),
438  $ui_factory,
439  $tpl_factory,
440  $lng,
441  $js_binding,
442  $image_path_resolver,
443  $data_factory,
444  $help_text_retriever,
445  $this->getUploadLimitResolver()
446  ),
448  $ui_factory,
449  $tpl_factory,
450  $lng,
451  $js_binding,
452  $image_path_resolver,
453  $data_factory,
454  $help_text_retriever,
455  $this->getUploadLimitResolver()
456  ),
458  $ui_factory,
459  $tpl_factory,
460  $lng,
461  $js_binding,
462  $image_path_resolver,
463  $data_factory,
464  $help_text_retriever,
465  $this->getUploadLimitResolver()
466  )
467  )
468  )
469  );
470  return new TestDefaultRenderer($component_renderer_loader, $js_binding, $with_stub_renderings, $with_additional_contexts);
471  }
472 
473  public function getDecoratedRenderer(Renderer $default)
474  {
475  return new TestDecoratedRenderer($default);
476  }
477 
478  public function normalizeHTML(string $html): string
479  {
480  return trim(str_replace(["\n", "\r"], "", $html));
481  }
482 
483  public function assertHTMLEquals(string $expected_html_as_string, string $html_as_string): void
484  {
485  $html = new DOMDocument();
486  $html->formatOutput = true;
487  $html->preserveWhiteSpace = false;
488  $expected = new DOMDocument();
489  $expected->formatOutput = true;
490  $expected->preserveWhiteSpace = false;
491  $html->loadXML($this->normalizeHTML($html_as_string));
492  $expected->loadXML($this->normalizeHTML($expected_html_as_string));
493  $this->assertEquals($expected->saveHTML(), $html->saveHTML());
494  }
495 
500  protected function brutallyTrimHTML(string $html): string
501  {
502  $html = str_replace(["\n", "\r", "\t"], "", $html);
503  $html = preg_replace('# {2,}#', " ", $html);
504  $html = preg_replace('/<!--(.|\s)*?-->/', '', $html);
505  $html = preg_replace("/>(\s+)</", "><", $html);
506  $html = str_replace(" >", ">", $html);
507  $html = str_replace(" <", "<", $html);
508  return trim($html);
509  }
510 
515  protected function brutallyTrimSignals(string $html): string
516  {
517  $html = preg_replace('/il_signal_(\w+)/', "il_signal...", $html);
518  return $html;
519  }
520 }
Registry for resources required by rendered output like Javascript or CSS.
getRendererFor(IComponent $component)
Definition: Base.php:250
registerResources(ResourceRegistry $registry)
Definition: Base.php:280
card()
description: purpose: > A card is a flexible content container for small chunks of structured data...
Definition: Base.php:66
item()
description: purpose: > An item displays a unique entity within the system.
Definition: Base.php:105
breadcrumbs(array $crumbs)
description: purpose: > Breadcrumbs is a supplemental navigation scheme.
Definition: Base.php:111
dropzone()
description: purpose: > Dropzones are containers used to drop either files or other HTML elements...
Definition: Base.php:90
getLangKey()
Definition: Base.php:195
$resources
Definition: ltiservices.php:68
getComponentCanonicalNameAttribute(IComponent $component)
Definition: Base.php:263
__construct()
Definition: Base.php:175
getCanonicalName()
Get the canonical name of the component.
Definition: Base.php:321
mainControls()
description: purpose: > Main Controls are components that are always usable, depending only on overa...
Definition: Base.php:129
viewControl()
description: purpose: > View Controls switch between different visualisation of data.
Definition: Base.php:108
Loads renderers for components from the file system.
Definition: FSLoader.php:41
Interface Observer Contains several chained tasks and infos about them.
An entity that renders components to a string output.
link()
description: purpose: > Links are used navigate to other resources or views of the system by clickin...
Definition: Base.php:99
symbol()
description: purpose: > Symbols are graphical representations of concepts or contexts quickly compre...
Definition: Base.php:138
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Render\Loader $component_renderer_loader, JavaScriptBinding $java_script_binding, array $with_stub_renderings=[], protected array $with_additional_contexts=[],)
Definition: Base.php:230
legacy(string $content)
description: purpose: > This component is used to wrap an existing ILIAS UI element into a UI compon...
Definition: Base.php:78
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
prompt()
description: purpose: > A Prompt requires a user to make some inputs to the system, like making choices, acknowleding an important information or filling out a form.
Definition: Base.php:156
Registers resources for retreived renderers at a ResourceRegistry.
layout()
description: purpose: > Layout components are components used for the overall construction of the us...
Definition: Base.php:126
messageBox()
description: purpose: > Message Boxes inform the user about the state of the system or an ongoing us...
Definition: Base.php:123
$c
Definition: deliver.php:9
entity()
description: purpose: > An Entity displays information about entities within the system...
Definition: Base.php:153
deck(array $cards)
description: purpose: > Decks are used to display multiple Cards in a grid.
Definition: Base.php:69
toast()
description: purpose: Toasts are temporary messages from the system published to the user...
Definition: Base.php:141
getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template instance.
Definition: Base.php:52
$path
Definition: ltiservices.php:30
This describes a facility that the UI framework can use to retrieve some help text.
helpTopics(string ... $topic)
description: purpose: > Help Topics can be attached to certain components.
Definition: Base.php:150
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.
Definition: Base.php:220
player()
description: purpose: > The Player component is used to play and control a media source...
Definition: Base.php:144
getLanguage()
render(ILIAS\UI\Component\Component $component, ILIAS\UI\Renderer $default_renderer)
Definition: Base.php:275
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is how the factory for UI elements looks.
Definition: Factory.php:37
tree()
description: purpose: > Trees present hierarchically structured data.
Definition: Base.php:132
chart()
description: purpose: > Charts are used to graphically represent data in various forms such as maps...
Definition: Base.php:114
panel()
description: purpose: > Panels are used to group titled content.
Definition: Base.php:81
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
manipulateRendering($component, Renderer $root)
Definition: Base.php:295
toJS($a_lang_key, ilGlobalTemplateInterface $a_tpl=null)
Definition: Base.php:185
launcher()
description: purpose: > The Launcher starts an object, a process or a workflow.
Definition: Base.php:147
input()
description: purpose: > In opposite to components with a purely receptive or at most navigational ch...
Definition: Base.php:117
modal()
description: purpose: The Modal forces users to focus on the task at hand.
Definition: Base.php:84
Provides methods to interface with javascript.
dropdown()
description: purpose: > Dropdowns reveal a list of interactions that change the system’s status or ...
Definition: Base.php:102
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
menu()
description: purpose: > Menus let the user choose from several (navigational) options.
Definition: Base.php:135
image()
description: purpose: The Image component is used to display images of various sources.
Definition: Base.php:75
progress()
description: purpose: > A Progress component is designed to represent the users advancement within a...
Definition: Base.php:87
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
__construct(Container $dic, ilPlugin $plugin)
global $lng
Definition: privfeed.php:32
loadLanguageModule(string $a_module)
Definition: Base.php:191
listing()
description: purpose: > Listings are used to structure itemised textual information.
Definition: Base.php:72
txt($a_topic, $a_default_lang_fallback_mod="")
Definition: Base.php:179
_getRendererFor(IComponent $component)
Definition: Base.php:245
table()
description: purpose: > Tables present a set of uniformly structured data.
Definition: Base.php:120
createId()
Create a fresh unique id.
Definition: Base.php:207
button()
description: purpose: > Buttons trigger interactions that change the system’s or view&#39;s status...
Definition: Base.php:63
Loads renderers for components.
Definition: Loader.php:29
Interface for a factory that provides templates.
divider()
description: purpose: > A divider marks a thematic change in a sequence of other components...
Definition: Base.php:96
counter()
description: purpose: > Counter inform users about the quantity of items indicated by a glyph...
Definition: Base.php:60
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Purpose.php:21
popover()
description: purpose: > Popovers can be used when space is scarce i.e.
Definition: Base.php:93