ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
Base.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once("libs/composer/vendor/autoload.php");
6 
7 require_once(__DIR__ . "/Renderer/ilIndependentTemplate.php");
8 require_once(__DIR__ . "/../../Services/Language/classes/class.ilLanguage.php");
9 
10 use ILIAS\UI\Component as C;
12 use ILIAS\UI\Implementaiton\Component as I;
26 
28 {
29  public function getTemplate($path, $purge_unfilled_vars, $purge_unused_blocks)
30  {
31  return new ilIndependentGlobalTemplate($path, $purge_unfilled_vars, $purge_unused_blocks);
32  }
33 }
34 
35 class NoUIFactory implements Factory
36 {
37  public function counter()
38  {
39  }
40  public function button()
41  {
42  }
43  public function card()
44  {
45  }
46  public function deck(array $cards)
47  {
48  }
49  public function listing()
50  {
51  }
52  public function image()
53  {
54  }
55  public function legacy($content)
56  {
57  }
58  public function panel()
59  {
60  }
61  public function modal()
62  {
63  }
64  public function dropzone()
65  {
66  }
67  public function popover()
68  {
69  }
70  public function divider()
71  {
72  }
73  public function link()
74  {
75  }
76  public function dropdown()
77  {
78  }
79  public function item()
80  {
81  }
82  public function viewControl()
83  {
84  }
85  public function breadcrumbs(array $crumbs)
86  {
87  }
88  public function chart()
89  {
90  }
91  public function input()
92  {
93  }
94  public function table()
95  {
96  }
97  public function messageBox()
98  {
99  }
100  public function layout() : C\Layout\Factory
101  {
102  }
103  public function mainControls() : C\MainControls\Factory
104  {
105  }
106  public function tree()
107  {
108  }
109  public function menu() : C\Menu\Factory
110  {
111  }
112  public function symbol() : C\Symbol\Factory
113  {
114  }
115 }
116 
118 {
119  public $resources = array();
120 
121  public function register($name)
122  {
123  $this->resources[] = $name;
124  }
125 }
126 
128 {
129  public $requested = array();
130  public function __construct()
131  {
132  }
133  public function txt($a_topic, $a_default_lang_fallback_mod = "")
134  {
135  $this->requested[] = $a_topic;
136  return $a_topic;
137  }
138  public function toJS($a_lang_key, ilGlobalTemplateInterface $a_tpl = null)
139  {
140  }
141  public $lang_module = 'common';
142  public function loadLanguageModule($lang_module)
143  {
144  }
145 
146  public function getLangKey()
147  {
148  return "en";
149  }
150 }
151 
153 {
154  private $count = 0;
155  public $ids = array();
156  public function createId()
157  {
158  $this->count++;
159  $id = "id_" . $this->count;
160  $this->ids[] = $id;
161  return $id;
162  }
163  public $on_load_code = array();
164  public function addOnLoadCode($code)
165  {
166  $this->on_load_code[] = $code;
167  }
168  public function getOnLoadCodeAsync()
169  {
170  }
171 }
172 
174 {
178  protected $with_stub_renderings = [];
179 
180  public function __construct(Render\Loader $component_renderer_loader, $with_stub_renderings = [])
181  {
182  $this->with_stub_renderings = array_map(function ($component) {
183  return get_class($component);
184  }, $with_stub_renderings);
185  parent::__construct($component_renderer_loader);
186  }
187 
188  public function _getRendererFor(IComponent $component)
189  {
190  return $this->getRendererFor($component);
191  }
192 
193  public function getRendererFor(IComponent $component)
194  {
195  if (in_array(get_class($component), $this->with_stub_renderings)) {
196  return new TestDummyRenderer();
197  }
198  return parent::getRendererFor($component);
199  }
200 
201  public function _getContexts()
202  {
203  return $this->getContexts();
204  }
205 }
206 
208 {
209  public function __construct()
210  {
211  }
212  public function render($component, ?Renderer $root = null)
213  {
214  return $component->getCanonicalName();
215  }
216 }
217 
219 {
220  private $manipulate = false;
221 
222  public function manipulate() : void
223  {
224  $this->manipulate = true;
225  }
226 
227  protected function manipulateRendering($component, Renderer $root) : ?string
228  {
229  if ($this->manipulate) {
230  return "This content was manipulated";
231  } else {
232  return null;
233  }
234  }
235 }
236 
238 {
239  protected $id = 0;
240 
241  protected function createId()
242  {
243  return 'signal_' . ++$this->id;
244  }
245 }
246 
248 {
249 }
250 
251 class DummyComponent implements IComponent
252 {
253  public function getCanonicalName()
254  {
255  return "DummyComponent";
256  }
257 }
258 
262 abstract class ILIAS_UI_TestBase extends TestCase
263 {
264  public function setUp() : void
265  {
266  assert_options(ASSERT_WARNING, 0);
267  }
268 
269  public function tearDown() : void
270  {
271  assert_options(ASSERT_WARNING, 1);
272  }
273 
274  public function getUIFactory()
275  {
276  return new NoUIFactory();
277  }
278 
279  public function getTemplateFactory()
280  {
281  return new ilIndependentTemplateFactory();
282  }
283 
284  public function getResourceRegistry()
285  {
286  return new LoggingRegistry();
287  }
288 
289  public function getLanguage()
290  {
291  return new ilLanguageMock();
292  }
293 
294  public function getJavaScriptBinding()
295  {
296  return new LoggingJavaScriptBinding();
297  }
298 
299  public function getRefinery()
300  {
301  return $this->getMockBuilder(\ILIAS\Refinery\Factory::class)
302  ->disableOriginalConstructor()
303  ->getMock();
304  }
305 
306  public function getImagePathResolver()
307  {
308  return new ilImagePathResolver();
309  }
310 
311  public function getDefaultRenderer(JavaScriptBinding $js_binding = null, $with_stub_renderings = [])
312  {
313  $ui_factory = $this->getUIFactory();
314  $tpl_factory = $this->getTemplateFactory();
315  $resource_registry = $this->getResourceRegistry();
316  $lng = $this->getLanguage();
317  if (!$js_binding) {
318  $js_binding = $this->getJavaScriptBinding();
319  }
320 
321  $refinery = $this->getRefinery();
322  $image_path_resolver = $this->getImagePathResolver();
323 
324  $component_renderer_loader = new Render\LoaderCachingWrapper(
326  $resource_registry,
327  new Render\FSLoader(
329  $ui_factory,
330  $tpl_factory,
331  $lng,
332  $js_binding,
333  $refinery,
334  $image_path_resolver
335  ),
337  $ui_factory,
338  $tpl_factory,
339  $lng,
340  $js_binding,
341  $refinery,
342  $image_path_resolver
343  ),
345  $ui_factory,
346  $tpl_factory,
347  $lng,
348  $js_binding,
349  $refinery,
350  $image_path_resolver
351  )
352  )
353  )
354  );
355  return new TestDefaultRenderer($component_renderer_loader, $with_stub_renderings);
356  }
357 
358  public function getDecoratedRenderer(Renderer $default)
359  {
360  return new TestDecoratedRenderer($default);
361  }
362 
363  public function normalizeHTML($html)
364  {
365  return trim(str_replace(["\n", "\r"], "", $html));
366  }
367 
372  public function assertHTMLEquals($expected_html_as_string, $html_as_string)
373  {
374  $html = new DOMDocument();
375  $html->formatOutput = true;
376  $html->preserveWhiteSpace = false;
377  $expected = new DOMDocument();
378  $expected->formatOutput = true;
379  $expected->preserveWhiteSpace = false;
380  $html->loadXML($this->normalizeHTML($html_as_string));
381  $expected->loadXML($this->normalizeHTML($expected_html_as_string));
382  $this->assertEquals($expected->saveHTML(), $html->saveHTML());
383  }
384 
392  protected function brutallyTrimHTML($html)
393  {
394  $html = str_replace(["\n", "\r", "\t"], "", $html);
395  $html = preg_replace('# {2,}#', " ", $html);
396  $html = preg_replace('/<!--(.|\s)*?-->/', '', $html);
397  $html = preg_replace("/>(\s+)</", "><", $html);
398  $html = str_replace(" >", ">", $html);
399  $html = str_replace(" <", "<", $html);
400  return trim($html);
401  }
402 }
Registry for resources required by rendered output like Javascript or CSS.
getRendererFor(IComponent $component)
Definition: Base.php:193
An entity that renders components to a string output.
Definition: Renderer.php:14
card()
description: purpose: > A card is a flexible content container for small chunks of structured data...
Definition: Base.php:43
item()
description: purpose: > An item displays a unique entity within the system.
Definition: Base.php:79
breadcrumbs(array $crumbs)
description: purpose: > Breadcrumbs is a supplemental navigation scheme.
Definition: Base.php:85
dropzone()
description: purpose: > Dropzones are containers used to drop either files or other HTML elements...
Definition: Base.php:64
getDecoratedRenderer(Renderer $default)
Definition: Base.php:358
getCanonicalName()
Get the canonical name of the component.
Definition: Base.php:253
mainControls()
description: purpose: > Main Controls are components that are always usable, depending only on overa...
Definition: Base.php:103
viewControl()
description: purpose: > View Controls switch between different visualisation of data.
Definition: Base.php:82
Loads renderers for components from the file system.
Definition: FSLoader.php:20
Class ChatMainBarProvider .
link()
description: purpose: > Links are used navigate to other resources or views of the system by clickin...
Definition: Base.php:73
symbol()
description: purpose: > Symbols are graphical representations of concepts or contexts quickly compre...
Definition: Base.php:112
getImagePathResolver()
Definition: Base.php:306
Registers resources for retreived renderers at a ResourceRegistry.
layout()
description: purpose: > Layout components are compontents used for the overall construction of the u...
Definition: Base.php:100
messageBox()
description: purpose: > Message Boxes inform the user about the state of the system or an ongoing us...
Definition: Base.php:97
normalizeHTML($html)
Definition: Base.php:363
deck(array $cards)
description: purpose: > Decks are used to display multiple Cards in a grid.
Definition: Base.php:46
toJS($a_lang_key, ilGlobalTemplateInterface $a_tpl=null)
Definition: Base.php:138
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.
Definition: Base.php:168
getJavaScriptBinding()
Definition: Base.php:294
if($format !==null) $name
Definition: metadata.php:230
Provides common functionality for UI tests.
Definition: Base.php:262
$lng
This is how the factory for UI elements looks.
Definition: Factory.php:17
tree()
description: purpose: > Trees present hierarchically structured data.
Definition: Base.php:106
chart()
description: purpose: > Charts are used to graphically represent data in various forms such as maps...
Definition: Base.php:88
panel()
description: purpose: > Panels are used to group titled content.
Definition: Base.php:58
manipulateRendering($component, Renderer $root)
Definition: Base.php:227
render($component, ?Renderer $root=null)
Render given component.
Definition: Base.php:212
legacy($content)
description: purpose: > This component is used to wrap an existing ILIAS UI element into a UI compon...
Definition: Base.php:55
input()
description: purpose: > In opposite to components with a purely receptive or at most navigational ch...
Definition: Base.php:91
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
modal()
description: purpose: The Modal forces users to focus on the task at hand.
Definition: Base.php:61
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:76
menu()
description: purpose: > Menus let the user choose from several (navigational) options.
Definition: Base.php:109
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
getTemplateFactory()
Definition: Base.php:279
image()
description: purpose: The Image component is used to display images of various sources.
Definition: Base.php:52
addOnLoadCode($code)
Add some JavaScript-statements to the on-load handler of the page.
Definition: Base.php:164
getTemplate($path, $purge_unfilled_vars, $purge_unused_blocks)
Get template instance.
Definition: Base.php:29
__construct(Container $dic, ilPlugin $plugin)
getResourceRegistry()
Definition: Base.php:284
listing()
description: purpose: > Listings are used to structure itemised textual information.
Definition: Base.php:49
_getRendererFor(IComponent $component)
Definition: Base.php:188
language handling
table()
description: purpose: > Tables present a set of uniformly structured data.
Definition: Base.php:94
createId()
Create a fresh unique id.
Definition: Base.php:156
button()
description: purpose: > Buttons trigger interactions that change the system’s or view&#39;s status...
Definition: Base.php:40
Loads renderers for components.
Definition: Loader.php:12
txt($a_topic, $a_default_lang_fallback_mod="")
Definition: Base.php:133
loadLanguageModule($lang_module)
Definition: Base.php:142
Interface for a factory that provides templates.
__construct(Render\Loader $component_renderer_loader, $with_stub_renderings=[])
Definition: Base.php:180
divider()
description: purpose: > A divider marks a thematic change in a sequence of other components...
Definition: Base.php:70
counter()
description: purpose: > Counter inform users about the quantity of items indicated by a glyph...
Definition: Base.php:37
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
popover()
description: purpose: > Popovers can be used when space is scarce i.e.
Definition: Base.php:67