ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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;
44 use ILIAS\UI\Help;
48 
50 {
51  public function getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks): Render\Template
52  {
53  return new ilIndependentGlobalTemplate($path, $purge_unfilled_vars, $purge_unused_blocks);
54  }
55 }
56 
57 class NoUIFactory implements FactoryInternal
58 {
59  public function counter(): I\Counter\Factory
60  {
61  }
62  public function button(): I\Button\Factory
63  {
64  }
65  public function card(): I\Card\Factory
66  {
67  }
68  public function deck(array $cards): I\Deck\Deck
69  {
70  }
71  public function listing(): I\Listing\Factory
72  {
73  }
74  public function image(): I\Image\Factory
75  {
76  }
77  public function legacy(): I\Legacy\Factory
78  {
79  }
80  public function panel(): I\Panel\Factory
81  {
82  }
83  public function modal(): I\Modal\Factory
84  {
85  }
86  public function progress(): I\Progress\Factory
87  {
88  }
89  public function dropzone(): I\Dropzone\Factory
90  {
91  }
92  public function popover(): I\Popover\Factory
93  {
94  }
95  public function divider(): I\Divider\Factory
96  {
97  }
98  public function link(): I\Link\Factory
99  {
100  }
101  public function dropdown(): I\Dropdown\Factory
102  {
103  }
104  public function item(): I\Item\Factory
105  {
106  }
107  public function viewControl(): I\ViewControl\Factory
108  {
109  }
110  public function breadcrumbs(array $crumbs): I\Breadcrumbs\Breadcrumbs
111  {
112  }
113  public function chart(): I\Chart\Factory
114  {
115  }
116  public function input(): I\Input\Factory
117  {
118  }
119  public function table(): I\Table\Factory
120  {
121  }
122  public function messageBox(): I\MessageBox\Factory
123  {
124  }
125  public function layout(): I\Layout\Factory
126  {
127  }
128  public function mainControls(): I\MainControls\Factory
129  {
130  }
131  public function tree(): I\Tree\Factory
132  {
133  }
134  public function menu(): I\Menu\Factory
135  {
136  }
137  public function symbol(): I\Symbol\Factory
138  {
139  }
140  public function toast(): I\Toast\Factory
141  {
142  }
143  public function player(): I\Player\Factory
144  {
145  }
146  public function launcher(): I\Launcher\Factory
147  {
148  }
149  public function helpTopics(string ...$topic): array
150  {
151  }
152  public function entity(): I\Entity\Factory
153  {
154  }
155  public function prompt(): I\Prompt\Factory
156  {
157  }
158 }
159 
161 {
162  public $resources = array();
163 
164  public function register(string $name): void
165  {
166  $this->resources[] = $name;
167  }
168 }
169 
171 {
172  public array $requested = array();
173 
174  public function __construct()
175  {
176  }
177 
178  public function txt($a_topic, $a_default_lang_fallback_mod = ""): string
179  {
180  $this->requested[] = $a_topic;
181  return $a_topic;
182  }
183 
184  public function toJS($a_lang_key, ?ilGlobalTemplateInterface $a_tpl = null): void
185  {
186  }
187 
188  public string $lang_module = 'common';
189 
190  public function loadLanguageModule(string $a_module): void
191  {
192  }
193 
194  public function getLangKey(): string
195  {
196  return "en";
197  }
198 }
199 
201 {
202  public array $on_load_code = array();
203  public array $ids = array();
204  private int $count = 0;
205 
206  public function createId(): string
207  {
208  $this->count++;
209  $id = "id_" . $this->count;
210  $this->ids[] = $id;
211  return $id;
212  }
213 
214  public function addOnLoadCode($code): void
215  {
216  $this->on_load_code[] = $code;
217  }
218 
219  public function getOnLoadCodeAsync(): string
220  {
221  return "";
222  }
223 }
224 
226 {
227  protected array $with_stub_renderings = [];
228 
229  public function __construct(
230  Render\Loader $component_renderer_loader,
231  JavaScriptBinding $java_script_binding,
232  \ILIAS\Language\Language $language,
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, $language);
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, $lng, $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:65
item()
description: purpose: > An item displays a unique entity within the system.
Definition: Base.php:104
breadcrumbs(array $crumbs)
description: purpose: > Breadcrumbs is a supplemental navigation scheme.
Definition: Base.php:110
dropzone()
description: purpose: > Dropzones are containers used to drop either files or other HTML elements...
Definition: Base.php:89
getLangKey()
Definition: Base.php:194
$resources
Definition: ltiservices.php:65
getComponentCanonicalNameAttribute(IComponent $component)
Definition: Base.php:263
__construct()
Definition: Base.php:174
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:128
viewControl()
description: purpose: > View Controls switch between different visualisation of data.
Definition: Base.php:107
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:98
symbol()
description: purpose: > Symbols are graphical representations of concepts or contexts quickly compre...
Definition: Base.php:137
__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:229
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:77
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:155
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:125
messageBox()
description: purpose: > Message Boxes inform the user about the state of the system or an ongoing us...
Definition: Base.php:122
$c
Definition: deliver.php:25
entity()
description: purpose: > An Entity displays information about entities within the system...
Definition: Base.php:152
deck(array $cards)
description: purpose: > Decks are used to display multiple Cards in a grid.
Definition: Base.php:68
toast()
description: purpose: Toasts are temporary messages from the system published to the user...
Definition: Base.php:140
getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template instance.
Definition: Base.php:51
$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:149
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.
Definition: Base.php:219
player()
description: purpose: > The Player component is used to play and control a media source...
Definition: Base.php:143
getLanguage()
render(ILIAS\UI\Component\Component $component, ILIAS\UI\Renderer $default_renderer)
Definition: Base.php:275
tree()
description: purpose: > Trees present hierarchically structured data.
Definition: Base.php:131
chart()
description: purpose: > Charts are used to graphically represent data in various forms such as maps...
Definition: Base.php:113
panel()
description: purpose: > Panels are used to group titled content.
Definition: Base.php:80
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
launcher()
description: purpose: > The Launcher starts an object, a process or a workflow.
Definition: Base.php:146
input()
description: purpose: > In opposite to components with a purely receptive or at most navigational ch...
Definition: Base.php:116
modal()
description: purpose: The Modal forces users to focus on the task at hand.
Definition: Base.php:83
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:101
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:134
toJS($a_lang_key, ?ilGlobalTemplateInterface $a_tpl=null)
Definition: Base.php:184
image()
description: purpose: The Image component is used to display images of various sources.
Definition: Base.php:74
progress()
description: purpose: > A Progress component is designed to represent the users advancement within a...
Definition: Base.php:86
$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:190
listing()
description: purpose: > Listings are used to structure itemised textual information.
Definition: Base.php:71
txt($a_topic, $a_default_lang_fallback_mod="")
Definition: Base.php:178
_getRendererFor(IComponent $component)
Definition: Base.php:245
table()
description: purpose: > Tables present a set of uniformly structured data.
Definition: Base.php:119
createId()
Create a fresh unique id.
Definition: Base.php:206
button()
description: purpose: > Buttons trigger interactions that change the system’s or view&#39;s status...
Definition: Base.php:62
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:95
counter()
description: purpose: > Counter inform users about the quantity of items indicated by a glyph...
Definition: Base.php:59
popover()
description: purpose: > Popovers can be used when space is scarce i.e.
Definition: Base.php:92