ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ComponentRendererFSLoaderTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/TestComponent.php");
22 
30 
32 {
36  private $glyph_renderer;
40  private $icon_renderer;
41 
42  protected function getComponentRendererFSLoader(): FSLoader
43  {
44  $ui_factory = $this->getMockBuilder(ILIAS\UI\Implementation\FactoryInternal::class)->disableOriginalConstructor()->getMock();
45  $tpl_factory = $this->getMockBuilder(I\Render\TemplateFactory::class)->getMock();
46  $lng = $this->getMockBuilder(ILIAS\Language\Language::class)->disableOriginalConstructor()->getMock();
47  $js_binding = $this->getMockBuilder(I\Render\JavaScriptBinding::class)->getMock();
48  $image_path_resolver = $this->getMockBuilder(ILIAS\UI\Implementation\Render\ImagePathResolver::class)
49  ->getMock();
50  $data_factory = $this->getMockBuilder(ILIAS\Data\Factory::class)->getMock();
51  $help_text_retriever = $this->createMock(ILIAS\UI\HelpTextRetriever::class);
52  $upload_limit_resolver = $this->createMock(ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class);
53 
54  $default_renderer_factory = new I\Render\DefaultRendererFactory(
55  $ui_factory,
56  $tpl_factory,
57  $lng,
58  $js_binding,
59  $image_path_resolver,
60  $data_factory,
61  $help_text_retriever,
62  $upload_limit_resolver,
63  );
64  $this->glyph_renderer = $this->createMock(I\Render\RendererFactory::class);
65  $this->icon_renderer = $this->createMock(I\Render\RendererFactory::class);
66  $messagebox_renderer = $this->createMock(I\Render\RendererFactory::class);
67  $form_renderer = $this->createMock(I\Render\RendererFactory::class);
68 
69  $field_renderer = $this->createMock(I\Render\RendererFactory::class);
70  return new FSLoader(
71  $default_renderer_factory,
72  $this->glyph_renderer,
73  $this->icon_renderer,
74  $field_renderer,
75  $messagebox_renderer,
76  $form_renderer,
77  );
78  }
79 
80  public function testGetRendererSuccessfully(): void
81  {
82  // There should be a renderer for Glyph...
84  $component = new I\Component\Button\Standard("", "");
85  $r = $f->getRendererFor($component, []);
86  $this->assertInstanceOf(I\Render\ComponentRenderer::class, $r);
87  }
88 
89  public function testGetRendererSuccessfullyExtra(): void
90  {
91  // There should be a renderer for Glyph...
93  $component = new I\Component\Symbol\Glyph\Glyph("up", "up");
94  $context = $this->createMock(Component::class);
95  $renderer = $this->createMock(I\Render\ComponentRenderer::class);
96 
97  $context_name = "foo";
98  $context
99  ->expects($this->once())
100  ->method("getCanonicalName")
101  ->willReturn($context_name);
102 
103  $this->glyph_renderer
104  ->expects($this->once())
105  ->method("getRendererInContext")
106  ->with($component, [$context_name])
107  ->willReturn($renderer);
108 
109  $r = $f->getRendererFor($component, [$context]);
110 
111  $this->assertEquals($renderer, $r);
112  }
113 
114  public function testGetRendererUsesRendererFactory(): void
115  {
116  $loader = $this->getMockBuilder(ILIAS\UI\Implementation\Render\FSLoader::class)
117  ->onlyMethods(["getRendererFactoryFor", "getContextNames"])
118  ->disableOriginalConstructor()
119  ->getMock();
120  $factory = $this->getMockBuilder(ILIAS\UI\Implementation\Render\RendererFactory::class)
121  ->getMock();
122 
123  $rendered_component = $this->createMock(ILIAS\UI\Component\Component::class);
124 
125  $component1 = $this->createMock(ILIAS\UI\Component\Component::class);
126  $component2 = $this->createMock(ILIAS\UI\Component\Component::class);
127  $component_name1 = "COMPONENT 1";
128  $component_name2 = "COMPONENT 2";
129 
130  $loader
131  ->expects($this->once())
132  ->method("getContextNames")
133  ->with([$component1, $component2])
134  ->willReturn([$component_name1, $component_name2]);
135 
136  $loader
137  ->expects($this->once())
138  ->method("getRendererFactoryFor")
139  ->with($rendered_component)
140  ->willReturn($factory);
141 
142  $renderer = $this->createMock(ComponentRenderer::class);
143  $factory
144  ->expects($this->once())
145  ->method("getRendererInContext")
146  ->with($rendered_component, [$component_name1, $component_name2])
147  ->willReturn($renderer);
148 
149  $renderer2 = $loader->getRendererFor($rendered_component, [$component1, $component2]);
150  $this->assertEquals($renderer, $renderer2);
151  }
152 }
$renderer
$context
Definition: webdav.php:31
Loads renderers for components from the file system.
Definition: FSLoader.php:41
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
$r