ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ComponentRendererLoaderCachingWrapperTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
28 
30 {
31  public function test_forwards_from_underlying(): void
32  {
33  $underlying = $this->getMockBuilder(Loader::class)
34  ->onlyMethods(["getRendererFor", "getRendererFactoryFor"])
35  ->getMock();
36 
37  $renderer = $this->createMock(ComponentRenderer::class);
38  $component = $this->getMockBuilder(Component::class)->getMock();
39  $context = [new TestComponent("foo")];
40  $underlying
41  ->expects($this->once())
42  ->method("getRendererFor")
43  ->with($component, $context)
44  ->willReturn($renderer);
45 
46  $l = new LoaderCachingWrapper($underlying);
47  $r = $l->getRendererFor($component, $context);
48 
49  $this->assertSame($renderer, $r);
50  }
51 
52  public function test_caches(): void
53  {
54  $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
55  ->onlyMethods(["getRendererFor", "getRendererFactoryFor"])
56  ->getMock();
57 
58  $renderer = $this->createMock(ComponentRenderer::class);
59  $component = $this->getMockBuilder(Component::class)->getMock();
60  $underlying
61  ->expects($this->once())
62  ->method("getRendererFor")
63  ->with($component, [])
64  ->willReturn($renderer);
65 
66  $l = new LoaderCachingWrapper($underlying);
67  $r1 = $l->getRendererFor($component, []);
68  $r2 = $l->getRendererFor($component, []);
69 
70  $this->assertSame($renderer, $r1);
71  $this->assertSame($renderer, $r2);
72  }
73 
74  public function test_caching_respects_contexts(): void
75  {
76  $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
77  ->onlyMethods(["getRendererFor", "getRendererFactoryFor"])
78  ->getMock();
79 
80  $renderer1 = $this->createMock(ComponentRenderer::class);
81  $renderer2 = $this->createMock(ComponentRenderer::class);
82  $c1 = $this->getMockBuilder(Component::class)->getMock();
83  $c2 = new TestComponent("foo");
84  $underlying
85  ->expects($this->exactly(2))
86  ->method("getRendererFor")
87  ->withConsecutive([$c1, [] ], [$c1, [$c2]])
88  ->will($this->onConsecutiveCalls($renderer1, $renderer2));
89 
90  $l = new LoaderCachingWrapper($underlying);
91  $r1 = $l->getRendererFor($c1, []);
92  $r2 = $l->getRendererFor($c1, [$c2]);
93  $r3 = $l->getRendererFor($c1, [$c2]);
94  $r4 = $l->getRendererFor($c1, []);
95 
96  $this->assertSame($renderer1, $r1);
97  $this->assertSame($renderer2, $r2);
98  $this->assertSame($renderer2, $r3);
99  $this->assertSame($renderer1, $r4);
100  }
101 
102  public function test_passthrough_getRendererFactory(): void
103  {
104  $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
105  ->onlyMethods(["getRendererFor", "getRendererFactoryFor"])
106  ->getMock();
107 
108  $c1 = $this->createMock(Component::class);
109 
110  $factory = $this->createMock(RendererFactory::class);
111  $underlying
112  ->expects($this->exactly(1))
113  ->method("getRendererFactoryFor")
114  ->with($c1)
115  ->willReturn($factory);
116 
117  $l = new LoaderCachingWrapper($underlying);
118 
119  $this->assertSame($factory, $l->getRendererFactoryFor($c1));
120  }
121 }
$context
Definition: webdav.php:29
Class Factory.
Class ChatMainBarProvider .
Caches renderers loaded by another loader.
$factory
Definition: metadata.php:75