ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ComponentRendererFSLoaderTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once(__DIR__ . "/TestComponent.php");
6 
7 use \ILIAS\UI\Implementation as I;
9 
11 {
12  public function _instantiateRendererFor($class)
13  {
14  return $this->instantiateRendererFor($class);
15  }
16 }
17 
19 {
20  protected function getComponentRendererFSLoader()
21  {
22  $ui_factory = $this->getMockBuilder(ILIAS\UI\Factory::class)->getMock();
23  $tpl_factory = $this->getMockBuilder(I\Render\TemplateFactory::class)->getMock();
24  $lng = $this->getMockBuilder(\ilLanguage::class)->disableOriginalConstructor()->getMock();
25  $js_binding = $this->getMockBuilder(I\Render\JavaScriptBinding::class)->getMock();
26  $refinery_mock = $this->getMockBuilder(\ILIAS\Refinery\Factory::class)
27  ->disableOriginalConstructor()
28  ->getMock();
29 
30  $default_renderer_factory = new I\Render\DefaultRendererFactory(
31  $ui_factory,
32  $tpl_factory,
33  $lng,
34  $js_binding,
35  $refinery_mock
36  );
37  $this->glyph_renderer = $this->createMock(I\Render\RendererFactory::class);
38  $this->field_renderer = $this->createMock(I\Render\RendererFactory::class);
39  return new ComponentRendererFSLoaderTesting($default_renderer_factory, $this->glyph_renderer, $this->field_renderer);
40  }
41 
43  {
44  // There should be a renderer for Glyph...
45  $f = $this->getComponentRendererFSLoader();
46  $component = new I\Component\Button\Standard("", "");
47  $r = $f->getRendererFor($component, []);
48  $this->assertInstanceOf(I\Render\ComponentRenderer::class, $r);
49  }
50 
52  {
53  // There should be a renderer for Glyph...
54  $f = $this->getComponentRendererFSLoader();
55  $component = new I\Component\Symbol\Glyph\Glyph("up", "up");
56  $context = $this->createMock(\ILIAS\UI\Component\Component::class);
57  $renderer = $this->createMock(I\Render\ComponentRenderer::class);
58 
59  $context_name = "foo";
60  $context
61  ->expects($this->once())
62  ->method("getCanonicalName")
63  ->willReturn($context_name);
64 
65  $this->glyph_renderer
66  ->expects($this->once())
67  ->method("getRendererInContext")
68  ->with($component, [$context_name])
69  ->willReturn($renderer);
70 
71  $r = $f->getRendererFor($component, [$context]);
72 
73  $this->assertEquals($renderer, $r);
74  }
75 
77  {
78  $loader = $this->getMockBuilder(ILIAS\UI\Implementation\Render\FSLoader::class)
79  ->setMethods(["getRendererFactoryFor", "getContextNames"])
80  ->disableOriginalConstructor()
81  ->getMock();
82  $factory = $this->getMockBuilder(ILIAS\UI\Implementation\RendererFactory::class)
83  ->setMethods(["getRendererInContext"])
84  ->getMock();
85 
86  $rendered_component = $this->createMock(ILIAS\UI\Component\Component::class);
87 
88  $component1 = $this->createMock(ILIAS\UI\Component\Component::class);
89  $component2 = $this->createMock(ILIAS\UI\Component\Component::class);
90  $component_name1 = "COMPONENT 1";
91  $component_name2 = "COMPONENT 2";
92 
93  $loader
94  ->expects($this->once())
95  ->method("getContextNames")
96  ->with([$component1, $component2])
97  ->willReturn([$component_name1, $component_name2]);
98 
99  $loader
100  ->expects($this->once())
101  ->method("getRendererFactoryFor")
102  ->with($rendered_component)
103  ->willReturn($factory);
104 
105  $renderer = "RENDERER";
106  $factory
107  ->expects($this->once())
108  ->method("getRendererInContext")
109  ->with($rendered_component, [$component_name1, $component_name2])
110  ->willReturn($renderer);
111 
112  $renderer2 = $loader->getRendererFor($rendered_component, [$component1, $component2]);
113  $this->assertEquals($renderer, $renderer2);
114  }
115 }
$context
Definition: webdav.php:26
Class Factory.
Class ChatMainBarProvider .
$lng
$factory
Definition: metadata.php:58