ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ComponentRendererLoaderCachingWrapperTest.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 = new \stdClass();
15  $component = $this->getMockBuilder(\ILIAS\UI\Component\Component::class)->getMock();
16  $context = [new \ILIAS\UI\Component\Test\TestComponent("foo")];
17  $underlying
18  ->expects($this->once())
19  ->method("getRendererFor")
20  ->with($component, $context)
21  ->willReturn($renderer);
22 
23  $l = new \ILIAS\UI\Implementation\Render\LoaderCachingWrapper($underlying);
24  $r = $l->getRendererFor($component, $context);
25 
26  $this->assertSame($renderer, $r);
27  }
28 
29  public function test_caches()
30  {
31  $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
32  ->setMethods(["getRendererFor", "getRendererFactoryFor"])
33  ->getMock();
34 
35  $renderer = new \stdClass();
36  $component = $this->getMockBuilder(\ILIAS\UI\Component\Component::class)->getMock();
37  $underlying
38  ->expects($this->once())
39  ->method("getRendererFor")
40  ->with($component, [])
41  ->willReturn($renderer);
42 
43  $l = new \ILIAS\UI\Implementation\Render\LoaderCachingWrapper($underlying);
44  $r1 = $l->getRendererFor($component, []);
45  $r2 = $l->getRendererFor($component, []);
46 
47  $this->assertSame($renderer, $r1);
48  $this->assertSame($renderer, $r2);
49  }
50 
52  {
53  $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
54  ->setMethods(["getRendererFor", "getRendererFactoryFor"])
55  ->getMock();
56 
57  $renderer1 = new \stdClass();
58  $renderer2 = new \stdClass();
59  $c1 = $this->getMockBuilder(\ILIAS\UI\Component\Component::class)->getMock();
60  $c2 = new \ILIAS\UI\Component\Test\TestComponent("foo");
61  $underlying
62  ->expects($this->exactly(2))
63  ->method("getRendererFor")
64  ->withConsecutive([$c1, [] ], [$c1, [$c2]])
65  ->will($this->onConsecutiveCalls($renderer1, $renderer2));
66 
67  $l = new \ILIAS\UI\Implementation\Render\LoaderCachingWrapper($underlying);
68  $r1 = $l->getRendererFor($c1, []);
69  $r2 = $l->getRendererFor($c1, [$c2]);
70  $r3 = $l->getRendererFor($c1, [$c2]);
71  $r4 = $l->getRendererFor($c1, []);
72 
73  $this->assertSame($renderer1, $r1);
74  $this->assertSame($renderer2, $r2);
75  $this->assertSame($renderer2, $r3);
76  $this->assertSame($renderer1, $r4);
77  }
78 
80  {
81  $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
82  ->setMethods(["getRendererFor", "getRendererFactoryFor"])
83  ->getMock();
84 
85  $c1 = $this->createMock(\ILIAS\UI\Component\Component::class);
86 
87  $factory = "FACTORY";
88  $underlying
89  ->expects($this->exactly(1))
90  ->method("getRendererFactoryFor")
91  ->with($c1)
92  ->willReturn($factory);
93 
94  $l = new \ILIAS\UI\Implementation\Render\LoaderCachingWrapper($underlying);
95 
96  $this->assertSame($factory, $l->getRendererFactoryFor($c1));
97  }
98 }
Class Factory.
Class BaseForm.
$factory
Definition: metadata.php:47
$r
Definition: example_031.php:79
global $l
Definition: afr.php:30