ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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\\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)
112 {
113 return "";
114 }
115 public function renderAsync($component)
116 {
117 return '';
118 }
119 public function withAdditionalContext(C\Component $context)
120 {
121 return $this;
122 }
123 }
124
126 {
127 public function setUp()
128 {
129 parent::setUp();
130 $this->tpl_factory = new TemplateFactoryMock();
131 $this->ui_factory = new NoUIFactory();
132 $this->lng = new ilLanguageMock();
133 $this->js_binding = new LoggingJavaScriptBinding();
134 }
135
137 {
138 $r = new \ILIAS\UI\Implementation\Component\Glyph\GlyphNonAbstractRenderer($this->ui_factory, $this->tpl_factory, $this->lng, $this->js_binding);
139 $tpl = $r->_getTemplate("tpl.glyph.html", true, false);
140
141 $expected = array( realpath(__DIR__ . "/../../../src/UI/templates/default/Glyph/tpl.glyph.html")
142 => array(true, false)
143 );
144
145 $this->assertEquals($expected, $this->tpl_factory->files);
146 }
147
149 {
150 $r = new \ILIAS\UI\Implementation\Component\Counter\CounterNonAbstractRenderer($this->ui_factory, $this->tpl_factory, $this->lng, $this->js_binding);
151
152 try {
153 $tpl = $r->_getTemplate("tpl.counter_foo.html", true, false);
154 $this->assertFalse("We should not get here");
155 } catch (\InvalidArgumentException $e) {
156 };
157
158 $expected = array( realpath(__DIR__ . "/../../src/UI/templates/default/Counter/tpl.counter_foo.html")
159 => array(true, false)
160 );
161 $this->assertEquals($expected, $this->tpl_factory->files);
162 }
163
165 {
166 $r = new \ILIAS\UI\Implementation\Component\Glyph\GlyphNonAbstractRendererWithJS($this->ui_factory, $this->tpl_factory, $this->lng, $this->js_binding);
167
168 $g = new \ILIAS\UI\Implementation\Component\Glyph\Glyph(\ILIAS\UI\Component\Glyph\Glyph::SETTINGS, "aria_label");
169
170 $ids = array();
171 $g = $g->withOnLoadCode(function ($id) use (&$ids) {
172 $ids[] = $id;
173 return "ID: $id";
174 });
175 $r->render($g, new NullDefaultRenderer());
176
177 $this->assertEquals($this->js_binding->ids, $ids);
178 $this->assertEquals(array("id_1"), $ids);
179 $this->assertEquals(array("ID: id_1"), $this->js_binding->on_load_code);
180 }
181
183 {
184 $r = new \ILIAS\UI\Implementation\Component\Glyph\GlyphNonAbstractRendererWithJS($this->ui_factory, $this->tpl_factory, $this->lng, $this->js_binding);
185
186 $g = new \ILIAS\UI\Implementation\Component\Glyph\Glyph(\ILIAS\UI\Component\Glyph\Glyph::SETTINGS, "aria_label");
187
188 $g = $g->withOnLoadCode(function ($id) {
189 return null;
190 });
191
192 try {
193 $r->render($g, new NullDefaultRenderer());
194 $this->assertFalse("This should not happen...");
195 } catch (\LogicException $e) {
196 $this->assertTrue(true);
197 }
198 }
199 }
200}
$tpl
Definition: ilias.php:10
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)
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:192
render($component)
Render given component.
withAdditionalContext(C\Component $context)
renderAsync($component)
Same as render, except that this version also returns any javascript code bound to the on load event,...
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.
$r
Definition: example_031.php:79
$code
Definition: example_050.php:99
if(!array_key_exists('StateId', $_REQUEST)) $id
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
$files
Definition: metarefresh.php:49
Class BaseForm.
Class Factory.
$context
Definition: webdav.php:25