ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $this->image_path_resolver = $this->getMockBuilder(ILIAS\UI\Implementation\Render\ImagePathResolver::class)
135 ->getMock();
136 }
137
139 {
140 $r = new \ILIAS\UI\Implementation\Component\Symbol\Glyph\GlyphNonAbstractRenderer(
141 $this->ui_factory,
142 $this->tpl_factory,
143 $this->lng,
144 $this->js_binding,
145 $this->getRefinery(),
146 $this->image_path_resolver
147 );
148 $tpl = $r->_getTemplate("tpl.glyph.html", true, false);
149
150 $expected = array( realpath(__DIR__ . "/../../../src/UI/templates/default/Symbol/tpl.glyph.html")
151 => array(true, false)
152 );
153
154 $this->assertEquals($expected, $this->tpl_factory->files);
155 }
156
158 {
159 $r = new \ILIAS\UI\Implementation\Component\Counter\CounterNonAbstractRenderer(
160 $this->ui_factory,
161 $this->tpl_factory,
162 $this->lng,
163 $this->js_binding,
164 $this->getRefinery(),
165 $this->image_path_resolver
166 );
167
168 try {
169 $tpl = $r->_getTemplate("tpl.counter_foo.html", true, false);
170 $this->assertFalse("We should not get here");
171 } catch (\InvalidArgumentException $e) {
172 };
173
174 $expected = array( realpath(__DIR__ . "/../../src/UI/templates/default/Counter/tpl.counter_foo.html")
175 => array(true, false)
176 );
177 $this->assertEquals($expected, $this->tpl_factory->files);
178 }
179
181 {
182 $r = new \ILIAS\UI\Implementation\Component\Symbol\Glyph\GlyphNonAbstractRendererWithJS(
183 $this->ui_factory,
184 $this->tpl_factory,
185 $this->lng,
186 $this->js_binding,
187 $this->getRefinery(),
188 $this->image_path_resolver
189 );
190
191 $g = new \ILIAS\UI\Implementation\Component\Symbol\Glyph\Glyph(\ILIAS\UI\Component\Symbol\Glyph\Glyph::SETTINGS, "aria_label");
192
193 $ids = array();
194 $g = $g->withOnLoadCode(function ($id) use (&$ids) {
195 $ids[] = $id;
196 return "ID: $id";
197 });
198 $r->render($g, new NullDefaultRenderer());
199
200 $this->assertEquals($this->js_binding->ids, $ids);
201 $this->assertEquals(array("id_1"), $ids);
202 $this->assertEquals(array("ID: id_1"), $this->js_binding->on_load_code);
203 }
204
206 {
207 $r = new \ILIAS\UI\Implementation\Component\Symbol\Glyph\GlyphNonAbstractRendererWithJS(
208 $this->ui_factory,
209 $this->tpl_factory,
210 $this->lng,
211 $this->js_binding,
212 $this->getRefinery(),
213 $this->image_path_resolver
214 );
215
216 $g = new \ILIAS\UI\Implementation\Component\Symbol\Glyph\Glyph(\ILIAS\UI\Component\Symbol\Glyph\Glyph::SETTINGS, "aria_label");
217
218 $g = $g->withOnLoadCode(function ($id) {
219 return null;
220 });
221
222 try {
223 $r->render($g, new NullDefaultRenderer());
224 $this->assertFalse("This should not happen...");
225 } catch (\LogicException $e) {
226 $this->assertTrue(true);
227 }
228 }
229 }
230}
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:263
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.
$c
Definition: cli.php:37
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($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
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
$context
Definition: webdav.php:26