ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 require_once(__DIR__ . "/TestComponent.php");
6 require_once(__DIR__ . "/../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 use \ILIAS\UI\Implementation\DefaultRenderer;
10 use \ILIAS\UI\Implementation\Glyph\Renderer as GlyphRenderer;
11 
13 {
15  {
16  // There should be a renderer for Glyph...
17  $dr = $this->getDefaultRenderer();
18  $r = $dr->_getRendererFor(new \ILIAS\UI\Implementation\Component\Glyph\Glyph("up", "up"));
19  $this->assertInstanceOf(\ILIAS\UI\Implementation\Render\ComponentRenderer::class, $r);
20  }
21 
22  public function test_getRenderer_caching()
23  {
24  $dr = $this->getDefaultRenderer();
25  $r1 = $dr->_getRendererFor(new \ILIAS\UI\Implementation\Component\Glyph\Glyph("up", "up"));
26  $r2 = $dr->_getRendererFor(new \ILIAS\UI\Implementation\Component\Glyph\Glyph("up", "up"));
27  $this->assertTrue($r1 === $r2, "Instances not equal");
28  }
29 
30  public function getResourceRegistry()
31  {
32  $this->resource_registry = parent::getResourceRegistry();
33  return $this->resource_registry;
34  }
35 
36  public function test_invokesRegistry()
37  {
38  $dr = $this->getDefaultRenderer();
39  $component = new \ILIAS\UI\Component\Test\TestComponent("foo");
40 
41  $dr->render($component);
42 
43  $this->assertEquals(array("test.js"), $this->resource_registry->resources);
44  }
45 
47  {
48  $dr = $this->getDefaultRenderer();
49  $component = new \ILIAS\UI\Component\Test\TestComponent("foo");
50  $dr2 = $dr->withAdditionalContext($component);
51  $this->assertNotSame($dr, $dr2);
52  }
53 
54  public function test_getContexts()
55  {
56  $dr = $this->getDefaultRenderer();
57  $c1 = new \ILIAS\UI\Component\Test\TestComponent("foo");
58  $c2 = new \ILIAS\UI\Component\Test\TestComponent("bar");
59  $dr2 = $dr
60  ->withAdditionalContext($c1)
61  ->withAdditionalContext($c2);
62  $this->assertEquals([], $dr->_getContexts());
63  $this->assertEquals([$c1, $c2], $dr2->_getContexts());
64  }
65 
67  {
68  $loader = $this
69  ->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
70  ->setMethods(["getRendererFor", "getRendererFactoryFor"])
71  ->getMock();
72 
73  $renderer = new TestDefaultRenderer($loader);
74 
75  $c1 = new \ILIAS\UI\Component\Test\TestComponent("foo");
76  $c2 = new \ILIAS\UI\Component\Test\TestComponent("bar");
77 
78  $renderer = $renderer
79  ->withAdditionalContext($c1)
80  ->withAdditionalContext($c2);
81 
82  $loader
83  ->expects($this->once())
84  ->method("getRendererFor")
85  ->with($c1, [$c1, $c2]);
86 
87  $renderer->_getRendererFor($c1);
88  }
89 
90  public function test_render()
91  {
92  $c1 = new \ILIAS\UI\Component\Test\TestComponent("foo");
93  $renderer = $this->getDefaultRenderer();
94  $html = $renderer->render($c1);
95  $this->assertEquals("foo", $html);
96  }
97 
98  public function test_render_async_no_js()
99  {
100  $c1 = new \ILIAS\UI\Component\Test\TestComponent("foo");
101  $renderer = $this->getDefaultRenderer(
102  new \ILIAS\UI\Implementation\Render\ilJavaScriptBinding(
103  $this->getTemplateFactory()->getTemplate(false, false, false)
104  )
105  );
106  $html = $renderer->renderAsync($c1);
107  $this->assertEquals("foo", $html);
108  }
109 
110  public function test_render_async_with_js()
111  {
112  $c1 = new \ILIAS\UI\Component\Test\JSTestComponent("foo");
113  $renderer = $this->getDefaultRenderer(
114  new \ILIAS\UI\Implementation\Render\ilJavaScriptBinding($this->getTemplateFactory()->getTemplate(false, false, false))
115  );
116  $html = $renderer->renderAsync($c1);
117  $this->assertEquals('foo<script>id:foo.id content:foo</script>', $html);
118  }
119 
121  {
122  $c1 = new \ILIAS\UI\Component\Test\TestComponent("foo");
123  $c2 = new \ILIAS\UI\Component\Test\JSTestComponent("foo");
124  $renderer = $this->getDefaultRenderer(
125  new \ILIAS\UI\Implementation\Render\ilJavaScriptBinding($this->getTemplateFactory()->getTemplate(false, false, false))
126  );
127  $html = $renderer->renderAsync($c2);
128  $this->assertEquals('foo<script>id:foo.id content:foo</script>', $html);
129  $html = $renderer->renderAsync($c1);
130  $this->assertEquals("foo", $html);
131  $html = $renderer->renderAsync($c2);
132  $this->assertEquals('foo<script>id:foo.id content:foo</script>', $html);
133  }
134 
135  public function test_render_async_array()
136  {
137  $c1 = new \ILIAS\UI\Component\Test\TestComponent("foo");
138 
139  $renderer = $this->getDefaultRenderer(
140  new \ILIAS\UI\Implementation\Render\ilJavaScriptBinding($this->getTemplateFactory()->getTemplate(false, false, false))
141  );
142  $html = $renderer->renderAsync([$c1,$c1]);
143  $this->assertEquals('foofoo', $html);
144  }
145 }
Class Factory.
Class BaseForm.
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:177
Create styles array
The data for the language used.
getTemplateFactory()
Definition: Base.php:196
$html
Definition: example_001.php:87