ILIAS  release_7 Revision v7.30-3-g800a261c036
FooterTest.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
5require_once("libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \ILIAS\UI\Component as C;
9use \ILIAS\UI\Implementation\Component as I;
11
16{
17 private $links = [];
18 private $text = '';
19 private $perm_url = '';
20
21 public function setUp() : void
22 {
23 $f = new I\Link\Factory();
24 $this->links = [
25 $f->standard("Goto ILIAS", "http://www.ilias.de"),
26 $f->standard("go up", "#")
27 ];
28 $this->text = 'footer text';
29 $this->perm_url = 'http://www.ilias.de/goto.php?target=xxx_123';
30 }
31
32 protected function getFactory()
33 {
34 $sig_gen = new I\SignalGenerator();
35 $counter_factory = new I\Counter\Factory();
36 $slate_factory = new I\MainControls\Slate\Factory(
37 $sig_gen,
38 $counter_factory,
39 new I\Symbol\Factory(
40 new I\Symbol\Icon\Factory(),
41 new I\Symbol\Glyph\Factory(),
42 new I\Symbol\Avatar\Factory()
43 )
44 );
45 $factory = new I\MainControls\Factory($sig_gen, $slate_factory);
46 return $factory;
47 }
48
49 public function testConstruction()
50 {
51 $footer = $this->getFactory()->footer($this->links, $this->text);
52 $this->assertInstanceOf(
53 "ILIAS\\UI\\Component\\MainControls\\Footer",
54 $footer
55 );
56 return $footer;
57 }
58
59 public function testConstructionNoLinks()
60 {
61 $footer = $this->getFactory()->footer([], $this->text);
62 $this->assertInstanceOf(
63 "ILIAS\\UI\\Component\\MainControls\\Footer",
64 $footer
65 );
66 return $footer;
67 }
68
72 public function testGetLinks($footer)
73 {
74 $this->assertEquals(
75 $this->links,
76 $footer->getLinks()
77 );
78 }
79
83 public function testGetText($footer)
84 {
85 $this->assertEquals(
86 $this->text,
87 $footer->getText()
88 );
89 }
90
94 public function testGetAndSetModalsWithTrigger(C\MainControls\Footer $footer)
95 {
96 $bf = new I\Button\Factory();
97 $signalGenerator = new SignalGenerator();
98 $mf = new I\Modal\Factory($signalGenerator);
99 $legacy = new ILIAS\UI\Implementation\Component\Legacy\Legacy('PhpUnit', $signalGenerator);
100
101 $shyButton1 = $bf->shy('Button1', '#');
102 $shyButton2 = $bf->shy('Button2', '#');
103
104 $modal1 = $mf->roundtrip('Modal1', $legacy);
105 $modal2 = $mf->roundtrip('Modal2', $legacy);
106
107 $footer = $footer
108 ->withAdditionalModalAndTrigger($modal1, $shyButton1)
109 ->withAdditionalModalAndTrigger($modal2, $shyButton2);
110
111 $this->assertCount(2, $footer->getModals());
112
113 return $footer;
114 }
115
119 public function testPermanentURL($footer)
120 {
121 $df = new \ILIAS\Data\Factory();
122 $footer = $footer->withPermanentURL($df->uri($this->perm_url));
123 $perm_url = $footer->getPermanentURL();
124 $this->assertInstanceOf("\\ILIAS\\Data\\URI", $perm_url);
125 $this->assertEquals(
126 $perm_url->getBaseURI() . '?' . $perm_url->getQuery(),
127 $this->perm_url
128 );
129 return $footer;
130 }
131
132 public function getUIFactory()
133 {
134 $factory = new class extends NoUIFactory {
135 public function listing()
136 {
137 return new I\Listing\Factory();
138 }
139 };
140 return $factory;
141 }
142
146 public function testRendering($footer)
147 {
148 $r = $this->getDefaultRenderer();
149 $html = $r->render($footer);
150
151 $expected = <<<EOT
152 <div class="il-maincontrols-footer">
153 <div class="il-footer-content">
154 <div class="il-footer-text">
155 footer text
156 </div>
157
158 <div class="il-footer-links">
159 <ul>
160 <li><a href="http://www.ilias.de" >Goto ILIAS</a></li>
161 <li><a href="#" >go up</a></li>
162 </ul>
163 </div>
164 </div>
165 </div>
166EOT;
167
168 $this->assertEquals(
169 $this->brutallyTrimHTML($expected),
170 $this->brutallyTrimHTML($html)
171 );
172 }
173
177 public function testRenderingNoLinks($footer)
178 {
179 $r = $this->getDefaultRenderer();
180 $html = $r->render($footer);
181
182 $expected = <<<EOT
183 <div class="il-maincontrols-footer">
184 <div class="il-footer-content">
185 <div class="il-footer-text">
186 footer text
187 </div>
188 </div>
189 </div>
190EOT;
191
192 $this->assertEquals(
193 $this->brutallyTrimHTML($expected),
194 $this->brutallyTrimHTML($html)
195 );
196 }
197
201 public function testRenderingPermUrl($footer)
202 {
203 $r = $this->getDefaultRenderer();
204 $html = $r->render($footer);
205
206 $expected = <<<EOT
207 <div class="il-maincontrols-footer">
208 <div class="il-footer-content">
209 <div class="il-footer-permanent-url"><label for="current_perma_link">perma_link</label><input id="current_perma_link" type="text" value="http://www.ilias.de/goto.php?target=xxx_123" readonly="readOnly">
210 </div>
211
212 <div class="il-footer-text">footer text</div>
213
214 <div class="il-footer-links">
215 <ul>
216 <li><a href="http://www.ilias.de" >Goto ILIAS</a></li>
217 <li><a href="#" >go up</a></li>
218 </ul>
219 </div>
220 </div>
221 </div>
222EOT;
223
224 $this->assertEquals(
225 $this->brutallyTrimHTML($expected),
226 $this->brutallyTrimHTML($html)
227 );
228 }
229
233 public function testRenderingModalsWithTriggers(C\MainControls\Footer $footer)
234 {
235 $r = $this->getDefaultRenderer();
236 $html = $r->render($footer);
237
238 $expected = <<<EOT
239 <div class="il-maincontrols-footer">
240 <div class="il-footer-content">
241 <div class="il-footer-text">footer text</div>
242
243 <div class="il-footer-links">
244 <ul>
245 <li><a href="http://www.ilias.de" >Goto ILIAS</a></li>
246 <li><a href="#" >go up</a></li>
247 <li><button class="btn btn-link" id="id_1" >Button1</button></li>
248 <li><button class="btn btn-link" id="id_2">Button2</button></li>
249 </ul>
250 </div>
251 </div>
252 <div class="il-footer-modals">
253 <div class="modal fade il-modal-roundtrip" tabindex="-1" role="dialog" id="id_3">
254 <div class="modal-dialog" role="document" data-replace-marker="component">
255 <div class="modal-content">
256 <div class="modal-header">
257 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
258 <span aria-hidden="true">&times;</span>
259 </button>
260 <span class="modal-title">Modal1</span>
261 </div>
262 <div class="modal-body">PhpUnit</div>
263 <div class="modal-footer">
264 <button class="btn btn-default" data-dismiss="modal" aria-label="Close">cancel</button>
265 </div>
266 </div>
267 </div>
268 </div>
269 <div class="modal fade il-modal-roundtrip" tabindex="-1" role="dialog" id="id_5">
270 <div class="modal-dialog" role="document" data-replace-marker="component">
271 <div class="modal-content">
272 <div class="modal-header">
273 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
274 <span aria-hidden="true">&times;</span>
275 </button>
276 <span class="modal-title">Modal2</span>
277 </div>
278 <div class="modal-body">PhpUnit</div>
279 <div class="modal-footer">
280 <button class="btn btn-default" data-dismiss="modal" aria-label="Close">cancel</button>
281 </div>
282 </div>
283 </div>
284 </div>
285 </div>
286 </div>
287EOT;
288
289 $this->assertEquals(
290 $this->brutallyTrimHTML($expected),
291 $this->brutallyTrimHTML($html)
292 );
293 }
294}
An exception for terminatinating execution or to throw for unit testing.
Tests for the Footer.
Definition: FooterTest.php:16
testGetText($footer)
@depends testConstruction
Definition: FooterTest.php:83
testRenderingModalsWithTriggers(C\MainControls\Footer $footer)
@depends testGetAndSetModalsWithTrigger
Definition: FooterTest.php:233
testConstruction()
Definition: FooterTest.php:49
testGetLinks($footer)
@depends testConstruction
Definition: FooterTest.php:72
testRenderingNoLinks($footer)
@depends testConstructionNoLinks
Definition: FooterTest.php:177
testRendering($footer)
@depends testConstruction
Definition: FooterTest.php:146
testGetAndSetModalsWithTrigger(C\MainControls\Footer $footer)
@depends testConstruction
Definition: FooterTest.php:94
testPermanentURL($footer)
@depends testConstruction
Definition: FooterTest.php:119
testConstructionNoLinks()
Definition: FooterTest.php:59
testRenderingPermUrl($footer)
@depends testPermanentURL
Definition: FooterTest.php:201
Provides common functionality for UI tests.
Definition: Base.php:263
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
footer()
Definition: footer.php:3
$factory
Definition: metadata.php:58
Class ChatMainBarProvider \MainMenu\Provider.
up()
Definition: up.php:2