ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ComponentRendererLoaderResourceRegistryWrapperTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
29
31{
32 public function testForwardsFromUnderlying(): void
33 {
34 $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
35 ->onlyMethods(["getRendererFor", "getRendererFactoryFor"])
36 ->getMock();
37
38 $renderer = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\ComponentRenderer::class)
39 ->onlyMethods(["registerResources", "render"])
40 ->getMock();
41 $component = $this->getMockBuilder(Component::class)->getMock();
42 $context = ["a", "b"];
43 $underlying
44 ->expects($this->once())
45 ->method("getRendererFor")
46 ->with($component, $context)
47 ->willReturn($renderer);
48
49 $registry = $this->getMockBuilder(ResourceRegistry::class)
50 ->getMock();
51
52 $l = new LoaderResourceRegistryWrapper($registry, $underlying);
53 $r = $l->getRendererFor($component, $context);
54
55 $this->assertSame($renderer, $r);
56 }
57
58 public function testRegisterResources(): void
59 {
60 $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
61 ->onlyMethods(["getRendererFor", "getRendererFactoryFor"])
62 ->getMock();
63
64 $renderer = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\ComponentRenderer::class)
65 ->onlyMethods(["registerResources", "render"])
66 ->getMock();
67 $component = $this->getMockBuilder(Component::class)->getMock();
68 $underlying
69 ->expects($this->once())
70 ->method("getRendererFor")
71 ->with($component, [])
72 ->willReturn($renderer);
73
74 $registry = $this->getMockBuilder(ResourceRegistry::class)
75 ->getMock();
76
78 ->expects($this->once())
79 ->method("registerResources")
80 ->with($registry);
81
82 $l = new LoaderResourceRegistryWrapper($registry, $underlying);
83 $l->getRendererFor($component, []);
84 }
85
86 public function testPassthroughGetRendererFactory(): void
87 {
88 $underlying = $this->getMockBuilder(\ILIAS\UI\Implementation\Render\Loader::class)
89 ->onlyMethods(["getRendererFor", "getRendererFactoryFor"])
90 ->getMock();
91
92 $c1 = $this->createMock(Component::class);
93
94 $factory = $this->createMock(RendererFactory::class);
95 $underlying
96 ->expects($this->exactly(1))
97 ->method("getRendererFactoryFor")
98 ->with($c1)
99 ->willReturn($factory);
100
101 $l = new LoaderCachingWrapper($underlying);
102
103 $this->assertSame($factory, $l->getRendererFactoryFor($c1));
104 }
105}
$renderer
Caches renderers loaded by another loader.
Registers resources for retreived renderers at a ResourceRegistry.
A component is the most general form of an entity in the UI.
Definition: Component.php:28
An entity that renders components to a string output.
Loads renderers for components.
Definition: Loader.php:30
This is the interface that components should use if they want to load specific renderers.
Registry for resources required by rendered output like Javascript or CSS.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$context
Definition: webdav.php:31