ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
148{
149 private $count = 0;
150 public $ids = array();
151 public function createId()
152 {
153 $this->count++;
154 $id = "id_" . $this->count;
155 $this->ids[] = $id;
156 return $id;
157 }
158 public $on_load_code = array();
159 public function addOnLoadCode($code)
160 {
161 $this->on_load_code[] = $code;
162 }
163 public function getOnLoadCodeAsync()
164 {
165 }
166}
167
169{
170 public function _getRendererFor(IComponent $component)
171 {
172 return $this->getRendererFor($component);
173 }
174 public function _getContexts()
175 {
176 return $this->getContexts();
177 }
178}
179
181{
182 private $manipulate = false;
183
184 public function manipulate() : void
185 {
186 $this->manipulate = true;
187 }
188
189 protected function manipulateRendering($component, Renderer $root) : ?string
190 {
191 if ($this->manipulate) {
192 return "This content was manipulated";
193 } else {
194 return null;
195 }
196 }
197}
198
200{
201 protected $id = 0;
202
203 protected function createId()
204 {
205 return 'signal_' . ++$this->id;
206 }
207}
208
210{
211}
212
213class DummyComponent implements IComponent
214{
215 public function getCanonicalName()
216 {
217 return "DummyComponent";
218 }
219}
220
224abstract class ILIAS_UI_TestBase extends TestCase
225{
226 public function setUp() : void
227 {
228 assert_options(ASSERT_WARNING, 0);
229 }
230
231 public function tearDown() : void
232 {
233 assert_options(ASSERT_WARNING, 1);
234 }
235
236 public function getUIFactory()
237 {
238 return new NoUIFactory();
239 }
240
241 public function getTemplateFactory()
242 {
243 return new ilIndependentTemplateFactory();
244 }
245
246 public function getResourceRegistry()
247 {
248 return new LoggingRegistry();
249 }
250
251 public function getLanguage()
252 {
253 return new ilLanguageMock();
254 }
255
256 public function getJavaScriptBinding()
257 {
258 return new LoggingJavaScriptBinding();
259 }
260
261 public function getRefinery()
262 {
263 return $this->getMockBuilder(\ILIAS\Refinery\Factory::class)
264 ->disableOriginalConstructor()
265 ->getMock();
266 }
267
268 public function getDefaultRenderer(JavaScriptBinding $js_binding = null)
269 {
270 $ui_factory = $this->getUIFactory();
271 $tpl_factory = $this->getTemplateFactory();
272 $resource_registry = $this->getResourceRegistry();
273 $lng = $this->getLanguage();
274 if (!$js_binding) {
275 $js_binding = $this->getJavaScriptBinding();
276 }
277
278 $refinery = $this->getRefinery();
279
280 $component_renderer_loader
283 $resource_registry,
284 new Render\FSLoader(
286 $ui_factory,
287 $tpl_factory,
288 $lng,
289 $js_binding,
290 $refinery
291 ),
293 $ui_factory,
294 $tpl_factory,
295 $lng,
296 $js_binding,
297 $refinery
298 ),
300 $ui_factory,
301 $tpl_factory,
302 $lng,
303 $js_binding,
304 $refinery
305 )
306 )
307 )
308 );
309 return new TestDefaultRenderer($component_renderer_loader);
310 }
311
312 public function getDecoratedRenderer(Renderer $default)
313 {
314 return new TestDecoratedRenderer($default);
315 }
316
317 public function normalizeHTML($html)
318 {
319 return trim(str_replace(["\n", "\r"], "", $html));
320 }
321
326 public function assertHTMLEquals($expected_html_as_string, $html_as_string)
327 {
328 $html = new DOMDocument();
329 $html->formatOutput = true;
330 $html->preserveWhiteSpace = false;
331 $expected = new DOMDocument();
332 $expected->formatOutput = true;
333 $expected->preserveWhiteSpace = false;
334 $html->loadXML($this->normalizeHTML($html_as_string));
335 $expected->loadXML($this->normalizeHTML($expected_html_as_string));
336 $this->assertEquals($expected->saveHTML(), $html->saveHTML());
337 }
338
346 protected function brutallyTrimHTML($html)
347 {
348 $html = str_replace(["\n", "\r", "\t"], "", $html);
349 $html = preg_replace('# {2,}#', " ", $html);
350 $html = str_replace("> <", "><", $html);
351 $html = str_replace(" >", ">", $html);
352
353 return trim($html);
354 }
355}
An exception for terminatinating execution or to throw for unit testing.
getCanonicalName()
Get the canonical name of the component.
Definition: Base.php:215
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...
getRendererFor(Component $component)
Get a renderer for a certain Component class.
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:225
getJavaScriptBinding()
Definition: Base.php:256
getDecoratedRenderer(Renderer $default)
Definition: Base.php:312
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:326
getTemplateFactory()
Definition: Base.php:241
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
getResourceRegistry()
Definition: Base.php:246
normalizeHTML($html)
Definition: Base.php:317
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:346
createId()
Create a fresh unique id.
Definition: Base.php:151
addOnLoadCode($code)
Add some JavaScript-statements to the on-load handler of the page.
Definition: Base.php:159
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.
Definition: Base.php:163
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:189
_getRendererFor(IComponent $component)
Definition: Base.php:170
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.
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
Class ChatMainBarProvider \MainMenu\Provider.
$lng