ILIAS  release_8 Revision v8.23
FooterTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
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 link(): C\Link\Factory
159  {
160  return new I\Link\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"><a href="http://www.ilias.de/goto.php?target=xxx_123">perma_link</a>
232  </div>
233 
234  <div class="il-footer-text">footer text</div>
235 
236  <div class="il-footer-links">
237  <ul>
238  <li><a href="http://www.ilias.de" >Goto ILIAS</a></li>
239  <li><a href="#" >go up</a></li>
240  </ul>
241  </div>
242  </div>
243  </div>
244 EOT;
245 
246  $this->assertEquals(
247  $this->brutallyTrimHTML($expected),
248  $this->brutallyTrimHTML($html)
249  );
250  }
251 
255  public function testRenderingModalsWithTriggers(C\MainControls\Footer $footer): void
256  {
257  $r = $this->getDefaultRenderer();
258  $html = $r->render($footer);
259 
260  $expected = <<<EOT
261  <div class="il-maincontrols-footer">
262  <div class="il-footer-content">
263  <div class="il-footer-text">footer text</div>
264 
265  <div class="il-footer-links">
266  <ul>
267  <li><a href="http://www.ilias.de" >Goto ILIAS</a></li>
268  <li><a href="#" >go up</a></li>
269  <li><button class="btn btn-link" id="id_1" >Button1</button></li>
270  <li><button class="btn btn-link" id="id_2">Button2</button></li>
271  </ul>
272  </div>
273  </div>
274  <div class="il-footer-modals">
275  <div class="modal fade il-modal-roundtrip" tabindex="-1" role="dialog" id="id_3">
276  <div class="modal-dialog" role="document" data-replace-marker="component">
277  <div class="modal-content">
278  <div class="modal-header">
279  <button type="button" class="close" data-dismiss="modal" aria-label="close">
280  <span aria-hidden="true">&times;</span>
281  </button>
282  <span class="modal-title">Modal1</span>
283  </div>
284  <div class="modal-body">PhpUnit</div>
285  <div class="modal-footer">
286  <button class="btn btn-default" data-dismiss="modal">cancel</button>
287  </div>
288  </div>
289  </div>
290  </div>
291  <div class="modal fade il-modal-roundtrip" tabindex="-1" role="dialog" id="id_5">
292  <div class="modal-dialog" role="document" data-replace-marker="component">
293  <div class="modal-content">
294  <div class="modal-header">
295  <button type="button" class="close" data-dismiss="modal" aria-label="close">
296  <span aria-hidden="true">&times;</span>
297  </button>
298  <span class="modal-title">Modal2</span>
299  </div>
300  <div class="modal-body">PhpUnit</div>
301  <div class="modal-footer">
302  <button class="btn btn-default" data-dismiss="modal">cancel</button>
303  </div>
304  </div>
305  </div>
306  </div>
307  </div>
308  </div>
309 EOT;
310 
311  $this->assertEquals(
312  $this->brutallyTrimHTML($expected),
313  $this->brutallyTrimHTML($html)
314  );
315  }
316 
317  protected function getModalFactory(): I\Modal\Factory
318  {
319  $group_mock = $this->createMock(Group::class);
320  $group_mock->method('withNameFrom')->willReturnSelf();
321 
322  $factory_mock = $this->createMock(FieldFactory::class);
323  $factory_mock->method('group')->willReturn($group_mock);
324 
325  return new I\Modal\Factory(new SignalGeneratorMock(), $factory_mock);
326  }
327 }
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:355
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:255
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:444
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:298
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