ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
Base.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 
5 require_once("libs/composer/vendor/autoload.php");
6 
7 require_once(__DIR__ . "/Renderer/ilIndependentTemplate.php");
8 require_once(__DIR__ . "/../../Services/Language/classes/class.ilLanguage.php");
9 
10 use ILIAS\UI\Component as C;
12 use ILIAS\UI\Implementaiton\Component as I;
26 
28 {
29  public function getTemplate($path, $purge_unfilled_vars, $purge_unused_blocks)
30  {
31  return new ilIndependentGlobalTemplate($path, $purge_unfilled_vars, $purge_unused_blocks);
32  }
33 }
34 
35 class NoUIFactory implements Factory
36 {
37  public function counter()
38  {
39  }
40  public function button()
41  {
42  }
43  public function card()
44  {
45  }
46  public function deck(array $cards)
47  {
48  }
49  public function listing()
50  {
51  }
52  public function image()
53  {
54  }
55  public function legacy($content)
56  {
57  }
58  public function panel()
59  {
60  }
61  public function modal()
62  {
63  }
64  public function dropzone()
65  {
66  }
67  public function popover()
68  {
69  }
70  public function divider()
71  {
72  }
73  public function link()
74  {
75  }
76  public function dropdown()
77  {
78  }
79  public function item()
80  {
81  }
82  public function viewControl()
83  {
84  }
85  public function breadcrumbs(array $crumbs)
86  {
87  }
88  public function chart()
89  {
90  }
91  public function input()
92  {
93  }
94  public function table()
95  {
96  }
97  public function messageBox()
98  {
99  }
100  public function layout() : C\Layout\Factory
101  {
102  }
103  public function mainControls() : C\MainControls\Factory
104  {
105  }
106  public function tree()
107  {
108  }
109  public function menu() : C\Menu\Factory
110  {
111  }
112  public function symbol() : C\Symbol\Factory
113  {
114  }
115 }
116 
118 {
119  public $resources = array();
120 
121  public function register($name)
122  {
123  $this->resources[] = $name;
124  }
125 }
126 
128 {
129  public $requested = array();
130  public function __construct()
131  {
132  }
133  public function txt($a_topic, $a_default_lang_fallback_mod = "")
134  {
135  $this->requested[] = $a_topic;
136  return $a_topic;
137  }
138  public function toJS($a_lang_key, ilGlobalTemplateInterface $a_tpl = null)
139  {
140  }
141  public $lang_module = 'common';
142  public function loadLanguageModule($lang_module)
143  {
144  }
145 }
146 
148 {
149  private $count = 0;
150  public $ids = array();
151  public function createId()
152  {
153  $this->count++;
154  $id = "id_" . $this->count;
155  $this->ids[] = $id;
156  return $id;
157  }
158  public $on_load_code = array();
159  public function addOnLoadCode($code)
160  {
161  $this->on_load_code[] = $code;
162  }
163  public function getOnLoadCodeAsync()
164  {
165  }
166 }
167 
169 {
170  public function _getRendererFor(IComponent $component)
171  {
172  return $this->getRendererFor($component);
173  }
174  public function _getContexts()
175  {
176  return $this->getContexts();
177  }
178 }
179 
181 {
182  private $manipulate = false;
183 
184  public function manipulate() : void
185  {
186  $this->manipulate = true;
187  }
188 
189  protected function manipulateRendering($component, Renderer $root) : ?string
190  {
191  if ($this->manipulate) {
192  return "This content was manipulated";
193  } else {
194  return null;
195  }
196  }
197 }
198 
200 {
201  protected $id = 0;
202 
203  protected function createId()
204  {
205  return 'signal_' . ++$this->id;
206  }
207 }
208 
210 {
211 }
212 
213 class DummyComponent implements IComponent
214 {
215  public function getCanonicalName()
216  {
217  return "DummyComponent";
218  }
219 }
220 
224 abstract class ILIAS_UI_TestBase extends TestCase
225 {
226  public function setUp() : void
227  {
228  assert_options(ASSERT_WARNING, 0);
229  }
230 
231  public function tearDown() : void
232  {
233  assert_options(ASSERT_WARNING, 1);
234  }
235 
236  public function getUIFactory()
237  {
238  return new NoUIFactory();
239  }
240 
241  public function getTemplateFactory()
242  {
243  return new ilIndependentTemplateFactory();
244  }
245 
246  public function getResourceRegistry()
247  {
248  return new LoggingRegistry();
249  }
250 
251  public function getLanguage()
252  {
253  return new ilLanguageMock();
254  }
255 
256  public function getJavaScriptBinding()
257  {
258  return new LoggingJavaScriptBinding();
259  }
260 
261  public function getRefinery()
262  {
263  return $this->getMockBuilder(\ILIAS\Refinery\Factory::class)
264  ->disableOriginalConstructor()
265  ->getMock();
266  }
267 
268  public function getDefaultRenderer(JavaScriptBinding $js_binding = null)
269  {
270  $ui_factory = $this->getUIFactory();
271  $tpl_factory = $this->getTemplateFactory();
272  $resource_registry = $this->getResourceRegistry();
273  $lng = $this->getLanguage();
274  if (!$js_binding) {
275  $js_binding = $this->getJavaScriptBinding();
276  }
277 
278  $refinery = $this->getRefinery();
279 
280  $component_renderer_loader
281  = new Render\LoaderCachingWrapper(
283  $resource_registry,
284  new Render\FSLoader(
286  $ui_factory,
287  $tpl_factory,
288  $lng,
289  $js_binding,
290  $refinery
291  ),
293  $ui_factory,
294  $tpl_factory,
295  $lng,
296  $js_binding,
297  $refinery
298  ),
300  $ui_factory,
301  $tpl_factory,
302  $lng,
303  $js_binding,
304  $refinery
305  )
306  )
307  )
308  );
309  return new TestDefaultRenderer($component_renderer_loader);
310  }
311 
312  public function getDecoratedRenderer(Renderer $default)
313  {
314  return new TestDecoratedRenderer($default);
315  }
316 
317  public function normalizeHTML($html)
318  {
319  return trim(str_replace(["\n", "\r"], "", $html));
320  }
321 
326  public function assertHTMLEquals($expected_html_as_string, $html_as_string)
327  {
328  $html = new DOMDocument();
329  $html->formatOutput = true;
330  $html->preserveWhiteSpace = false;
331  $expected = new DOMDocument();
332  $expected->formatOutput = true;
333  $expected->preserveWhiteSpace = false;
334  $html->loadXML($this->normalizeHTML($html_as_string));
335  $expected->loadXML($this->normalizeHTML($expected_html_as_string));
336  $this->assertEquals($expected->saveHTML(), $html->saveHTML());
337  }
338 
346  protected function brutallyTrimHTML($html)
347  {
348  $html = str_replace(["\n", "\r", "\t"], "", $html);
349  $html = preg_replace('# {2,}#', " ", $html);
350  $html = str_replace("> <", "><", $html);
351  $html = str_replace(" >", ">", $html);
352 
353  return trim($html);
354  }
355 }
Registry for resources required by rendered output like Javascript or CSS.
An entity that renders components to a string output.
Definition: Renderer.php:14
card()
description: purpose: > A card is a flexible content container for small chunks of structured data...
Definition: Base.php:43
item()
description: purpose: > An item displays a unique entity within the system.
Definition: Base.php:79
breadcrumbs(array $crumbs)
description: purpose: > Breadcrumbs is a supplemental navigation scheme.
Definition: Base.php:85
dropzone()
description: purpose: > Dropzones are containers used to drop either files or other HTML elements...
Definition: Base.php:64
getDecoratedRenderer(Renderer $default)
Definition: Base.php:312
getCanonicalName()
Get the canonical name of the component.
Definition: Base.php:215
mainControls()
description: purpose: > Main Controls are components that are always usable, depending only on overa...
Definition: Base.php:103
viewControl()
description: purpose: > View Controls switch between different visualisation of data.
Definition: Base.php:82
Loads renderers for components from the file system.
Definition: FSLoader.php:20
Class ChatMainBarProvider .
link()
description: purpose: > Links are used navigate to other resources or views of the system by clickin...
Definition: Base.php:73
symbol()
description: purpose: > Symbols are graphical representations of concepts or contexts quickly compre...
Definition: Base.php:112
Registers resources for retreived renderers at a ResourceRegistry.
layout()
description: purpose: > Layout components are compontents used for the overall construction of the u...
Definition: Base.php:100
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
messageBox()
description: purpose: > Message Boxes inform the user about the state of the system or an ongoing us...
Definition: Base.php:97
normalizeHTML($html)
Definition: Base.php:317
deck(array $cards)
description: purpose: > Decks are used to display multiple Cards in a grid.
Definition: Base.php:46
toJS($a_lang_key, ilGlobalTemplateInterface $a_tpl=null)
Definition: Base.php:138
getOnLoadCodeAsync()
Get all the registered on-load javascript code for the async context, e.g.
Definition: Base.php:163
getJavaScriptBinding()
Definition: Base.php:256
if($format !==null) $name
Definition: metadata.php:230
Provides common functionality for UI tests.
Definition: Base.php:224
$lng
This is how the factory for UI elements looks.
Definition: Factory.php:17
tree()
description: purpose: > Trees present hierarchically structured data.
Definition: Base.php:106
chart()
description: purpose: > Charts are used to graphically represent data in various forms such as maps...
Definition: Base.php:88
panel()
description: purpose: > Panels are used to group titled content.
Definition: Base.php:58
manipulateRendering($component, Renderer $root)
Definition: Base.php:189
legacy($content)
description: purpose: > This component is used to wrap an existing ILIAS UI element into a UI compon...
Definition: Base.php:55
input()
description: purpose: > In opposite to components with a purely receptive or at most navigational ch...
Definition: Base.php:91
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:326
modal()
description: purpose: The Modal forces users to focus on the task at hand.
Definition: Base.php:61
Provides methods to interface with javascript.
dropdown()
description: purpose: > Dropdowns reveal a list of interactions that change the system’s status or ...
Definition: Base.php:76
menu()
description: purpose: > Menus let the user choose from several (navigational) options.
Definition: Base.php:109
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:346
getTemplateFactory()
Definition: Base.php:241
image()
description: purpose: The Image component is used to display images of various sources.
Definition: Base.php:52
addOnLoadCode($code)
Add some JavaScript-statements to the on-load handler of the page.
Definition: Base.php:159
getTemplate($path, $purge_unfilled_vars, $purge_unused_blocks)
Get template instance.
Definition: Base.php:29
getResourceRegistry()
Definition: Base.php:246
listing()
description: purpose: > Listings are used to structure itemised textual information.
Definition: Base.php:49
_getRendererFor(IComponent $component)
Definition: Base.php:170
language handling
table()
description: purpose: > Tables present a set of uniformly structured data.
Definition: Base.php:94
createId()
Create a fresh unique id.
Definition: Base.php:151
button()
description: purpose: > Buttons trigger interactions that change the system’s or view&#39;s status...
Definition: Base.php:40
txt($a_topic, $a_default_lang_fallback_mod="")
Definition: Base.php:133
loadLanguageModule($lang_module)
Definition: Base.php:142
Interface for a factory that provides templates.
divider()
description: purpose: > A divider marks a thematic change in a sequence of other components...
Definition: Base.php:70
counter()
description: purpose: > Counter inform users about the quantity of items indicated by a glyph...
Definition: Base.php:37
popover()
description: purpose: > Popovers can be used when space is scarce i.e.
Definition: Base.php:67