ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
StandardPageTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once("libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 use \ILIAS\UI\Component\MainControls\MetaBar;
10 use \ILIAS\UI\Component\MainControls\MainBar;
11 use \ILIAS\UI\Component\Breadcrumbs\Breadcrumbs;
12 use \ILIAS\UI\Component\Image\Image;
13 use \ILIAS\UI\Implementation\Component\Layout\Page;
14 use \ILIAS\UI\Implementation\Component\Legacy\Legacy;
15 
20 {
24  protected $stdpage;
25 
29  protected $factory;
30 
34  protected $mainbar;
35 
39  protected $metabar;
40 
44  protected $crumbs;
45 
49  protected $logo;
50 
51  public function setUp() : void
52  {
53  $sig_gen = new \ILIAS\UI\Implementation\Component\SignalGenerator();
54  $this->metabar = $this->createMock(MetaBar::class);
55  $this->metabar->method("getCanonicalName")->willReturn("MetaBar Stub");
56  $this->mainbar = $this->createMock(MainBar::class);
57  $this->mainbar->method("getCanonicalName")->willReturn("MainBar Stub");
58  $this->crumbs = $this->createMock(Breadcrumbs::class);
59  $this->crumbs->method("getCanonicalName")->willReturn("Breadcrumbs Stub");
60  $this->logo = $this->createMock(Image::class);
61  $this->logo->method("getCanonicalName")->willReturn("Logo Stub");
62  $this->responsive_logo = $this->createMock(Image::class);
63  $this->responsive_logo->method("getCanonicalName")->willReturn("Responsive Logo Stub");
64  $this->contents = array(new Legacy('some content', $sig_gen));
65  $this->title = 'pagetitle';
66 
67  $this->factory = new Page\Factory();
68  $this->stdpage = $this->factory->standard(
69  $this->contents,
70  $this->metabar,
71  $this->mainbar,
72  $this->crumbs,
73  $this->logo,
74  null,
75  $this->title
76  )->withResponsiveLogo($this->responsive_logo);
77  }
78 
79  public function testConstruction() : void
80  {
81  $this->assertInstanceOf(
82  "ILIAS\\UI\\Component\\Layout\\Page\\Standard",
83  $this->stdpage
84  );
85  }
86 
87  public function testGetContent() : void
88  {
89  $this->assertEquals(
90  $this->contents,
91  $this->stdpage->getContent()
92  );
93  }
94 
95  public function testGetMetabar() : void
96  {
97  $this->assertEquals(
98  $this->metabar,
99  $this->stdpage->getMetabar()
100  );
101  }
102 
103  public function testGetMainbar() : void
104  {
105  $this->assertEquals(
106  $this->mainbar,
107  $this->stdpage->getMainbar()
108  );
109  }
110 
111  public function testGetBreadcrumbs() : void
112  {
113  $this->assertEquals(
114  $this->crumbs,
115  $this->stdpage->getBreadcrumbs()
116  );
117  }
118 
119  public function testGetLogo() : void
120  {
121  $this->assertEquals(
122  $this->logo,
123  $this->stdpage->getLogo()
124  );
125  }
126 
127  public function testHasLogo() : void
128  {
129  $this->assertTrue($this->stdpage->hasLogo());
130  }
131 
132  public function testGetResponsiveLogo() : void
133  {
134  $this->assertEquals(
135  $this->responsive_logo,
136  $this->stdpage->getResponsiveLogo()
137  );
138  }
139 
140  public function testHasResponsiveLogo() : void
141  {
142  $this->assertTrue($this->stdpage->hasResponsiveLogo());
143  }
144 
145  public function testWithWrongContents() : void
146  {
147  $this->expectException(TypeError::class);
148  $this->stdpage = $this->factory->standard(
149  $this->metabar,
150  $this->mainbar,
151  'string is not allowed here',
152  $this->crumbs,
153  $this->logo
154  );
155  }
156 
157  public function testGetTitle() : void
158  {
159  $this->assertEquals(
160  $this->title,
161  $this->stdpage->getTitle()
162  );
163  }
164 
165  public function testWithTitle() : void
166  {
167  $title = 'some title';
168  $this->assertEquals(
169  $title,
170  $this->stdpage->withTitle($title)->getTitle()
171  );
172  }
173  public function testWithShortTitle() : void
174  {
175  $title = 'some short title';
176  $this->assertEquals(
177  $title,
178  $this->stdpage->withShortTitle($title)->getShortTitle()
179  );
180  }
181  public function testWithViewTitle() : void
182  {
183  $title = 'some view title';
184  $this->assertEquals(
185  $title,
186  $this->stdpage->withViewTitle($title)->getViewTitle()
187  );
188  }
189 
190  public function testWithTextDirection() : void
191  {
192  $this->assertEquals("ltr", $this->stdpage->getTextDirection());
193  $this->assertEquals(
194  "rtl",
195  $this->stdpage
196  ->withTextDirection($this->stdpage::RTL)
197  ->getTextDirection()
198  );
199  }
200 
201  public function testWithMetaDatum()
202  {
203  $meta_datum_key = 'meta_datum_key';
204  $meta_datum_value = 'meta_datum_value';
205  $meta_data = [$meta_datum_key => $meta_datum_value];
206  $this->assertEquals(
207  $meta_data,
208  $this->stdpage->withAdditionalMetaDatum($meta_datum_key, $meta_datum_value)->getMetaData()
209  );
210  }
211 
212  public function testRenderingWithTitle() : void
213  {
214  $this->stdpage = $this->stdpage
215  ->withTitle("Title")
216  ->withViewTitle("View Title")
217  ->withShortTitle("Short Title");
218 
219  $r = $this->getDefaultRenderer(null, [$this->metabar, $this->mainbar, $this->crumbs, $this->logo]);
220  $html = $this->brutallyTrimHTML($r->render($this->stdpage));
221 
222  $exptected = $this->brutallyTrimHTML('
223 <!DOCTYPE html>
224 <html lang="en" dir="ltr">
225  <head>
226  <meta charset="utf-8" />
227  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
228  <meta name="viewport" content="width=device-width, initial-scale=1" />
229  <title>Short Title: View Title</title>
230  <style></style>
231  </head>
232  <body>
233  <div class="il-layout-page">
234  <header>
235  <div class="header-inner">
236  <div class="il-logo">
237  <span class="hidden-xs">Logo Stub</span>
238  <span class="visible-xs">Responsive Logo Stub</span>
239  <div class="il-pagetitle">Title</div>
240  </div>MetaBar Stub
241  </div>
242  </header>
243  <div class="breadcrumbs"></div>
244  <div class="il-system-infos"></div>
245  <div class="nav il-maincontrols">MainBar Stub</div>
246  <!-- html5 main-tag is not supported in IE / div is needed -->
247  <main class="il-layout-page-content">
248  <div>some content</div>
249  </main>
250  </div>
251  <script>il.Util.addOnLoad(function() {});</script>
252  </body>
253 </html>');
254  $this->assertEquals($exptected, $html);
255  }
256 
257  public function testRenderingWithMetaData()
258  {
259  $this->stdpage = $this->stdpage->withAdditionalMetaDatum('meta_datum_key_1', 'meta_datum_value_1');
260  $this->stdpage = $this->stdpage->withAdditionalMetaDatum('meta_datum_key_2', 'meta_datum_value_2');
261 
262  $r = $this->getDefaultRenderer(null, [$this->metabar, $this->mainbar, $this->crumbs, $this->logo]);
263  $html = $this->brutallyTrimHTML($r->render($this->stdpage));
264  $expected = $this->brutallyTrimHTML('
265 <!DOCTYPE html>
266 <html lang="en" dir="ltr">
267  <head>
268  <meta charset="utf-8" />
269  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
270  <meta name="viewport" content="width=device-width, initial-scale=1" />
271  <title>:</title>
272  <style></style>
273  <meta name="meta_datum_key_1" content="meta_datum_value_1" />
274  <meta name="meta_datum_key_2" content="meta_datum_value_2" />
275  </head>
276  <body>
277  <div class="il-layout-page">
278  <header>
279  <div class="header-inner">
280  <div class="il-logo"><span class="hidden-xs">Logo Stub</span><span class="visible-xs">Responsive Logo Stub</span>
281  <div class="il-pagetitle">pagetitle</div>
282  </div>MetaBar Stub
283  </div>
284  </header>
285  <div class="breadcrumbs"></div>
286  <div class="il-system-infos"></div>
287  <div class="nav il-maincontrols">MainBar Stub</div>
288  <!-- html5 main-tag is not supported in IE / div is needed -->
289  <main class="il-layout-page-content">
290  <div>some content</div>
291  </main>
292  </div>
293  <script>il.Util.addOnLoad(function() {});</script>
294  </body>
295 </html>');
296  $this->assertEquals($expected, $html);
297  }
298 
299  public function testRenderingWithRtlLanguage() : void
300  {
301  $this->stdpage = $this->stdpage->withTextDirection($this->stdpage::RTL);
302 
303  $r = $this->getDefaultRenderer(null, [$this->metabar, $this->mainbar, $this->crumbs, $this->logo]);
304  $html = $this->brutallyTrimHTML($r->render($this->stdpage));
305 
306  $exptected = $this->brutallyTrimHTML('
307 <!DOCTYPE html>
308 <html lang="en" dir="rtl">
309  <head>
310  <meta charset="utf-8" />
311  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
312  <meta name="viewport" content="width=device-width, initial-scale=1" />
313  <title>: </title>
314  <style></style>
315  </head>
316  <body>
317  <div class="il-layout-page">
318  <header>
319  <div class="header-inner">
320  <div class="il-logo">
321  <span class="hidden-xs">Logo Stub</span>
322  <span class="visible-xs">Responsive Logo Stub</span>
323  <div class="il-pagetitle">pagetitle</div>
324  </div>MetaBar Stub
325  </div>
326  </header>
327  <div class="breadcrumbs"></div>
328  <div class="il-system-infos"></div>
329  <div class="nav il-maincontrols">MainBar Stub</div>
330  <!-- html5 main-tag is not supported in IE / div is needed -->
331  <main class="il-layout-page-content">
332  <div>some content</div>
333  </main>
334  </div>
335  <script>il.Util.addOnLoad(function() {});</script>
336  </body>
337 </html>');
338  $this->assertEquals($exptected, $html);
339  }
340 }
This describes the Legacy-Slate.
Definition: Legacy.php:10
Tests for the Standard Page.
metabar()
Definition: metabar.php:2
Provides common functionality for UI tests.
Definition: Base.php:262
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
mainbar()
Definition: mainbar.php:2
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311