ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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;
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 FactoryInternal
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 }
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  \ILIAS\Language\Language $language,
234  array $with_stub_renderings = [],
235  protected array $with_additional_contexts = [],
236  ) {
237  $this->with_stub_renderings = array_map(function ($component) {
238  return get_class($component);
239  }, $with_stub_renderings);
240 
241  array_walk($this->with_additional_contexts, fn(Component $c) => $this->pushContext($c));
242 
243  parent::__construct($component_renderer_loader, $java_script_binding, $language);
244  }
245 
246  public function _getRendererFor(IComponent $component): Render\ComponentRenderer
247  {
248  return $this->getRendererFor($component);
249  }
250 
251  public function getRendererFor(IComponent $component): Render\ComponentRenderer
252  {
253  if (in_array(get_class($component), $this->with_stub_renderings)) {
254  return new TestDummyRenderer();
255  }
256  return parent::getRendererFor($component);
257  }
258 
259  public function _getContexts(): array
260  {
261  return $this->getContexts();
262  }
263 
264  public function getComponentCanonicalNameAttribute(IComponent $component): string
265  {
266  return str_replace(' ', '-', strtolower($component->getCanonicalName()));
267  }
268 }
269 
270 class TestDummyRenderer implements Render\ComponentRenderer
271 {
272  public function __construct()
273  {
274  }
275 
276  public function render(ILIAS\UI\Component\Component $component, ILIAS\UI\Renderer $default_renderer): string
277  {
278  return $component->getCanonicalName();
279  }
280 
281  public function registerResources(ResourceRegistry $registry): void
282  {
283  // TODO: Implement registerResources() method.
284  }
285 }
286 
288 {
289  private $manipulate = false;
290 
291  public function manipulate(): void
292  {
293  $this->manipulate = true;
294  }
295 
296  protected function manipulateRendering($component, Renderer $root): ?string
297  {
298  if ($this->manipulate) {
299  return "This content was manipulated";
300  } else {
301  return null;
302  }
303  }
304 }
305 
307 {
308  protected int $id = 0;
309 
310  protected function createId(): string
311  {
312  return 'signal_' . ++$this->id;
313  }
314 }
315 
317 {
318 }
319 
320 class DummyComponent implements IComponent
321 {
322  use ComponentHelper;
323 
324  public function getCanonicalName(): string
325  {
326  return "DummyComponent";
327  }
328 }
329 
333 abstract class ILIAS_UI_TestBase extends TestCase
334 {
335  use BaseUITestTrait;
336 }
337 
338 trait BaseUITestTrait
339 {
340  public function getUIFactory(): NoUIFactory
341  {
342  return new NoUIFactory();
343  }
344 
345  public function getTemplateFactory(): ilIndependentTemplateFactory
346  {
347  return new ilIndependentTemplateFactory();
348  }
349 
350  public function getResourceRegistry(): LoggingRegistry
351  {
352  return new LoggingRegistry();
353  }
354 
355  public function getLanguage(): LanguageMock
356  {
357  return new LanguageMock();
358  }
359 
360  public function getJavaScriptBinding(): LoggingJavaScriptBinding
361  {
362  return new LoggingJavaScriptBinding();
363  }
364 
368  public function getRefinery()
369  {
370  return $this->getMockBuilder(\ILIAS\Refinery\Factory::class)
371  ->disableOriginalConstructor()
372  ->getMock();
373  }
374 
375  public function getImagePathResolver(): ilImagePathResolver
376  {
377  return new ilImagePathResolver();
378  }
379 
380  public function getDataFactory(): DataFactory
381  {
382  return $this->createMock(DataFactory::class);
383  }
384 
385  public function getHelpTextRetriever(): HelpTextRetriever
386  {
387  return new Help\TextRetriever\Echoing();
388  }
389 
390  public function getUploadLimitResolver(): UploadLimitResolver
391  {
392  return $this->createMock(UploadLimitResolver::class);
393  }
394 
399  public function getDefaultRenderer(
400  ?JavaScriptBinding $js_binding = null,
401  array $with_stub_renderings = [],
402  array $with_additional_contexts = [],
404  $ui_factory = $this->getUIFactory();
405  $tpl_factory = $this->getTemplateFactory();
406  $resource_registry = $this->getResourceRegistry();
407  $lng = $this->getLanguage();
408  if (!$js_binding) {
409  $js_binding = $this->getJavaScriptBinding();
410  }
411 
412  $image_path_resolver = $this->getImagePathResolver();
413  $data_factory = $this->getDataFactory();
414  $help_text_retriever = $this->getHelpTextRetriever();
415 
416  $component_renderer_loader = new Render\LoaderCachingWrapper(
418  $resource_registry,
419  new Render\FSLoader(
421  $ui_factory,
422  $tpl_factory,
423  $lng,
424  $js_binding,
425  $image_path_resolver,
426  $data_factory,
427  $help_text_retriever,
428  $this->getUploadLimitResolver()
429  ),
431  $ui_factory,
432  $tpl_factory,
433  $lng,
434  $js_binding,
435  $image_path_resolver,
436  $data_factory,
437  $help_text_retriever,
438  $this->getUploadLimitResolver()
439  ),
441  $ui_factory,
442  $tpl_factory,
443  $lng,
444  $js_binding,
445  $image_path_resolver,
446  $data_factory,
447  $help_text_retriever,
448  $this->getUploadLimitResolver()
449  ),
451  $ui_factory,
452  $tpl_factory,
453  $lng,
454  $js_binding,
455  $image_path_resolver,
456  $data_factory,
457  $help_text_retriever,
458  $this->getUploadLimitResolver()
459  ),
461  $ui_factory,
462  $tpl_factory,
463  $lng,
464  $js_binding,
465  $image_path_resolver,
466  $data_factory,
467  $help_text_retriever,
468  $this->getUploadLimitResolver()
469  ),
470  new I\Menu\MenuRendererFactory(
471  $ui_factory,
472  $tpl_factory,
473  $lng,
474  $js_binding,
475  $image_path_resolver,
476  $data_factory,
477  $help_text_retriever,
478  $this->getUploadLimitResolver(),
479  )
480  )
481  )
482  );
483  return new TestDefaultRenderer($component_renderer_loader, $js_binding, $lng, $with_stub_renderings, $with_additional_contexts);
484  }
485 
486  public function getDecoratedRenderer(Renderer $default)
487  {
488  return new TestDecoratedRenderer($default);
489  }
490 
491  public function normalizeHTML(string $html): string
492  {
493  return trim(str_replace(["\n", "\r"], "", $html));
494  }
495 
501  public function assertHTMLEquals(string $expected_html_as_string, string $html_as_string): void
502  {
503  $html = new DOMDocument();
504  $html->formatOutput = true;
505  $html->preserveWhiteSpace = false;
506  $expected = new DOMDocument();
507  $expected->formatOutput = true;
508  $expected->preserveWhiteSpace = false;
509  $html->loadXML($this->normalizeHTML($html_as_string));
510  $expected->loadXML($this->normalizeHTML($expected_html_as_string));
511  $this->assertEquals($expected->saveHTML(), $html->saveHTML());
512  }
513 
518  protected function brutallyTrimHTML(string $html): string
519  {
520  $html = str_replace(["\n", "\r", "\t"], "", $html);
521  $html = preg_replace('# {2,}#', " ", $html);
522  $html = preg_replace('/<!--(.|\s)*?-->/', '', $html);
523  $html = preg_replace("/>(\s+)</", "><", $html);
524  $html = str_replace(" >", ">", $html);
525  $html = str_replace(" <", "<", $html);
526  return trim($html);
527  }
528 
533  protected function brutallyTrimSignals(string $html): string
534  {
535  $html = preg_replace('/il_signal_(\w+)/', "il_signal...", $html);
536  return $html;
537  }
538 }
Registry for resources required by rendered output like Javascript or CSS.
getRendererFor(IComponent $component)
Definition: Base.php:251
registerResources(ResourceRegistry $registry)
Definition: Base.php:281
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:65
getComponentCanonicalNameAttribute(IComponent $component)
Definition: Base.php:264
__construct()
Definition: Base.php:175
getCanonicalName()
Get the canonical name of the component.
Definition: Base.php:324
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:42
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
__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:230
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
legacy()
description: purpose: > legacy components are used as provisional elements in the UI framework while...
Definition: Base.php:78
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:25
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:29
This describes a facility that the UI framework can use to retrieve some help text.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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:276
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:296
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
toJS($a_lang_key, ?ilGlobalTemplateInterface $a_tpl=null)
Definition: Base.php:185
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:23
__construct(Container $dic, ilPlugin $plugin)
global $lng
Definition: privfeed.php:31
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:246
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
popover()
description: purpose: > Popovers can be used when space is scarce i.e.
Definition: Base.php:93