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