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