ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
FooterTest.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 
24 use ILIAS\UI\Component as C;
28 use ILIAS\Data;
30 
35 {
36  private array $links = [];
37  private string $text = '';
38  private string $perm_url = '';
39 
40  public function setUp(): void
41  {
42  $f = new I\Link\Factory();
43  $this->links = [
44  $f->standard("Goto ILIAS", "http://www.ilias.de"),
45  $f->standard("go up", "#")
46  ];
47  $this->text = 'footer text';
48  $this->perm_url = 'http://www.ilias.de/goto.php?target=xxx_123';
49  }
50 
51  protected function getFactory(): I\MainControls\Factory
52  {
53  $sig_gen = new I\SignalGenerator();
54  $counter_factory = new I\Counter\Factory();
55  $slate_factory = new I\MainControls\Slate\Factory(
56  $sig_gen,
57  $counter_factory,
58  new I\Symbol\Factory(
59  new I\Symbol\Icon\Factory(),
60  new I\Symbol\Glyph\Factory(),
61  new I\Symbol\Avatar\Factory()
62  )
63  );
64  return new I\MainControls\Factory($sig_gen, $slate_factory);
65  }
66 
67  public function testConstruction(): C\MainControls\Footer
68  {
69  $footer = $this->getFactory()->footer($this->links, $this->text);
70  $this->assertInstanceOf(
71  "ILIAS\\UI\\Component\\MainControls\\Footer",
72  $footer
73  );
74  return $footer;
75  }
76 
77  public function testConstructionNoLinks(): C\MainControls\Footer
78  {
79  $footer = $this->getFactory()->footer([], $this->text);
80  $this->assertInstanceOf(
81  "ILIAS\\UI\\Component\\MainControls\\Footer",
82  $footer
83  );
84  return $footer;
85  }
86 
90  public function testGetLinks(C\MainControls\Footer $footer): void
91  {
92  $this->assertEquals(
93  $this->links,
94  $footer->getLinks()
95  );
96  }
97 
101  public function testGetText(C\MainControls\Footer $footer): void
102  {
103  $this->assertEquals(
104  $this->text,
105  $footer->getText()
106  );
107  }
108 
112  public function testGetAndSetModalsWithTrigger(C\MainControls\Footer $footer): C\MainControls\Footer
113  {
114  $bf = new I\Button\Factory();
115  $signalGenerator = new SignalGenerator();
116  $mf = $this->getModalFactory();
117  $legacy = new ILIAS\UI\Implementation\Component\Legacy\Legacy('PhpUnit', $signalGenerator);
118 
119  $shyButton1 = $bf->shy('Button1', '#');
120  $shyButton2 = $bf->shy('Button2', '#');
121 
122  $modal1 = $mf->roundtrip('Modal1', $legacy);
123  $modal2 = $mf->roundtrip('Modal2', $legacy);
124 
125  $footer = $footer
126  ->withAdditionalModalAndTrigger($modal1, $shyButton1)
127  ->withAdditionalModalAndTrigger($modal2, $shyButton2);
128 
129  $this->assertCount(2, $footer->getModals());
130 
131  return $footer;
132  }
133 
137  public function testPermanentURL(C\MainControls\Footer $footer): C\MainControls\Footer
138  {
139  $df = new Data\Factory();
140  $footer = $footer->withPermanentURL($df->uri($this->perm_url));
141  $perm_url = $footer->getPermanentURL();
142  $this->assertInstanceOf("\\ILIAS\\Data\\URI", $perm_url);
143  $this->assertEquals(
144  $perm_url->getBaseURI() . '?' . $perm_url->getQuery(),
146  );
147  return $footer;
148  }
149 
150  public function getUIFactory(): NoUIFactory
151  {
152  return new class () extends NoUIFactory {
153  public function listing(): C\Listing\Factory
154  {
155  return new I\Listing\Factory();
156  }
157 
158  public function button(): C\Button\Factory
159  {
160  return new I\Button\Factory();
161  }
162  };
163  }
164 
168  public function testRendering(C\MainControls\Footer $footer): void
169  {
170  $r = $this->getDefaultRenderer();
171  $html = $r->render($footer);
172 
173  $expected = <<<EOT
174  <div class="il-maincontrols-footer">
175  <div class="il-footer-content">
176  <div class="il-footer-text">
177  footer text
178  </div>
179 
180  <div class="il-footer-links">
181  <ul>
182  <li><a href="http://www.ilias.de" >Goto ILIAS</a></li>
183  <li><a href="#" >go up</a></li>
184  </ul>
185  </div>
186  </div>
187  </div>
188 EOT;
189 
190  $this->assertEquals(
191  $this->brutallyTrimHTML($expected),
192  $this->brutallyTrimHTML($html)
193  );
194  }
195 
199  public function testRenderingNoLinks(C\MainControls\Footer $footer): void
200  {
201  $r = $this->getDefaultRenderer();
202  $html = $r->render($footer);
203 
204  $expected = <<<EOT
205  <div class="il-maincontrols-footer">
206  <div class="il-footer-content">
207  <div class="il-footer-text">
208  footer text
209  </div>
210  </div>
211  </div>
212 EOT;
213 
214  $this->assertEquals(
215  $this->brutallyTrimHTML($expected),
216  $this->brutallyTrimHTML($html)
217  );
218  }
219 
223  public function testRenderingPermUrl($footer): void
224  {
225  $r = $this->getDefaultRenderer();
226  $html = $r->render($footer);
227 
228  $expected = <<<EOT
229  <div class="il-maincontrols-footer">
230  <div class="il-footer-content">
231  <div class="il-footer-permanent-url c-tooltip__container c-tooltip--top" aria-live="polite">
232  <button class="btn btn-link" data-action="" id="id_1">copy_perma_link</button>
233  <div class="c-tooltip c-tooltip--hidden" role="tooltip"> perma_link_copied</div>
234  </div>
235 
236  <div class="il-footer-text">footer text</div>
237 
238  <div class="il-footer-links">
239  <ul>
240  <li><a href="http://www.ilias.de" >Goto ILIAS</a></li>
241  <li><a href="#" >go up</a></li>
242  </ul>
243  </div>
244  </div>
245  </div>
246 EOT;
247 
248  $this->assertEquals(
249  $this->brutallyTrimHTML($expected),
250  $this->brutallyTrimHTML($html)
251  );
252  }
253 
257  public function testRenderingModalsWithTriggers(C\MainControls\Footer $footer): void
258  {
259  $r = $this->getDefaultRenderer();
260  $html = $r->render($footer);
261 
262  $expected = <<<EOT
263  <div class="il-maincontrols-footer">
264  <div class="il-footer-content">
265  <div class="il-footer-text">footer text</div>
266 
267  <div class="il-footer-links">
268  <ul>
269  <li><a href="http://www.ilias.de" >Goto ILIAS</a></li>
270  <li><a href="#" >go up</a></li>
271  <li><button class="btn btn-link" id="id_1" >Button1</button></li>
272  <li><button class="btn btn-link" id="id_2">Button2</button></li>
273  </ul>
274  </div>
275  </div>
276  <div class="il-footer-modals">
277  <div class="modal fade il-modal-roundtrip" tabindex="-1" role="dialog" id="id_3">
278  <div class="modal-dialog" role="document" data-replace-marker="component">
279  <div class="modal-content">
280  <div class="modal-header">
281  <button type="button" class="close" data-dismiss="modal" aria-label="close">
282  <span aria-hidden="true">&times;</span>
283  </button>
284  <h1 class="modal-title">Modal1</h1>
285  </div>
286  <div class="modal-body">PhpUnit</div>
287  <div class="modal-footer">
288  <button class="btn btn-default" data-dismiss="modal">cancel</button>
289  </div>
290  </div>
291  </div>
292  </div>
293  <div class="modal fade il-modal-roundtrip" tabindex="-1" role="dialog" id="id_5">
294  <div class="modal-dialog" role="document" data-replace-marker="component">
295  <div class="modal-content">
296  <div class="modal-header">
297  <button type="button" class="close" data-dismiss="modal" aria-label="close">
298  <span aria-hidden="true">&times;</span>
299  </button>
300  <h1 class="modal-title">Modal2</h1>
301  </div>
302  <div class="modal-body">PhpUnit</div>
303  <div class="modal-footer">
304  <button class="btn btn-default" data-dismiss="modal">cancel</button>
305  </div>
306  </div>
307  </div>
308  </div>
309  </div>
310  </div>
311 EOT;
312 
313  $this->assertEquals(
314  $this->brutallyTrimHTML($expected),
315  $this->brutallyTrimHTML($html)
316  );
317  }
318 
319  protected function getModalFactory(): I\Modal\Factory
320  {
321  $group_mock = $this->createMock(Group::class);
322  $group_mock->method('withNameFrom')->willReturnSelf();
323 
324  $factory_mock = $this->createMock(FieldFactory::class);
325  $factory_mock->method('group')->willReturn($group_mock);
326 
327  return new I\Modal\Factory(
328  new SignalGeneratorMock(),
329  $this->createMock(C\Modal\InterruptiveItem\Factory::class),
330  $factory_mock,
331  );
332  }
333 }
This is what a factory for input fields looks like.
Definition: Factory.php:28
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:377
button(string $caption, string $cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testRenderingModalsWithTriggers(C\MainControls\Footer $footer)
testGetAndSetModalsWithTrigger
Definition: FooterTest.php:257
testGetText(C\MainControls\Footer $footer)
testConstruction
Definition: FooterTest.php:101
testGetAndSetModalsWithTrigger(C\MainControls\Footer $footer)
testConstruction
Definition: FooterTest.php:112
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider .
string $perm_url
Definition: FooterTest.php:38
Tests for the Footer.
Definition: FooterTest.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:475
testRendering(C\MainControls\Footer $footer)
testConstruction
Definition: FooterTest.php:168
testRenderingPermUrl($footer)
testPermanentURL
Definition: FooterTest.php:223
testConstructionNoLinks()
Definition: FooterTest.php:77
testGetLinks(C\MainControls\Footer $footer)
testConstruction
Definition: FooterTest.php:90
testPermanentURL(C\MainControls\Footer $footer)
testConstruction
Definition: FooterTest.php:137
Provides common functionality for UI tests.
Definition: Base.php:310
string $text
Definition: FooterTest.php:37
testRenderingNoLinks(C\MainControls\Footer $footer)
testConstructionNoLinks
Definition: FooterTest.php:199
testConstruction()
Definition: FooterTest.php:67
array $links
Definition: FooterTest.php:36
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$r