ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
AbstractRendererTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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 
72 namespace {
73  require_once(__DIR__ . "/../Base.php");
74 
75  use ILIAS\UI\Component as C;
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 
135  class NullDefaultRenderer implements Renderer
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 }
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.
Interface Observer Contains several chained tasks and infos about them.
render($component, ?Renderer $root=null)
Render given component.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: deliver.php:25
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setVariable(string $name, $value)
Set a variable in the current block.
render(Component $component, Renderer $default_renderer)
addOnLoadCode(string $code)
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
getTemplate(string $path, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template instance.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setCurrentBlock(string $name)
Set the block to work on.
$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.