ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ComponentRendererLoaderResourceRegistryWrapperTest.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 
7 {
8  public function test_forwards_from_underlying()
9  {
10  $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
11  ->setMethods(["getRendererFor", "getRendererFactoryFor"])
12  ->getMock();
13 
14  $renderer = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\ComponentRenderer::class)
15  ->setMethods(["registerResources", "render"])
16  ->getMock();
17  $component = $this->getMockBuilder(\ILIAS\UI\Component\Component::class)->getMock();
18  $context = ["a", "b"];
19  $underlying
20  ->expects($this->once())
21  ->method("getRendererFor")
22  ->with($component, $context)
23  ->willReturn($renderer);
24 
25  $registry = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\ResourceRegistry::class)
26  ->getMock();
27 
28  $l = new \ILIAS\UI\Implementation\Render\LoaderResourceRegistryWrapper($registry, $underlying);
29  $r = $l->getRendererFor($component, $context);
30 
31  $this->assertSame($renderer, $r);
32  }
33 
34  public function test_registerResources()
35  {
36  $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
37  ->setMethods(["getRendererFor", "getRendererFactoryFor"])
38  ->getMock();
39 
40  $renderer = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\ComponentRenderer::class)
41  ->setMethods(["registerResources", "render"])
42  ->getMock();
43  $component = $this->getMockBuilder(\ILIAS\UI\Component\Component::class)->getMock();
44  $underlying
45  ->expects($this->once())
46  ->method("getRendererFor")
47  ->with($component, [])
48  ->willReturn($renderer);
49 
50  $registry = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\ResourceRegistry::class)
51  ->getMock();
52 
53  $renderer
54  ->expects($this->once())
55  ->method("registerResources")
56  ->with($registry);
57 
58  $l = new \ILIAS\UI\Implementation\Render\LoaderResourceRegistryWrapper($registry, $underlying);
59  $r = $l->getRendererFor($component, []);
60  }
61 
63  {
64  $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
65  ->setMethods(["getRendererFor", "getRendererFactoryFor"])
66  ->getMock();
67 
68  $c1 = $this->createMock(\ILIAS\UI\Component\Component::class);
69 
70  $factory = "FACTORY";
71  $underlying
72  ->expects($this->exactly(1))
73  ->method("getRendererFactoryFor")
74  ->with($c1)
75  ->willReturn($factory);
76 
77  $l = new \ILIAS\UI\Implementation\Render\LoaderCachingWrapper($underlying);
78 
79  $this->assertSame($factory, $l->getRendererFactoryFor($c1));
80  }
81 }
$context
Definition: webdav.php:25
Class Factory.
Class BaseForm.
$factory
Definition: metadata.php:43
$r
Definition: example_031.php:79
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
global $l
Definition: afr.php:30