ILIAS  release_7 Revision v7.30-3-g800a261c036
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
5require_once("libs/composer/vendor/autoload.php");
6
7require_once(__DIR__ . "/Renderer/ilIndependentTemplate.php");
8require_once(__DIR__ . "/../../Services/Language/classes/class.ilLanguage.php");
9
11use ILIAS\UI\Component\Component as IComponent;
12use ILIAS\UI\Implementaiton\Component as I;
19use ILIAS\UI\Implementation\ComponentRendererFSLoader;
25use PHPUnit\Framework\TestCase;
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
35class 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';
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
181 {
182 $this->with_stub_renderings = array_map(function ($component) {
183 return get_class($component);
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
251class DummyComponent implements IComponent
252{
253 public function getCanonicalName()
254 {
255 return "DummyComponent";
256 }
257}
258
262abstract 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}
An exception for terminatinating execution or to throw for unit testing.
getCanonicalName()
Get the canonical name of the component.
Definition: Base.php:253
Renderer that dispatches rendering of UI components to a Renderer found in the same namespace as the ...
getContexts()
Get the contexts that are added via withAdditionalContext where most recently added contexts come las...
Loads renderers for components from the file system.
Definition: FSLoader.php:21
Caches renderers loaded by another loader.
Registers resources for retreived renderers at a ResourceRegistry.
Provides common functionality for UI tests.
Definition: Base.php:263
getJavaScriptBinding()
Definition: Base.php:294
getImagePathResolver()
Definition: Base.php:306
getDecoratedRenderer(Renderer $default)
Definition: Base.php:358
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
getTemplateFactory()
Definition: Base.php:279
getResourceRegistry()
Definition: Base.php:284
normalizeHTML($html)
Definition: Base.php:363
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
createId()
Create a fresh unique id.
Definition: Base.php:156
addOnLoadCode($code)
Add some JavaScript-statements to the on-load handler of the page.
Definition: Base.php:164
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.
Definition: Base.php:168
card()
Definition: Base.php:43
image()
Definition: Base.php:52
dropzone()
Definition: Base.php:64
listing()
Definition: Base.php:49
symbol()
Definition: Base.php:112
panel()
Definition: Base.php:58
link()
Definition: Base.php:73
item()
Definition: Base.php:79
modal()
Definition: Base.php:61
chart()
Definition: Base.php:88
deck(array $cards)
Definition: Base.php:46
divider()
Definition: Base.php:70
counter()
Definition: Base.php:37
button()
Definition: Base.php:40
dropdown()
Definition: Base.php:76
legacy($content)
Definition: Base.php:55
popover()
Definition: Base.php:67
messageBox()
Definition: Base.php:97
input()
Definition: Base.php:91
viewControl()
Definition: Base.php:82
table()
Definition: Base.php:94
breadcrumbs(array $crumbs)
Definition: Base.php:85
layout()
Definition: Base.php:100
mainControls()
Definition: Base.php:103
manipulateRendering($component, Renderer $root)
Manipulates the rendering of one or multiple components by appending, prepending or exchanging their ...
Definition: Base.php:227
_getRendererFor(IComponent $component)
Definition: Base.php:188
getRendererFor(IComponent $component)
Definition: Base.php:193
__construct(Render\Loader $component_renderer_loader, $with_stub_renderings=[])
Definition: Base.php:180
render($component, ?Renderer $root=null)
Render given component.If an array of components is passed, this method returns a concatenated output...
Definition: Base.php:212
getTemplate($path, $purge_unfilled_vars, $purge_unused_blocks)
Get template instance.
Definition: Base.php:29
toJS($a_lang_key, ilGlobalTemplateInterface $a_tpl=null)
Definition: Base.php:138
txt($a_topic, $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Definition: Base.php:133
loadLanguageModule($lang_module)
Definition: Base.php:142
language handling
A component is the most general form of an entity in the UI.
Definition: Component.php:14
This is how the factory for UI elements looks.
Definition: Factory.php:18
Provides methods to interface with javascript.
Loads renderers for components.
Definition: Loader.php:13
Registry for resources required by rendered output like Javascript or CSS.
Interface for a factory that provides templates.
An entity that renders components to a string output.
Definition: Renderer.php:15
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
$lng