ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
AbstractRendererTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22  require_once("libs/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  protected function getComponentInterfaceName(): array
41  {
42  return ["\\ILIAS\\UI\\Component\\Symbol\\Glyph\\Glyph"];
43  }
44  }
45 
47  {
48  public array $ids = array();
49 
50  public function render(Component $component, Renderer $default_renderer): string
51  {
52  $this->ids[] = $this->bindJavaScript($component);
53  return "";
54  }
55  }
56 }
57 
63 
65  {
66  public function render(Component $component, Renderer $default_renderer): string
67  {
68  }
69 
70  public function _getTemplate(string $a, bool $b, bool $c): Template
71  {
72  return $this->getTemplate($a, $b, $c);
73  }
74 
75  protected function getComponentInterfaceName(): array
76  {
77  return ["\\ILIAS\\UI\\Component\\Counter\\Counter"];
78  }
79  }
80 }
81 
82 namespace {
99  require_once(__DIR__ . "/../Base.php");
100 
101  use ILIAS\UI\Component as C;
104  use ILIAS\UI\Renderer;
111 
112  class NullTemplate implements Template
113  {
114  public function setCurrentBlock(string $name): bool
115  {
116  return true;
117  }
118 
119  public function parseCurrentBlock(): bool
120  {
121  return true;
122  }
123 
124  public function touchBlock(string $name): bool
125  {
126  return true;
127  }
128 
129  public function setVariable(string $name, $value): void
130  {
131  }
132 
133  public function get(string $block = null): string
134  {
135  return "";
136  }
137 
138  public function addOnLoadCode(string $code): void
139  {
140  }
141  }
142 
144  {
145  public array $files = array();
146 
147  public function getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks): Template
148  {
149  $file_name = realpath(__DIR__ . "/../../../" . $path);
150  $this->files[$file_name] = array($purge_unfilled_vars, $purge_unused_blocks);
151 
152  if (!file_exists($file_name)) {
153  throw new InvalidArgumentException();
154  }
155 
156  return new NullTemplate();
157  }
158  }
159 
160  class NullDefaultRenderer implements Renderer
161  {
162  public function render($component, ?Renderer $root = null)
163  {
164  return "";
165  }
166  public function renderAsync($component, ?Renderer $root = null)
167  {
168  return '';
169  }
170 
172  {
173  return $this;
174  }
175  }
176 
178  {
181  protected ilLanguageMock $lng;
188 
189  public function setUp(): void
190  {
191  parent::setUp();
192  $this->tpl_factory = new TemplateFactoryMock();
193  $this->ui_factory = $this->getUIFactory(); //new NoUIFactory();
194  $this->lng = new ilLanguageMock();
195  $this->js_binding = new LoggingJavaScriptBinding();
196  $this->image_path_resolver = $this->getMockBuilder(ILIAS\UI\Implementation\Render\ImagePathResolver::class)
197  ->getMock();
198  $this->help_text_retriever = $this->createMock(ILIAS\UI\HelpTextRetriever::class);
199  }
200 
201  public function testGetTemplateSuccessfull(): void
202  {
204  $this->ui_factory,
205  $this->tpl_factory,
206  $this->lng,
207  $this->js_binding,
208  $this->getRefinery(),
209  $this->image_path_resolver,
210  $this->getDataFactory(),
211  $this->help_text_retriever,
212  $this->getUploadLimitResolver()
213  );
214  $r->_getTemplate("tpl.glyph.html", true, false);
215 
216  $expected = array(realpath(__DIR__ . "/../../../src/UI/templates/default/Symbol/tpl.glyph.html")
217  => array(true, false)
218  );
219 
220  $this->assertEquals($expected, $this->tpl_factory->files);
221  }
222 
223  public function testGetTemplateUnsuccessfull(): void
224  {
226  $this->ui_factory,
227  $this->tpl_factory,
228  $this->lng,
229  $this->js_binding,
230  $this->getRefinery(),
231  $this->image_path_resolver,
232  $this->getDataFactory(),
233  $this->help_text_retriever,
234  $this->getUploadLimitResolver()
235  );
236 
237  $this->expectException(TypeError::class);
238  $r->_getTemplate("tpl.counter_foo.html", true, false);
239 
240  $expected = array(realpath(__DIR__ . "/../../src/UI/templates/default/Counter/tpl.counter_foo.html")
241  => array(true, false)
242  );
243  $this->assertEquals($expected, $this->tpl_factory->files);
244  }
245 
246  public function testBindJavaScriptSuccessfull(): void
247  {
249  $this->ui_factory,
250  $this->tpl_factory,
251  $this->lng,
252  $this->js_binding,
253  $this->getRefinery(),
254  $this->image_path_resolver,
255  $this->getDataFactory(),
256  $this->help_text_retriever,
257  $this->getUploadLimitResolver()
258  );
259 
260  $g = new Glyph(C\Symbol\Glyph\Glyph::SETTINGS, "aria_label");
261 
262  $ids = array();
263  $g = $g->withOnLoadCode(function ($id) use (&$ids) {
264  $ids[] = $id;
265  return "ID: $id";
266  });
267  $r->render($g, new NullDefaultRenderer());
268 
269  $this->assertEquals($this->js_binding->ids, $ids);
270  $this->assertEquals(array("id_1"), $ids);
271  $this->assertEquals(array("ID: id_1"), $this->js_binding->on_load_code);
272  }
273 
274  public function testBindJavaScriptNoString(): void
275  {
277  $this->ui_factory,
278  $this->tpl_factory,
279  $this->lng,
280  $this->js_binding,
281  $this->getRefinery(),
282  $this->image_path_resolver,
283  $this->getDataFactory(),
284  $this->help_text_retriever,
285  $this->getUploadLimitResolver()
286  );
287 
288  $g = new Glyph(C\Symbol\Glyph\Glyph::SETTINGS, "aria_label");
289 
290  $g = $g->withOnLoadCode(function ($id) {
291  return null;
292  });
293 
294  try {
295  $r->render($g, new NullDefaultRenderer());
296  $this->assertFalse("This should not happen...");
297  } catch (LogicException $e) {
298  $this->assertTrue(true);
299  }
300  }
301  }
302 }
An entity that renders components to a string output.
Definition: Renderer.php:30
$context
Definition: webdav.php:31
LoggingJavaScriptBinding $js_binding
TemplateFactoryMock $tpl_factory
renderAsync($component, ?Renderer $root=null)
Same as render, except that this version also returns any javascript code bound to the on load event...
touchBlock(string $name)
Touch a block without working further on it.
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
render($component, ?Renderer $root=null)
Render given component.
$path
Definition: ltiservices.php:32
setVariable(string $name, $value)
Set a variable in the current block.
render(Component $component, Renderer $default_renderer)
Provides common functionality for UI tests.
Definition: Base.php:310
addOnLoadCode(string $code)
Add some javascript to be executed on_load of the rendered page.
withAdditionalContext(C\Component $context)
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
ILIAS UI HelpTextRetriever $help_text_retriever
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Counter.php:21
getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template instance.
setCurrentBlock(string $name)
Set the block to work on.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
parseCurrentBlock()
Parse the block that is currently worked on.
Interface for a factory that provides templates.
$r
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.