ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AbstractRendererTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22 require_once("vendor/composer/vendor/autoload.php");
23
28
30 {
31 public function render(Component $component, Renderer $default_renderer): string
32 {
33 }
34
35 public function _getTemplate(string $a, bool $b, bool $c): Template
36 {
37 return $this->getTemplate($a, $b, $c);
38 }
39 }
40
42 {
43 public array $ids = array();
44
45 public function render(Component $component, Renderer $default_renderer): string
46 {
47 $this->ids[] = $this->bindJavaScript($component);
48 return "";
49 }
50 }
51}
52
58
60 {
61 public function render(Component $component, Renderer $default_renderer): string
62 {
63 }
64
65 public function _getTemplate(string $a, bool $b, bool $c): Template
66 {
67 return $this->getTemplate($a, $b, $c);
68 }
69 }
70}
71
72namespace {
73 require_once(__DIR__ . "/../Base.php");
74
75 use ILIAS\UI\Component as C;
80 use PHPUnit\Framework\MockObject\MockObject;
86
87 class NullTemplate implements Template
88 {
89 public function setCurrentBlock(string $name): bool
90 {
91 return true;
92 }
93
94 public function parseCurrentBlock(): bool
95 {
96 return true;
97 }
98
99 public function touchBlock(string $name): bool
100 {
101 return true;
102 }
103
104 public function setVariable(string $name, $value): void
105 {
106 }
107
108 public function get(?string $block = null): string
109 {
110 return "";
111 }
112
113 public function addOnLoadCode(string $code): void
114 {
115 }
116 }
117
119 {
120 public array $files = array();
121
122 public function getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks): Template
123 {
124 $file_name = realpath(__DIR__ . "/../../../../../" . $path);
125 $this->files[$file_name] = array($purge_unfilled_vars, $purge_unused_blocks);
126
127 if (!file_exists($file_name)) {
128 throw new InvalidArgumentException();
129 }
130
131 return new NullTemplate();
132 }
133 }
134
136 {
137 public function render($component, ?Renderer $root = null)
138 {
139 return "";
140 }
141 public function renderAsync($component, ?Renderer $root = null)
142 {
143 return '';
144 }
145 }
146
148 {
151 protected Language $lng;
158
159 public function setUp(): void
160 {
161 parent::setUp();
162 $this->tpl_factory = new TemplateFactoryMock();
163 $this->ui_factory = $this->getUIFactory(); //new NoUIFactory();
164 $this->lng = new LanguageMock();
165 $this->js_binding = new LoggingJavaScriptBinding();
166 $this->image_path_resolver = $this->getMockBuilder(ILIAS\UI\Implementation\Render\ImagePathResolver::class)
167 ->getMock();
168 $this->help_text_retriever = $this->createMock(ILIAS\UI\HelpTextRetriever::class);
169 }
170
171 public function testGetTemplateSuccessfull(): void
172 {
174 $this->ui_factory,
175 $this->tpl_factory,
176 $this->lng,
177 $this->js_binding,
178 $this->image_path_resolver,
179 $this->getDataFactory(),
180 $this->help_text_retriever,
181 $this->getUploadLimitResolver()
182 );
183 $r->_getTemplate("tpl.glyph.html", true, false);
184
185 $expected = array(realpath(__DIR__ . "/../../../../../components/ILIAS/UI/src/templates/default/Symbol/tpl.glyph.html")
186 => array(true, false)
187 );
188
189 $this->assertEquals($expected, $this->tpl_factory->files);
190 }
191
192 public function testGetTemplateUnsuccessfull(): void
193 {
195 $this->ui_factory,
196 $this->tpl_factory,
197 $this->lng,
198 $this->js_binding,
199 $this->image_path_resolver,
200 $this->getDataFactory(),
201 $this->help_text_retriever,
202 $this->getUploadLimitResolver()
203 );
204
205 $this->expectException(TypeError::class);
206 $r->_getTemplate("tpl.counter_foo.html", true, false);
207
208 $expected = array(realpath(__DIR__ . "/../../components/ILIAS/UI/src/templates/default/Counter/tpl.counter_foo.html")
209 => array(true, false)
210 );
211 $this->assertEquals($expected, $this->tpl_factory->files);
212 }
213
214 public function testBindJavaScriptSuccessfull(): void
215 {
217 $this->ui_factory,
218 $this->tpl_factory,
219 $this->lng,
220 $this->js_binding,
221 $this->image_path_resolver,
222 $this->getDataFactory(),
223 $this->help_text_retriever,
224 $this->getUploadLimitResolver()
225 );
226
227 $g = new Glyph(C\Symbol\Glyph\Glyph::SETTINGS, "aria_label");
228
229 $ids = array();
230 $g = $g->withOnLoadCode(function ($id) use (&$ids) {
231 $ids[] = $id;
232 return "ID: $id";
233 });
234 $r->render($g, new NullDefaultRenderer());
235
236 $this->assertEquals($this->js_binding->ids, $ids);
237 $this->assertEquals(array("id_1"), $ids);
238 $this->assertEquals(array("ID: id_1"), $this->js_binding->on_load_code);
239 }
240
241 public function testBindJavaScriptNoString(): void
242 {
244 $this->ui_factory,
245 $this->tpl_factory,
246 $this->lng,
247 $this->js_binding,
248 $this->image_path_resolver,
249 $this->getDataFactory(),
250 $this->help_text_retriever,
251 $this->getUploadLimitResolver()
252 );
253
254 $g = new Glyph(C\Symbol\Glyph\Glyph::SETTINGS, "aria_label");
255
256 $g = $g->withOnLoadCode(function ($id) {
257 return null;
258 });
259
260 try {
261 $r->render($g, new NullDefaultRenderer());
262 $this->assertFalse("This should not happen...");
263 } catch (LogicException $e) {
264 $this->assertTrue(true);
265 }
266 }
267 }
268}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
LoggingJavaScriptBinding $js_binding
ILIAS UI HelpTextRetriever $help_text_retriever
TemplateFactoryMock $tpl_factory
render(Component $component, Renderer $default_renderer)
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:337
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.
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)
getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template instance.
$c
Definition: deliver.php:25
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This describes a facility that the UI framework can use to retrieve some help text.
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:30
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples