ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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;
8 
10 {
11  public function _instantiateRendererFor($class)
12  {
13  return $this->instantiateRendererFor($class);
14  }
15 }
16 
18 {
19  protected function getComponentRendererFSLoader()
20  {
21  $ui_factory = $this->getMockBuilder(ILIAS\UI\Factory::class)->getMock();
22  $tpl_factory = $this->getMockBuilder(I\Render\TemplateFactory::class)->getMock();
23  $lng = $this->getMockBuilder(\ilLanguage::class)->disableOriginalConstructor()->getMock();
24  $js_binding = $this->getMockBuilder(I\Render\JavaScriptBinding::class)->getMock();
25  $default_renderer_factory = new I\Render\DefaultRendererFactory($ui_factory, $tpl_factory, $lng, $js_binding);
26  $this->glyph_renderer = $this->createMock(I\Render\RendererFactory::class);
27  return new ComponentRendererFSLoaderTesting($default_renderer_factory, $this->glyph_renderer);
28  }
29 
31  {
32  // There should be a renderer for Glyph...
33  $f = $this->getComponentRendererFSLoader();
34  $component = new I\Component\Button\Standard("", "");
35  $r = $f->getRendererFor($component, []);
36  $this->assertInstanceOf(I\Render\ComponentRenderer::class, $r);
37  }
38 
40  {
41  // There should be a renderer for Glyph...
42  $f = $this->getComponentRendererFSLoader();
43  $component = new I\Component\Glyph\Glyph("up", "up");
44  $context = $this->createMock(\ILIAS\UI\Component\Component::class);
45  $renderer = $this->createMock(I\Render\ComponentRenderer::class);
46 
47  $context_name = "foo";
48  $context
49  ->expects($this->once())
50  ->method("getCanonicalName")
51  ->willReturn($context_name);
52 
53  $this->glyph_renderer
54  ->expects($this->once())
55  ->method("getRendererInContext")
56  ->with($component, [$context_name])
57  ->willReturn($renderer);
58 
59  $r = $f->getRendererFor($component, [$context]);
60 
61  $this->assertEquals($renderer, $r);
62  }
63 
65  {
66  $loader = $this->getMockBuilder(ILIAS\UI\Implementation\Render\FSLoader::class)
67  ->setMethods(["getRendererFactoryFor", "getContextNames"])
68  ->disableOriginalConstructor()
69  ->getMock();
70  $factory = $this->getMockBuilder(ILIAS\UI\Implementation\RendererFactory::class)
71  ->setMethods(["getRendererInContext"])
72  ->getMock();
73 
74  $rendered_component = $this->createMock(ILIAS\UI\Component\Component::class);
75 
76  $component1 = $this->createMock(ILIAS\UI\Component\Component::class);
77  $component2 = $this->createMock(ILIAS\UI\Component\Component::class);
78  $component_name1 = "COMPONENT 1";
79  $component_name2 = "COMPONENT 2";
80 
81  $loader
82  ->expects($this->once())
83  ->method("getContextNames")
84  ->with([$component1, $component2])
85  ->willReturn([$component_name1, $component_name2]);
86 
87  $loader
88  ->expects($this->once())
89  ->method("getRendererFactoryFor")
90  ->with($rendered_component)
91  ->willReturn($factory);
92 
93  $renderer = "RENDERER";
94  $factory
95  ->expects($this->once())
96  ->method("getRendererInContext")
97  ->with($rendered_component, [$component_name1, $component_name2])
98  ->willReturn($renderer);
99 
100  $renderer2 = $loader->getRendererFor($rendered_component, [$component1, $component2]);
101  $this->assertEquals($renderer, $renderer2);
102  }
103 }
$context
Definition: webdav.php:25
Class Factory.
Loads renderers for components from the file system.
Definition: FSLoader.php:20
Class BaseForm.
$factory
Definition: metadata.php:43
$r
Definition: example_031.php:79
$lng
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.