ILIAS  release_8 Revision v8.24
AbstractRendererTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
23 require_once("libs/composer/vendor/autoload.php");
24
29
31 {
32 public function render(Component $component, Renderer $default_renderer): string
33 {
34 }
35
36 public function _getTemplate(string $a, bool $b, bool $c): Template
37 {
38 return $this->getTemplate($a, $b, $c);
39 }
40
41 protected function getComponentInterfaceName(): array
42 {
43 return ["\\ILIAS\\UI\\Component\\Symbol\\Glyph\\Glyph"];
44 }
45 }
46
48 {
49 public array $ids = array();
50
51 public function render(Component $component, Renderer $default_renderer): string
52 {
53 $this->ids[] = $this->bindJavaScript($component);
54 return "";
55 }
56 }
57}
58
60
65
67 {
68 public function render(Component $component, Renderer $default_renderer): string
69 {
70 }
71
72 public function _getTemplate(string $a, bool $b, bool $c): Template
73 {
74 return $this->getTemplate($a, $b, $c);
75 }
76
77 protected function getComponentInterfaceName(): array
78 {
79 return ["\\ILIAS\\UI\\Component\\Counter\\Counter"];
80 }
81 }
82}
83
84namespace {
85
102 require_once(__DIR__ . "/../Base.php");
103
104 use ILIAS\UI\Component as C;
109 use PHPUnit\Framework\MockObject\MockObject;
114
115 class NullTemplate implements Template
116 {
117 public function setCurrentBlock(string $name): bool
118 {
119 return true;
120 }
121
122 public function parseCurrentBlock(): bool
123 {
124 return true;
125 }
126
127 public function touchBlock(string $name): bool
128 {
129 return true;
130 }
131
132 public function setVariable(string $name, $value): void
133 {
134 }
135
136 public function get(string $block = null): string
137 {
138 return "";
139 }
140
141 public function addOnLoadCode(string $code): void
142 {
143 }
144 }
145
147 {
148 public array $files = array();
149
150 public function getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks): Template
151 {
152 $file_name = realpath(__DIR__ . "/../../../" . $path);
153 $this->files[$file_name] = array($purge_unfilled_vars, $purge_unused_blocks);
154
155 if (!file_exists($file_name)) {
156 throw new InvalidArgumentException();
157 }
158
159 return new NullTemplate();
160 }
161 }
162
164 {
165 public function render($component, ?Renderer $root = null)
166 {
167 return "";
168 }
169 public function renderAsync($component, ?Renderer $root = null)
170 {
171 return '';
172 }
173
175 {
176 return $this;
177 }
178 }
179
181 {
190
191 public function setUp(): void
192 {
193 parent::setUp();
194 $this->tpl_factory = new TemplateFactoryMock();
195 $this->ui_factory = $this->getUIFactory(); //new NoUIFactory();
196 $this->lng = new ilLanguageMock();
197 $this->js_binding = new LoggingJavaScriptBinding();
198 $this->image_path_resolver = $this->getMockBuilder(ILIAS\UI\Implementation\Render\ImagePathResolver::class)
199 ->getMock();
200 }
201
202 public function test_getTemplate_successfull(): void
203 {
205 $this->ui_factory,
206 $this->tpl_factory,
207 $this->lng,
208 $this->js_binding,
209 $this->getRefinery(),
210 $this->image_path_resolver,
211 $this->getDataFactory()
212 );
213 $r->_getTemplate("tpl.glyph.html", true, false);
214
215 $expected = array(realpath(__DIR__ . "/../../../src/UI/templates/default/Symbol/tpl.glyph.html")
216 => array(true, false)
217 );
218
219 $this->assertEquals($expected, $this->tpl_factory->files);
220 }
221
222 public function test_getTemplate_unsuccessfull(): void
223 {
225 $this->ui_factory,
226 $this->tpl_factory,
227 $this->lng,
228 $this->js_binding,
229 $this->getRefinery(),
230 $this->image_path_resolver,
231 $this->getDataFactory()
232 );
233
234 $this->expectException(TypeError::class);
235 $r->_getTemplate("tpl.counter_foo.html", true, false);
236
237 $expected = array(realpath(__DIR__ . "/../../src/UI/templates/default/Counter/tpl.counter_foo.html")
238 => array(true, false)
239 );
240 $this->assertEquals($expected, $this->tpl_factory->files);
241 }
242
243 public function test_bindJavaScript_successfull(): void
244 {
246 $this->ui_factory,
247 $this->tpl_factory,
248 $this->lng,
249 $this->js_binding,
250 $this->getRefinery(),
251 $this->image_path_resolver,
252 $this->getDataFactory()
253 );
254
255 $g = new Glyph(C\Symbol\Glyph\Glyph::SETTINGS, "aria_label");
256
257 $ids = array();
258 $g = $g->withOnLoadCode(function ($id) use (&$ids) {
259 $ids[] = $id;
260 return "ID: $id";
261 });
262 $r->render($g, new NullDefaultRenderer());
263
264 $this->assertEquals($this->js_binding->ids, $ids);
265 $this->assertEquals(array("id_1"), $ids);
266 $this->assertEquals(array("ID: id_1"), $this->js_binding->on_load_code);
267 }
268
269 public function test_bindJavaScript_no_string(): void
270 {
272 $this->ui_factory,
273 $this->tpl_factory,
274 $this->lng,
275 $this->js_binding,
276 $this->getRefinery(),
277 $this->image_path_resolver,
278 $this->getDataFactory()
279 );
280
281 $g = new Glyph(C\Symbol\Glyph\Glyph::SETTINGS, "aria_label");
282
283 $g = $g->withOnLoadCode(function ($id) {
284 return null;
285 });
286
287 try {
288 $r->render($g, new NullDefaultRenderer());
289 $this->assertFalse("This should not happen...");
290 } catch (LogicException $e) {
291 $this->assertTrue(true);
292 }
293 }
294 }
295}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
LoggingJavaScriptBinding $js_binding
TemplateFactoryMock $tpl_factory
getComponentInterfaceName()
Get the name of the component-interface this renderer is supposed to render.
render(Component $component, Renderer $default_renderer)
getComponentInterfaceName()
Get the name of the component-interface this renderer is supposed to render.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
Provides common functionality for UI tests.
Definition: Base.php:299
renderAsync($component, ?Renderer $root=null)
Same as render, except that this version also returns any javascript code bound to the on load event,...
render($component, ?Renderer $root=null)
Render given component.
withAdditionalContext(C\Component $context)
parseCurrentBlock()
Parse the block that is currently worked on.
touchBlock(string $name)
Touch a block without working further on it.
setCurrentBlock(string $name)
Set the block to work on.
setVariable(string $name, $value)
Set a variable in the current block.
addOnLoadCode(string $code)
Add some javascript to be executed on_load of the rendered page.
getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template instance.
$c
Definition: cli.php:38
A component is the most general form of an entity in the UI.
Definition: Component.php:28
Some Components need to resolve pathes to image-files.
Interface for a factory that provides templates.
Interface to templating as it is used in the UI framework.
Definition: Template.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31
$path
Definition: ltiservices.php:32
if($format !==null) $name
Definition: metadata.php:247
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Counter.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$context
Definition: webdav.php:29