ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
StandardPageTest.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
38use ILIAS\Data\Factory as DataFactory;
39
44{
47 protected MainBar $mainbar;
48 protected MetaBar $metabar;
50 protected Image $logo;
53 protected string $title;
54
58 protected array $contents;
59
60 public function setUp(): void
61 {
62 $sig_gen = new SignalGenerator();
63 $this->metabar = $this->createMock(MetaBar::class);
64 $this->metabar->method("getCanonicalName")->willReturn("MetaBar Stub");
65 $this->mainbar = $this->createMock(MainBar::class);
66 $this->mainbar->method("getCanonicalName")->willReturn("MainBar Stub");
67 $this->crumbs = $this->createMock(Breadcrumbs::class);
68 $this->crumbs->method("getCanonicalName")->willReturn("Breadcrumbs Stub");
69 $this->logo = $this->createMock(Image::class);
70 $this->logo->method("getCanonicalName")->willReturn("Logo Stub");
71 $this->responsive_logo = $this->createMock(Image::class);
72 $this->responsive_logo->method("getCanonicalName")->willReturn("Responsive Logo Stub");
73 $this->overlay = $this->createMock(Container::class);
74 $this->overlay->method("getCanonicalName")->willReturn("Overlay Stub");
75 $this->contents = array(new Content('some content', $sig_gen));
76 $this->title = 'pagetitle';
77
78 $this->factory = new Page\Factory();
79 $this->stdpage = $this->factory->standard(
80 $this->contents,
81 $this->metabar,
82 $this->mainbar,
83 $this->crumbs,
84 $this->logo,
85 $this->responsive_logo,
86 'logo/favicon.ico',
87 $this->overlay,
88 null,
89 $this->title
90 );
91 }
92
93 public function testConstruction(): void
94 {
95 $this->assertInstanceOf(
96 "ILIAS\\UI\\Component\\Layout\\Page\\Standard",
97 $this->stdpage
98 );
99 }
100
101 public function testGetContent(): void
102 {
103 $this->assertEquals(
104 $this->contents,
105 $this->stdpage->getContent()
106 );
107 }
108
109 public function testGetMetabar(): void
110 {
111 $this->assertEquals(
112 $this->metabar,
113 $this->stdpage->getMetabar()
114 );
115 }
116
117 public function testGetMainbar(): void
118 {
119 $this->assertEquals(
120 $this->mainbar,
121 $this->stdpage->getMainbar()
122 );
123 }
124
125 public function testGetBreadcrumbs(): void
126 {
127 $this->assertEquals(
128 $this->crumbs,
129 $this->stdpage->getBreadcrumbs()
130 );
131 }
132
133 public function testGetLogo(): void
134 {
135 $this->assertEquals(
136 $this->logo,
137 $this->stdpage->getLogo()
138 );
139 }
140
141 public function testHasLogo(): void
142 {
143 $this->assertTrue($this->stdpage->hasLogo());
144 }
145
146 public function testGetResponsiveLogo(): void
147 {
148 $this->assertEquals(
149 $this->responsive_logo,
150 $this->stdpage->getResponsiveLogo()
151 );
152 }
153
154 public function testHasResponsiveLogo(): void
155 {
156 $this->assertTrue($this->stdpage->hasResponsiveLogo());
157 }
158
159 public function testWithFaviconPath(): void
160 {
161 $this->assertEquals("logo/favicon.ico", $this->stdpage->getFaviconPath());
162 $this->assertEquals(
163 "test",
164 $this->stdpage->withFaviconPath("test")->getFaviconPath()
165 );
166 }
167
168 public function testGetOverlay(): void
169 {
170 $this->assertEquals(
171 $this->overlay,
172 $this->stdpage->getOverlay()
173 );
174 }
175
176 public function testWithWrongContents(): void
177 {
178 $this->expectException(TypeError::class);
179 $this->stdpage = $this->factory->standard(
180 $this->metabar,
181 $this->mainbar,
182 'string is not allowed here',
183 $this->crumbs,
184 $this->logo
185 );
186 }
187
188 public function testGetTitle(): void
189 {
190 $this->assertEquals(
191 $this->title,
192 $this->stdpage->getTitle()
193 );
194 }
195
196 public function testWithTitle(): void
197 {
198 $title = 'some title';
199 $this->assertEquals(
200 $title,
201 $this->stdpage->withTitle($title)->getTitle()
202 );
203 }
204
205 public function testWithShortTitle(): void
206 {
207 $title = 'some short title';
208 $this->assertEquals(
209 $title,
210 $this->stdpage->withShortTitle($title)->getShortTitle()
211 );
212 }
213
214 public function testWithViewTitle(): void
215 {
216 $title = 'some view title';
217 $this->assertEquals(
218 $title,
219 $this->stdpage->withViewTitle($title)->getViewTitle()
220 );
221 }
222
223 public function testWithTextDirection(): void
224 {
225 $this->assertEquals("ltr", $this->stdpage->getTextDirection());
226 $this->assertEquals(
227 "rtl",
228 $this->stdpage
229 ->withTextDirection($this->stdpage::RTL)
230 ->getTextDirection()
231 );
232 }
233
234 public function testWithMetaDatum(): void
235 {
236 $meta_datum_html = 'test_html';
237 $meta_datum = $this->getMockedTag($meta_datum_html);
238 $this->assertEquals(
239 [$meta_datum],
240 $this->stdpage->withAdditionalMetaDatum($meta_datum)->getMetaData()
241 );
242 }
243
244 public function testRenderingWithTitle(): void
245 {
246 $this->stdpage = $this->stdpage
247 ->withTitle("Title")
248 ->withViewTitle("View Title")
249 ->withShortTitle("Short Title");
250
251 $r = $this->getDefaultRenderer(
252 null,
253 [$this->metabar, $this->mainbar, $this->crumbs, $this->logo, $this->overlay]
254 );
255 $html = $this->brutallyTrimHTML($r->render($this->stdpage));
256
257 $exptected = $this->brutallyTrimHTML(
258 '<!DOCTYPE html>
259<html lang="en" dir="ltr">
260
261<head>
262 <meta charset="utf-8" />
263 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
264 <meta name="viewport" content="width=device-width, initial-scale=1" />
265 <title>View Title: Short Title</title>
266 <link rel="icon" href="logo/favicon.ico" type="image/x-icon">
267 <script type="application/javascript">var il = il ||{}; window.il = il;</script>
268 <style></style>
269</head>
270
271<body class="c-layout__page">
272 <div class="il-page-overlay">Overlay Stub</div>
273 <div class="il-layout-page">
274 <header>
275 <div class="header-inner">
276 <div class="il-logo"><span class="hidden-xs">Logo Stub</span><span class="visible-xs-block">Responsive Logo Stub</span>
277 <div class="il-pagetitle">Title</div>
278 </div>MetaBar Stub
279 </div>
280 </header>
281 <div class="il-system-infos"></div>
282 <div class="nav il-maincontrols">MainBar Stub</div>
283 <main class="il-layout-page-content">some content</main>
284 </div>
285 <script>il.Util.addOnLoad(function() {});</script>
286</body>
287
288</html>'
289 );
290 $this->assertEquals($exptected, $html);
291 }
292
293 public function testRenderingWithRtlLanguage(): void
294 {
295 $this->stdpage = $this->stdpage->withTextDirection($this->stdpage::RTL);
296
297 $r = $this->getDefaultRenderer(
298 null,
299 [$this->metabar, $this->mainbar, $this->crumbs, $this->logo, $this->overlay]
300 );
301 $html = $this->brutallyTrimHTML($r->render($this->stdpage));
302
303 $exptected = $this->brutallyTrimHTML(
304 '<!DOCTYPE html>
305<html lang="en" dir="rtl">
306
307<head>
308 <meta charset="utf-8" />
309 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
310 <meta name="viewport" content="width=device-width, initial-scale=1" />
311 <title>:</title>
312 <link rel="icon" href="logo/favicon.ico" type="image/x-icon">
313 <script type="application/javascript">var il = il ||{}; window.il = il;</script>
314 <style></style>
315</head>
316
317<body class="c-layout__page">
318 <div class="il-page-overlay">Overlay Stub</div>
319 <div class="il-layout-page">
320 <header>
321 <div class="header-inner">
322 <div class="il-logo"><span class="hidden-xs">Logo Stub</span><span class="visible-xs-block">Responsive Logo Stub</span>
323 <div class="il-pagetitle">pagetitle</div>
324 </div>MetaBar Stub
325 </div>
326 </header>
327 <div class="il-system-infos"></div>
328 <div class="nav il-maincontrols">MainBar Stub</div>
329 <main class="il-layout-page-content">some content</main>
330 </div>
331 <script>il.Util.addOnLoad(function() {});</script>
332</body>
333
334</html>'
335 );
336 $this->assertEquals($exptected, $html);
337 }
338
339 public function testRenderingWithMetaData(): void
340 {
341 $meta_datum_1_html = 'test_html_1';
342 $meta_datum_2_html = 'test_html_2';
343 $meta_datum_1 = $this->getMockedTag($meta_datum_1_html);
344 $meta_datum_2 = $this->getMockedTag($meta_datum_2_html);
345
346 $this->stdpage = $this->stdpage->withAdditionalMetaDatum($meta_datum_1);
347 $this->stdpage = $this->stdpage->withAdditionalMetaDatum($meta_datum_2);
348
349 $r = $this->getDefaultRenderer(
350 null,
351 [$this->metabar, $this->mainbar, $this->crumbs, $this->logo, $this->overlay]
352 );
353 $html = $this->brutallyTrimHTML($r->render($this->stdpage));
354 $expected = $this->brutallyTrimHTML(
355 '
356<!DOCTYPE html>
357<html lang="en" dir="ltr">
358
359<head>
360 <meta charset="utf-8" />
361 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
362 <meta name="viewport" content="width=device-width, initial-scale=1" />
363' . $meta_datum_1_html . $meta_datum_2_html . '
364 <title>:</title>
365 <link rel="icon" href="logo/favicon.ico" type="image/x-icon">
366 <script type="application/javascript">var il = il ||{}; window.il = il;</script>
367 <style></style>
368</head>
369
370<body class="c-layout__page">
371 <div class="il-page-overlay">Overlay Stub</div>
372 <div class="il-layout-page">
373 <header>
374 <div class="header-inner">
375 <div class="il-logo"><span class="hidden-xs">Logo Stub</span><span class="visible-xs-block">Responsive Logo Stub</span>
376 <div class="il-pagetitle">pagetitle</div>
377 </div>MetaBar Stub
378 </div>
379 </header>
380 <div class="il-system-infos"></div>
381 <div class="nav il-maincontrols">MainBar Stub</div>
382 <main class="il-layout-page-content">some content</main>
383 </div>
384 <script>il.Util.addOnLoad(function() {});</script>
385</body>
386
387</html>'
388 );
389 $this->assertEquals($expected, $html);
390 }
391
392 public function getUIFactory(): NoUIFactory
393 {
394 return new class () extends NoUIFactory {
395 public function button(): Button\Factory
396 {
397 return new Button\Factory();
398 }
399
400 public function dropdown(): Dropdown\Factory
401 {
402 return new Dropdown\Factory();
403 }
404 };
405 }
406
407 public function getDataFactory(): DataFactory
408 {
409 return new DataFactory();
410 }
411
412 public function testRenderingWithCrumbs(): void
413 {
414 $crumbs = new Crumbs([
415 new CrumbEntry("label1", '#'),
416 new CrumbEntry("label2", '#'),
417 new CrumbEntry("label3", '#')
418 ]);
419 $r = $this->getDefaultRenderer(null, [$this->metabar, $this->mainbar, $this->logo, $this->overlay]);
420
421 $stdpage = $this->factory->standard(
422 $this->contents,
423 $this->metabar,
424 $this->mainbar,
425 $crumbs,
426 $this->logo,
427 $this->responsive_logo,
428 'logo/favicon.ico',
429 $this->overlay,
430 null,
431 $this->title
432 );
433
434 $html = $this->brutallyTrimHTML($r->render($stdpage));
435
436 $exptected = $this->brutallyTrimHTML(
437 '<!DOCTYPE html>
438<html lang="en" dir="ltr">
439
440<head>
441 <meta charset="utf-8" />
442 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
443 <meta name="viewport" content="width=device-width, initial-scale=1" />
444 <title>:</title>
445 <link rel="icon" href="logo/favicon.ico" type="image/x-icon">
446 <script type="application/javascript">var il = il ||{}; window.il = il;</script>
447 <style></style>
448</head>
449
450<body class="c-layout__page">
451 <div class="il-page-overlay">Overlay Stub</div>
452 <div class="il-layout-page">
453 <header>
454 <div class="header-inner">
455 <div class="il-logo"><span class="hidden-xs">Logo Stub</span><span class="visible-xs-block">Responsive Logo Stub</span>
456 <div class="il-pagetitle">pagetitle</div>
457 </div>
458 <nav class="il-header-locator">
459 <div class="dropdown" id="id_3"><button class="btn btn-default dropdown-toggle" type="button" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_menu">label3<span class="caret"></span></button>
460 <ul id="id_3_menu" class="dropdown-menu">
461 <li><button class="btn btn-link" data-action="#" id="id_1">label2</button></li>
462 <li><button class="btn btn-link" data-action="#" id="id_2">label1</button></li>
463 </ul>
464 </div>
465 </nav>MetaBar Stub
466 </div>
467 </header>
468 <div class="il-system-infos"></div>
469 <div class="nav il-maincontrols">MainBar Stub</div>
470 <main class="il-layout-page-content">
471 <div class="breadcrumbs">
472 <nav aria-label="breadcrumbs_aria_label" class="breadcrumb_wrapper">
473 <div class="breadcrumb"><span class="crumb"><a href="#">label1</a></span><span class="crumb"><a href="#">label2</a></span><span class="crumb"><a href="#">label3</a></span></div>
474 </nav>
475 </div>some content
476 </main>
477 </div>
478 <script>il.Util.addOnLoad(function() {});</script>
479</body>
480
481</html>'
482 );
483 $this->assertEquals($exptected, $html);
484 }
485
486 public function getMockedTag(string $html): Html\Tag
487 {
488 return new class ($html) extends Html\Tag {
489 public function __construct(
490 protected string $html
491 ) {
492 }
493
494 public function toHtml(): string
495 {
496 return $this->html;
497 }
498 };
499 }
500}
factory()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Provides common functionality for UI tests.
Definition: Base.php:337
Tests for the Standard Page.
Page Factory $factory
getMockedTag(string $html)
Page Standard $stdpage
This describes the MainBar.
Definition: MainBar.php:34
This describes the MetaBar.
Definition: MetaBar.php:33
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
button(string $caption, string $cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21