ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
DefaultRendererTest.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
5namespace ILIAS\UI\Test {
6 require_once("libs/composer/vendor/autoload.php");
7
8
9use \ILIAS\UI\Implementation\Render\ResourceRegistry;
10use \ILIAS\UI\Renderer as DefaultRenderer;
11use \ILIAS\UI\Component\Component;
12
14 public function __construct($text) {
15 $this->text = $text;
16 }
17}
18
20 public function render(Component $component, DefaultRenderer $default_renderer) {
21 return $component->text;
22 }
23
24 public function registerResources(ResourceRegistry $registry) {
25 $registry->register("test.js");
26 }
27}
28
29} // namespace \ILIAS\UI\Test
30
31namespace {
32
33require_once("libs/composer/vendor/autoload.php");
34 require_once(__DIR__."/../Base.php");
35
36use \ILIAS\UI\Component as C;
37use \ILIAS\UI\Implementation\Glyph\Renderer as GlyphRenderer;
38
41 // There should be a renderer for Glyph...
42 $dr = $this->getDefaultRenderer();
43 $r = $dr->instantiateRendererFor("\\ILIAS\\UI\\Implementation\\Component\\Glyph\\Glyph");
44 $this->assertInstanceOf("\\ILIAS\\UI\\Implementation\\Render\\ComponentRenderer", $r);
45 }
46
48 // There should be a renderer for Glyph...
49 $dr = $this->getDefaultRenderer();
50 $r = $dr->getRendererFor("\\ILIAS\\UI\\Implementation\\Component\\Glyph\\Glyph");
51 $this->assertInstanceOf("\\ILIAS\\UI\\Implementation\\Render\\ComponentRenderer", $r);
52 }
53
54 public function test_getRenderer_caching() {
55 $dr = $this->getDefaultRenderer();
56 $r1 = $dr->getRendererFor("\\ILIAS\\UI\\Implementation\\Component\\Glyph\\Glyph");
57 $r2 = $dr->getRendererFor("\\ILIAS\\UI\\Implementation\\Component\\Glyph\\Glyph");
58 $this->assertTrue($r1 === $r2, "Instances not equal");
59 }
60
61 public function test_getRendererNameFor() {
62 $dr = $this->getDefaultRenderer();
63
64 $renderer_class = $dr->getRendererNameFor("\\ILIAS\\UI\\Implementation\\Component\\Glyph\\Glyph");
65 $expected = "\\ILIAS\\UI\\Implementation\\Component\\Glyph\\Renderer";
66 $this->assertEquals($expected, $renderer_class);
67 }
68
69 public function getResourceRegistry() {
70 $this->resource_registry = parent::getResourceRegistry();
71 return $this->resource_registry;
72 }
73
74 public function test_invokesRegistry() {
75 $dr = $this->getDefaultRenderer();
76 $component = new \ILIAS\UI\Test\TestComponent("foo");
77
78 $dr->render($component);
79
80 $this->assertEquals(array("test.js"), $this->resource_registry->resources);
81 }
82}
83
84} // root namespace
An exception for terminatinating execution or to throw for unit testing.
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
render(Component $component, DefaultRenderer $default_renderer)
Provides common functionality for UI tests.
Definition: Base.php:69
$text
$r
Definition: example_031.php:79
A component is the most general form of an entity in the UI.
Definition: Component.php:13
An entity that renders components to a string output.
Registry for resources required by rendered output like Javascript or CSS.