ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
FooterTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
24use PHPUnit\Framework\MockObject\MockObject;
27
29{
30 protected I\Link\Standard $link_mock;
31 protected I\Symbol\Icon\Icon $icon_mock;
32 protected I\Button\Shy $shy_mock;
33 protected I\Button\Standard $button_mock;
34 protected I\Listing\Unordered $unordered_mock;
35 protected I\Button\Factory $button_factory;
36 protected I\Link\Factory $link_factory;
37 protected I\Listing\Factory $listing_factory;
38 protected \ILIAS\Data\URI $uri_mock;
39 protected string $link_html;
40 protected string $icon_html;
41 protected string $shy_html;
42 protected string $button_html;
43 protected string $unordered_html;
44
45 protected function setUp(): void
46 {
47 $this->link_html = sha1(C\Link\Standard::class);
48 $this->icon_html = sha1(C\Symbol\Icon\Icon::class);
49 $this->shy_html = sha1(C\Button\Shy::class);
50 $this->button_html = sha1(C\Button\Standard::class);
51 $this->unordered_html = sha1(C\Listing\Unordered::class);
52
53 $this->link_mock = $this->createMock(I\Link\Standard::class);
54 $this->link_mock->method('getCanonicalName')->willReturn($this->link_html);
55
56 $this->icon_mock = $this->createMock(I\Symbol\Icon\Icon::class);
57 $this->icon_mock->method('getCanonicalName')->willReturn($this->icon_html);
58
59 $this->shy_mock = $this->createMock(I\Button\Shy::class);
60 $this->shy_mock->method('getCanonicalName')->willReturn($this->shy_html);
61
62 $this->button_mock = $this->createMock(I\Button\Standard::class);
63 $this->button_mock->method('getCanonicalName')->willReturn($this->button_html);
64
65 $this->unordered_mock = $this->createMock(I\Listing\Unordered::class);
66 $this->unordered_mock->method('getCanonicalName')->willReturn($this->unordered_html);
67
68 $this->button_factory = $this->createMock(I\Button\Factory::class);
69 $this->button_factory->method('shy')->willReturn($this->shy_mock);
70 $this->button_factory->method('standard')->willReturn($this->button_mock);
71
72 $this->link_factory = $this->createMock(I\Link\Factory::class);
73 $this->link_factory->method('standard')->willReturn($this->link_mock);
74
75 $this->listing_factory = $this->createMock(I\Listing\Factory::class);
76 $this->listing_factory->method('unordered')->willReturn($this->unordered_mock);
77
78 $this->uri_mock = $this->createMock(\ILIAS\Data\URI::class);
79
80 parent::setUp();
81 }
82
83 public function testSetAndGetModalsWithTrigger(): void
84 {
85 $signal_mock = $this->createMock(C\Signal::class);
86
87 $modal_mock = $this->createMock(C\Modal\RoundTrip::class);
88 $modal_mock->method('getShowSignal')->willReturn($signal_mock);
89
91 $shy_mock->expects($this->once())->method('withOnClick')->with($signal_mock)->willReturnSelf();
92
93 $shy_mock = $shy_mock->withOnClick($modal_mock->getShowSignal());
94
96 $footer = $this->getUIFactory()->mainControls()->footer();
97 $footer = $footer->withAdditionalLink($shy_mock);
98 $footer = $footer->withAdditionalModal($modal_mock);
99
100 $this->assertCount(1, $footer->getModals());
101 $this->assertCount(1, $footer->getAdditionalLinks());
102 }
103
104 public function testRenderWithPermanentUrl(): void
105 {
106 $footer = $this->getUIFactory()->mainControls()->footer();
107 $footer = $footer->withPermanentURL($this->uri_mock);
108
109 $this->button_factory->expects($this->once())->method('standard')->with('copy_perma_link', '');
110 $this->button_mock->expects($this->once())->method('withAdditionalOnLoadCode')->willReturnSelf();
111
112 $renderer = $this->getDefaultRenderer(null, [$this->button_mock]);
113 $actual_html = $renderer->render($footer);
114
115 $expected_html = <<<EOT
116<footer class="c-maincontrols c-maincontrols__footer">
117 <section class="c-maincontrols__footer-grid" data-section="permanent-link" aria-label="footer_permanent_link" tabindex="0">
118 <div class="c-maincontrols__footer-grid__item text-left">
119 <div class="c-tooltip__container c-tooltip--top" aria-live="polite">
120 $this->button_html
121 <div class="c-tooltip c-tooltip--hidden" role="tooltip">
122 perma_link_copied
123 </div>
124 </div>
125 </div>
126 </section>
127</footer>
128EOT;
129
130 $this->assertEquals(
131 $this->brutallyTrimHTML($expected_html),
132 $this->brutallyTrimHTML($actual_html)
133 );
134 }
135
136 public function testRenderWithAdditionalLinkGroup(): void
137 {
138 $link_group_title = sha1('link_group_1');
139
140 $footer = $this->getUIFactory()->mainControls()->footer();
141 $footer = $footer->withAdditionalLinkGroup($link_group_title, [$this->link_mock]);
142
143 $this->listing_factory->expects($this->once())->method('unordered')->with([$this->link_mock]);
144
145 $renderer = $this->getDefaultRenderer(null, [$this->unordered_mock]);
146 $actual_html = $renderer->render($footer);
147
148 $expected_html = <<<EOT
149<footer class="c-maincontrols c-maincontrols__footer">
150 <section class="c-maincontrols__footer-grid" data-section="link-groups" aria-label="footer_link_groups" tabindex="0">
151 <div class="c-maincontrols__footer-grid__item text-left">
152 <strong>$link_group_title</strong>$this->unordered_html
153 </div>
154 </section>
155</footer>
156EOT;
157
158 $this->assertEquals(
159 $this->brutallyTrimHTML($expected_html),
160 $this->brutallyTrimHTML($actual_html)
161 );
162 }
163
164 public function testRenderWithAdditionalLink(): void
165 {
166 $footer = $this->getUIFactory()->mainControls()->footer();
167 $footer = $footer->withAdditionalLink($this->link_mock);
168
169 $renderer = $this->getDefaultRenderer(null, [$this->link_mock]);
170 $actual_html = $renderer->render($footer);
171
172 $expected_html = <<<EOT
173<footer class="c-maincontrols c-maincontrols__footer">
174 <section class="c-maincontrols__footer-grid" data-section="links" aria-label="footer_links" tabindex="0">
175 <div class="c-maincontrols__footer-grid__item text-left">$this->link_html</div>
176 </section>
177</footer>
178EOT;
179
180 $this->assertEquals(
181 $this->brutallyTrimHTML($expected_html),
182 $this->brutallyTrimHTML($actual_html)
183 );
184 }
185
186 public function testRenderWithAdditionalIcon(): void
187 {
188 $footer = $this->getUIFactory()->mainControls()->footer();
189 $footer = $footer->withAdditionalIcon($this->icon_mock);
190
191 $renderer = $this->getDefaultRenderer(null, [$this->icon_mock]);
192 $actual_html = $renderer->render($footer);
193
194 $expected_html = <<<EOT
195<footer class="c-maincontrols c-maincontrols__footer">
196 <section class="c-maincontrols__footer-grid" data-section="icons" aria-label="footer_icons" tabindex="0">
197 <div class="c-maincontrols__footer-grid__item l-bar__group">
198 <span class="l-bar__element">$this->icon_html</span>
199 </div>
200 </section>
201</footer>
202EOT;
203
204 $this->assertEquals(
205 $this->brutallyTrimHTML($expected_html),
206 $this->brutallyTrimHTML($actual_html)
207 );
208 }
209
210 public function testRenderWithAdditionalText(): void
211 {
212 $text = sha1('text_1');
213
214 $footer = $this->getUIFactory()->mainControls()->footer();
215 $footer = $footer->withAdditionalText($text);
216
217 $renderer = $this->getDefaultRenderer();
218 $actual_html = $renderer->render($footer);
219
220 $expected_html = <<<EOT
221<footer class="c-maincontrols c-maincontrols__footer">
222 <section class="c-maincontrols__footer-grid" data-section="texts" aria-label="footer_texts" tabindex="0">
223 <div class="c-maincontrols__footer-grid__item text-left">$text</div>
224 </section>
225</footer>
226EOT;
227
228 $this->assertEquals(
229 $this->brutallyTrimHTML($expected_html),
230 $this->brutallyTrimHTML($actual_html)
231 );
232 }
233
234 public function testRenderWithModalsAndTrigger(): void
235 {
236 $modal_html = sha1(C\Modal\RoundTrip::class);
237 $modal_mock = $this->createMock(C\Modal\RoundTrip::class);
238 $modal_mock->method('getCanonicalName')->willReturn($modal_html);
239 $modal_mock->method('getShowSignal')->willReturn(
240 $this->createMock(C\Signal::class)
241 );
242
244 $shy_mock->method('withOnClick')->willReturnSelf();
245
246 $shy_mock = $shy_mock->withOnClick($modal_mock->getShowSignal());
247
248 $footer = $this->getUIFactory()->mainControls()->footer();
249 $footer = $footer->withAdditionalLink($shy_mock);
250 $footer = $footer->withAdditionalModal($modal_mock);
251
252 $renderer = $this->getDefaultRenderer(null, [$modal_mock, $shy_mock]);
253 $actual_html = $renderer->render($footer);
254
255 $expected_html = <<<EOT
256<footer class="c-maincontrols c-maincontrols__footer">
257 <section class="c-maincontrols__footer-grid" data-section="links" aria-label="footer_links" tabindex="0">
258 <div class="c-maincontrols__footer-grid__item text-left">$this->shy_html</div>
259 </section>
260</footer>$modal_html
261EOT;
262
263 $this->assertEquals(
264 $this->brutallyTrimHTML($expected_html),
265 $this->brutallyTrimHTML($actual_html)
266 );
267 }
268
269 public function testRenderEmptyFooter(): void
270 {
271 $footer = $this->getUIFactory()->mainControls()->footer();
272
273 $renderer = $this->getDefaultRenderer();
274 $actual_html = $renderer->render($footer);
275
276 $expected_html = '';
277
278 $this->assertEquals($expected_html, $actual_html);
279 }
280
281 public function getUIFactory(): NoUIFactory
282 {
283 return new class (
284 $this->createMock(I\SignalGeneratorInterface::class),
285 $this->createMock(I\Counter\Factory::class),
286 $this->createMock(I\Symbol\Factory::class),
290 ) extends NoUIFactory {
291 public function __construct(
292 protected I\SignalGeneratorInterface $signal_generator,
293 protected I\Counter\Factory $counter_factory,
294 protected I\Symbol\Factory $symbol_factory,
295 protected I\Button\Factory $button_factory,
296 protected I\Link\Factory $link_factory,
297 protected I\Listing\Factory $listing_factory,
298 ) {
299 }
300 public function mainControls(): I\MainControls\Factory
301 {
302 return new I\MainControls\Factory(
303 $this->signal_generator,
304 new I\MainControls\Slate\Factory(
305 $this->signal_generator,
306 $this->counter_factory,
307 $this->symbol_factory,
308 ),
309 );
310 }
311 public function button(): I\Button\Factory
312 {
314 }
315 public function link(): I\Link\Factory
316 {
317 return $this->link_factory;
318 }
319 public function listing(): I\Listing\Factory
320 {
322 }
323 };
324 }
325}
$renderer
string $link_html
Definition: FooterTest.php:39
I Button Shy $shy_mock
Definition: FooterTest.php:32
I Link Factory $link_factory
Definition: FooterTest.php:36
I Listing Unordered $unordered_mock
Definition: FooterTest.php:34
string $button_html
Definition: FooterTest.php:42
testRenderWithAdditionalIcon()
Definition: FooterTest.php:186
testRenderWithAdditionalLink()
Definition: FooterTest.php:164
testRenderWithAdditionalText()
Definition: FooterTest.php:210
I Link Standard $link_mock
Definition: FooterTest.php:30
testRenderEmptyFooter()
Definition: FooterTest.php:269
I Button Standard $button_mock
Definition: FooterTest.php:33
testRenderWithAdditionalLinkGroup()
Definition: FooterTest.php:136
string $shy_html
Definition: FooterTest.php:41
I Button Factory $button_factory
Definition: FooterTest.php:35
I Symbol Icon Icon $icon_mock
Definition: FooterTest.php:31
testRenderWithModalsAndTrigger()
Definition: FooterTest.php:234
testRenderWithPermanentUrl()
Definition: FooterTest.php:104
I Listing Factory $listing_factory
Definition: FooterTest.php:37
string $icon_html
Definition: FooterTest.php:40
string $unordered_html
Definition: FooterTest.php:43
ILIAS Data URI $uri_mock
Definition: FooterTest.php:38
Provides common functionality for UI tests.
Definition: Base.php:337
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
button(string $caption, string $cmd)
link(string $caption, string $href, bool $new_viewport=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.