ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
AbstractRendererTest.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
6 require_once("libs/composer/vendor/autoload.php");
7
8 use \ILIAS\UI\Component\Component;
9 use \ILIAS\UI\Renderer;
10 use \ILIAS\UI\Implementation\Render\AbstractComponentRenderer;
11
13 {
14 public function render(Component $component, Renderer $default_renderer)
15 {
16 }
17 public function _getTemplate($a, $b, $c)
18 {
19 return $this->getTemplate($a, $b, $c);
20 }
21 protected function getComponentInterfaceName()
22 {
23 return "\\ILIAS\\UI\\Component\\Symbol\\Glyph\\Glyph";
24 }
25 }
26
28 {
29 public $ids = array();
30 public function render(Component $component, Renderer $default_renderer)
31 {
32 $this->ids[] = $this->bindJavaScript($component);
33 return "";
34 }
35 }
36}
37
39 use \ILIAS\UI\Component\Component;
40 use \ILIAS\UI\Renderer;
41 use \ILIAS\UI\Implementation\Render\AbstractComponentRenderer;
42
44 {
45 public function render(Component $component, Renderer $default_renderer)
46 {
47 }
48 public function _getTemplate($a, $b, $c)
49 {
50 return $this->getTemplate($a, $b, $c);
51 }
52 protected function getComponentInterfaceName()
53 {
54 return "\\ILIAS\\UI\\Component\\Counter\\Counter";
55 }
56 }
57}
58
59namespace {
60
61 require_once(__DIR__ . "/../Base.php");
62
63
64 use \ILIAS\UI\Component as C;
65 use \ILIAS\UI\Implementation\Render\Template;
66 use \ILIAS\UI\Implementation\Render\JavaScriptBinding;
67 use \ILIAS\UI\Implementation\Render\TemplateFactory;
68
69 class NullTemplate implements Template
70 {
71 public function setCurrentBlock($name)
72 {
73 }
74 public function parseCurrentBlock()
75 {
76 }
77 public function touchBlock($name)
78 {
79 }
80 public function setVariable($name, $value)
81 {
82 }
83 public function get($name = null)
84 {
85 return "";
86 }
87 public function addOnLoadCode($code)
88 {
89 return "";
90 }
91 }
92
94 {
95 public $files = array();
96 public function getTemplate($file_name, $purge_unfilled_vars, $purge_unused_blocks)
97 {
98 $file_name = realpath(__DIR__ . "/../../../" . $file_name);
99 $this->files[$file_name] = array($purge_unfilled_vars, $purge_unused_blocks);
100
101 if (!file_exists($file_name)) {
102 throw new \InvalidArgumentException();
103 }
104
105 return new NullTemplate();
106 }
107 }
108
110 {
111 public function render($component, ?\ILIAS\UI\Renderer $root = null)
112 {
113 return "";
114 }
115 public function renderAsync($component, ?\ILIAS\UI\Renderer $root = null)
116 {
117 return '';
118 }
119 public function withAdditionalContext(C\Component $context)
120 {
121 return $this;
122 }
123 }
124
126 {
127 public function setUp() : void
128 {
129 parent::setUp();
130 $this->tpl_factory = new TemplateFactoryMock();
131 $this->ui_factory = $this->getUIFactory(); //new NoUIFactory();
132 $this->lng = new ilLanguageMock();
133 $this->js_binding = new LoggingJavaScriptBinding();
134 }
135
137 {
138 $r = new \ILIAS\UI\Implementation\Component\Symbol\Glyph\GlyphNonAbstractRenderer(
139 $this->ui_factory,
140 $this->tpl_factory,
141 $this->lng,
142 $this->js_binding,
143 $this->getRefinery()
144 );
145 $tpl = $r->_getTemplate("tpl.glyph.html", true, false);
146
147 $expected = array( realpath(__DIR__ . "/../../../src/UI/templates/default/Symbol/tpl.glyph.html")
148 => array(true, false)
149 );
150
151 $this->assertEquals($expected, $this->tpl_factory->files);
152 }
153
155 {
156 $r = new \ILIAS\UI\Implementation\Component\Counter\CounterNonAbstractRenderer(
157 $this->ui_factory,
158 $this->tpl_factory,
159 $this->lng,
160 $this->js_binding,
161 $this->getRefinery()
162 );
163
164 try {
165 $tpl = $r->_getTemplate("tpl.counter_foo.html", true, false);
166 $this->assertFalse("We should not get here");
167 } catch (\InvalidArgumentException $e) {
168 };
169
170 $expected = array( realpath(__DIR__ . "/../../src/UI/templates/default/Counter/tpl.counter_foo.html")
171 => array(true, false)
172 );
173 $this->assertEquals($expected, $this->tpl_factory->files);
174 }
175
177 {
178 $r = new \ILIAS\UI\Implementation\Component\Symbol\Glyph\GlyphNonAbstractRendererWithJS(
179 $this->ui_factory,
180 $this->tpl_factory,
181 $this->lng,
182 $this->js_binding,
183 $this->getRefinery()
184 );
185
186 $g = new \ILIAS\UI\Implementation\Component\Symbol\Glyph\Glyph(\ILIAS\UI\Component\Symbol\Glyph\Glyph::SETTINGS, "aria_label");
187
188 $ids = array();
189 $g = $g->withOnLoadCode(function ($id) use (&$ids) {
190 $ids[] = $id;
191 return "ID: $id";
192 });
193 $r->render($g, new NullDefaultRenderer());
194
195 $this->assertEquals($this->js_binding->ids, $ids);
196 $this->assertEquals(array("id_1"), $ids);
197 $this->assertEquals(array("ID: id_1"), $this->js_binding->on_load_code);
198 }
199
201 {
202 $r = new \ILIAS\UI\Implementation\Component\Symbol\Glyph\GlyphNonAbstractRendererWithJS(
203 $this->ui_factory,
204 $this->tpl_factory,
205 $this->lng,
206 $this->js_binding,
207 $this->getRefinery()
208 );
209
210 $g = new \ILIAS\UI\Implementation\Component\Symbol\Glyph\Glyph(\ILIAS\UI\Component\Symbol\Glyph\Glyph::SETTINGS, "aria_label");
211
212 $g = $g->withOnLoadCode(function ($id) {
213 return null;
214 });
215
216 try {
217 $r->render($g, new NullDefaultRenderer());
218 $this->assertFalse("This should not happen...");
219 } catch (\LogicException $e) {
220 $this->assertTrue(true);
221 }
222 }
223 }
224}
An exception for terminatinating execution or to throw for unit testing.
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.
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
Provides common functionality for UI tests.
Definition: Base.php:225
render($component, ?\ILIAS\UI\Renderer $root=null)
renderAsync($component, ?\ILIAS\UI\Renderer $root=null)
withAdditionalContext(C\Component $context)
parseCurrentBlock()
Parse the block that is currently worked on.
setVariable($name, $value)
Set a variable in the current block.
touchBlock($name)
Touch a block without working further on it.
setCurrentBlock($name)
Set the block to work on.
addOnLoadCode($code)
Add some javascript to be executed on_load of the rendered page.
getTemplate($file_name, $purge_unfilled_vars, $purge_unused_blocks)
Get template instance.
A component is the most general form of an entity in the UI.
Definition: Component.php:14
Interface for a factory that provides templates.
Interface to templating as it is used in the UI framework.
Definition: Template.php:14
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.
Class Factory.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$context
Definition: webdav.php:26