ILIAS  release_8 Revision v8.23
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;
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 
53 class 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 
210  public function __construct(Render\Loader $component_renderer_loader, array $with_stub_renderings = [])
211  {
212  $this->with_stub_renderings = array_map(function ($component) {
213  return get_class($component);
214  }, $with_stub_renderings);
215  parent::__construct($component_renderer_loader);
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 
237 class TestDummyRenderer implements Render\ComponentRenderer
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 
287 class DummyComponent implements IComponent
288 {
289  public function getCanonicalName(): string
290  {
291  return "DummyComponent";
292  }
293 }
294 
298 abstract 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 }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Registry for resources required by rendered output like Javascript or CSS.
getRendererFor(IComponent $component)
Definition: Base.php:223
registerResources(ResourceRegistry $registry)
Definition: Base.php:248
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:61
loadLanguageModule(string $a_module)
Definition: Base.php:171
item()
description: purpose: > An item displays a unique entity within the system.
Definition: Base.php:97
breadcrumbs(array $crumbs)
description: purpose: > Breadcrumbs is a supplemental navigation scheme.
Definition: Base.php:103
dropzone()
description: purpose: > Dropzones are containers used to drop either files or other HTML elements...
Definition: Base.php:82
$resources
Definition: ltiservices.php:68
Class Factory.
getDecoratedRenderer(Renderer $default)
Definition: Base.php:417
getCanonicalName()
Get the canonical name of the component.
Definition: Base.php:289
mainControls()
description: purpose: > Main Controls are components that are always usable, depending only on overa...
Definition: Base.php:121
viewControl()
description: purpose: > View Controls switch between different visualisation of data.
Definition: Base.php:100
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$lng
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:91
symbol()
description: purpose: > Symbols are graphical representations of concepts or contexts quickly compre...
Definition: Base.php:130
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:73
getImagePathResolver()
Definition: Base.php:345
__construct(Render\Loader $component_renderer_loader, array $with_stub_renderings=[])
Definition: Base.php:210
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:118
messageBox()
description: purpose: > Message Boxes inform the user about the state of the system or an ongoing us...
Definition: Base.php:115
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
deck(array $cards)
description: purpose: > Decks are used to display multiple Cards in a grid.
Definition: Base.php:64
toast()
description: purpose: Toasts are temporary messages from the system published to the user...
Definition: Base.php:133
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template instance.
Definition: Base.php:47
$path
Definition: ltiservices.php:32
toJS($a_lang_key, ilGlobalTemplateInterface $a_tpl=null)
Definition: Base.php:165
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.
Definition: Base.php:200
getJavaScriptBinding()
Definition: Base.php:330
if($format !==null) $name
Definition: metadata.php:247
player()
description: purpose: > The Player component is used to play and control a media source...
Definition: Base.php:136
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...
Provides common functionality for UI tests.
Definition: Base.php:298
tree()
description: purpose: > Trees present hierarchically structured data.
Definition: Base.php:124
chart()
description: purpose: > Charts are used to graphically represent data in various forms such as maps...
Definition: Base.php:106
panel()
description: purpose: > Panels are used to group titled content.
Definition: Base.php:76
manipulateRendering($component, Renderer $root)
Definition: Base.php:263
input()
description: purpose: > In opposite to components with a purely receptive or at most navigational ch...
Definition: Base.php:109
modal()
description: purpose: The Modal forces users to focus on the task at hand.
Definition: Base.php:79
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:94
menu()
description: purpose: > Menus let the user choose from several (navigational) options.
Definition: Base.php:127
getTemplateFactory()
Definition: Base.php:315
image()
description: purpose: The Image component is used to display images of various sources.
Definition: Base.php:70
__construct(Container $dic, ilPlugin $plugin)
getResourceRegistry()
Definition: Base.php:320
listing()
description: purpose: > Listings are used to structure itemised textual information.
Definition: Base.php:67
$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:459
_getRendererFor(IComponent $component)
Definition: Base.php:218
table()
description: purpose: > Tables present a set of uniformly structured data.
Definition: Base.php:112
normalizeHTML(string $html)
Definition: Base.php:422
createId()
Create a fresh unique id.
Definition: Base.php:187
button()
description: purpose: > Buttons trigger interactions that change the system’s or view&#39;s status...
Definition: Base.php:58
Loads renderers for components.
Definition: Loader.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt($a_topic, $a_default_lang_fallback_mod="")
Definition: Base.php:159
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:88
counter()
description: purpose: > Counter inform users about the quantity of items indicated by a glyph...
Definition: Base.php:55
popover()
description: purpose: > Popovers can be used when space is scarce i.e.
Definition: Base.php:85
Refinery Factory $refinery