ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
FooterTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
25 use ILIAS\UI\Component as C;
27 
29 {
30  protected I\Link\Standard $link_mock;
31  protected I\Symbol\Icon\Icon $icon_mock;
32  protected I\Button\Shy $shy_mock;
33  protected I\Listing\Unordered $unordered_mock;
34  protected I\Button\Factory $button_factory;
35  protected I\Link\Factory $link_factory;
36  protected I\Listing\Factory $listing_factory;
37  protected \ILIAS\Data\URI $uri_mock;
38  protected string $link_html;
39  protected string $icon_html;
40  protected string $shy_html;
41  protected string $unordered_html;
42 
43  protected function setUp(): void
44  {
45  $this->link_html = sha1(C\Link\Standard::class);
46  $this->icon_html = sha1(C\Symbol\Icon\Icon::class);
47  $this->shy_html = sha1(C\Button\Shy::class);
48  $this->unordered_html = sha1(C\Listing\Unordered::class);
49 
50  $this->link_mock = $this->createMock(I\Link\Standard::class);
51  $this->link_mock->method('getCanonicalName')->willReturn($this->link_html);
52 
53  $this->icon_mock = $this->createMock(I\Symbol\Icon\Icon::class);
54  $this->icon_mock->method('getCanonicalName')->willReturn($this->icon_html);
55 
56  $this->shy_mock = $this->createMock(I\Button\Shy::class);
57  $this->shy_mock->method('getCanonicalName')->willReturn($this->shy_html);
58 
59  $this->unordered_mock = $this->createMock(I\Listing\Unordered::class);
60  $this->unordered_mock->method('getCanonicalName')->willReturn($this->unordered_html);
61 
62  $this->button_factory = $this->createMock(I\Button\Factory::class);
63  $this->button_factory->method('shy')->willReturn($this->shy_mock);
64 
65  $this->link_factory = $this->createMock(I\Link\Factory::class);
66  $this->link_factory->method('standard')->willReturn($this->link_mock);
67 
68  $this->listing_factory = $this->createMock(I\Listing\Factory::class);
69  $this->listing_factory->method('unordered')->willReturn($this->unordered_mock);
70 
71  $this->uri_mock = $this->createMock(\ILIAS\Data\URI::class);
72 
73  parent::setUp();
74  }
75 
76  public function testSetAndGetModalsWithTrigger(): void
77  {
78  $signal_mock = $this->createMock(C\Signal::class);
79 
80  $modal_mock = $this->createMock(C\Modal\RoundTrip::class);
81  $modal_mock->method('getShowSignal')->willReturn($signal_mock);
82 
83  $shy_mock = $this->shy_mock;
84  $shy_mock->expects($this->once())->method('withOnClick')->with($signal_mock)->willReturnSelf();
85 
86  $shy_mock = $shy_mock->withOnClick($modal_mock->getShowSignal());
87 
89  $footer = $this->getUIFactory()->mainControls()->footer();
90  $footer = $footer->withAdditionalLink($shy_mock);
91  $footer = $footer->withAdditionalModal($modal_mock);
92 
93  $this->assertCount(1, $footer->getModals());
94  $this->assertCount(1, $footer->getAdditionalLinks());
95  }
96 
97  public function testRenderWithPermanentUrl(): void
98  {
99  $footer = $this->getUIFactory()->mainControls()->footer();
100  $footer = $footer->withPermanentURL($this->uri_mock);
101 
102  $this->button_factory->expects($this->once())->method('shy')->with('copy_perma_link', '');
103  $this->shy_mock->expects($this->once())->method('withAdditionalOnLoadCode')->willReturnSelf();
104 
105  $renderer = $this->getDefaultRenderer(null, [$this->shy_mock]);
106  $actual_html = $renderer->render($footer);
107 
108  $expected_html = <<<EOT
109 <footer class="c-maincontrols c-maincontrols__footer">
110  <section class="c-maincontrols__footer-grid" data-section="permanent-link" aria-label="footer_permanent_link" tabindex="0">
111  <div class="c-maincontrols__footer-grid__item text-left">
112  <div class="c-tooltip__container c-tooltip--top" aria-live="polite">
113  $this->shy_html
114  <div class="c-tooltip c-tooltip--hidden" role="tooltip">
115  perma_link_copied
116  </div>
117  </div>
118  </div>
119  </section>
120 </footer>
121 EOT;
122 
123  $this->assertEquals(
124  $this->brutallyTrimHTML($expected_html),
125  $this->brutallyTrimHTML($actual_html)
126  );
127  }
128 
129  public function testRenderWithAdditionalLinkGroup(): void
130  {
131  $link_group_title = sha1('link_group_1');
132 
133  $footer = $this->getUIFactory()->mainControls()->footer();
134  $footer = $footer->withAdditionalLinkGroup($link_group_title, [$this->link_mock]);
135 
136  $this->listing_factory->expects($this->once())->method('unordered')->with([$this->link_mock]);
137 
138  $renderer = $this->getDefaultRenderer(null, [$this->unordered_mock]);
139  $actual_html = $renderer->render($footer);
140 
141  $expected_html = <<<EOT
142 <footer class="c-maincontrols c-maincontrols__footer">
143  <section class="c-maincontrols__footer-grid" data-section="link-groups" aria-label="footer_link_groups" tabindex="0">
144  <div class="c-maincontrols__footer-grid__item text-left">
145  <strong>$link_group_title</strong>$this->unordered_html
146  </div>
147  </section>
148 </footer>
149 EOT;
150 
151  $this->assertEquals(
152  $this->brutallyTrimHTML($expected_html),
153  $this->brutallyTrimHTML($actual_html)
154  );
155  }
156 
157  public function testRenderWithAdditionalLink(): void
158  {
159  $footer = $this->getUIFactory()->mainControls()->footer();
160  $footer = $footer->withAdditionalLink($this->link_mock);
161 
162  $renderer = $this->getDefaultRenderer(null, [$this->link_mock]);
163  $actual_html = $renderer->render($footer);
164 
165  $expected_html = <<<EOT
166 <footer class="c-maincontrols c-maincontrols__footer">
167  <section class="c-maincontrols__footer-grid" data-section="links" aria-label="footer_links" tabindex="0">
168  <div class="c-maincontrols__footer-grid__item text-left">$this->link_html</div>
169  </section>
170 </footer>
171 EOT;
172 
173  $this->assertEquals(
174  $this->brutallyTrimHTML($expected_html),
175  $this->brutallyTrimHTML($actual_html)
176  );
177  }
178 
179  public function testRenderWithAdditionalIcon(): void
180  {
181  $footer = $this->getUIFactory()->mainControls()->footer();
182  $footer = $footer->withAdditionalIcon($this->icon_mock);
183 
184  $renderer = $this->getDefaultRenderer(null, [$this->icon_mock]);
185  $actual_html = $renderer->render($footer);
186 
187  $expected_html = <<<EOT
188 <footer class="c-maincontrols c-maincontrols__footer">
189  <section class="c-maincontrols__footer-grid" data-section="icons" aria-label="footer_icons" tabindex="0">
190  <div class="c-maincontrols__footer-grid__item l-bar__group">
191  <span class="l-bar__element">$this->icon_html</span>
192  </div>
193  </section>
194 </footer>
195 EOT;
196 
197  $this->assertEquals(
198  $this->brutallyTrimHTML($expected_html),
199  $this->brutallyTrimHTML($actual_html)
200  );
201  }
202 
203  public function testRenderWithAdditionalText(): void
204  {
205  $text = sha1('text_1');
206 
207  $footer = $this->getUIFactory()->mainControls()->footer();
208  $footer = $footer->withAdditionalText($text);
209 
210  $renderer = $this->getDefaultRenderer();
211  $actual_html = $renderer->render($footer);
212 
213  $expected_html = <<<EOT
214 <footer class="c-maincontrols c-maincontrols__footer">
215  <section class="c-maincontrols__footer-grid" data-section="texts" aria-label="footer_texts" tabindex="0">
216  <div class="c-maincontrols__footer-grid__item text-left">$text</div>
217  </section>
218 </footer>
219 EOT;
220 
221  $this->assertEquals(
222  $this->brutallyTrimHTML($expected_html),
223  $this->brutallyTrimHTML($actual_html)
224  );
225  }
226 
227  public function testRenderWithModalsAndTrigger(): void
228  {
229  $modal_html = sha1(C\Modal\RoundTrip::class);
230  $modal_mock = $this->createMock(C\Modal\RoundTrip::class);
231  $modal_mock->method('getCanonicalName')->willReturn($modal_html);
232  $modal_mock->method('getShowSignal')->willReturn(
233  $this->createMock(C\Signal::class)
234  );
235 
236  $shy_mock = $this->shy_mock;
237  $shy_mock->method('withOnClick')->willReturnSelf();
238 
239  $shy_mock = $shy_mock->withOnClick($modal_mock->getShowSignal());
240 
241  $footer = $this->getUIFactory()->mainControls()->footer();
242  $footer = $footer->withAdditionalLink($shy_mock);
243  $footer = $footer->withAdditionalModal($modal_mock);
244 
245  $renderer = $this->getDefaultRenderer(null, [$modal_mock, $shy_mock]);
246  $actual_html = $renderer->render($footer);
247 
248  $expected_html = <<<EOT
249 <footer class="c-maincontrols c-maincontrols__footer">
250  <section class="c-maincontrols__footer-grid" data-section="links" aria-label="footer_links" tabindex="0">
251  <div class="c-maincontrols__footer-grid__item text-left">$this->shy_html</div>
252  </section>
253 </footer>$modal_html
254 EOT;
255 
256  $this->assertEquals(
257  $this->brutallyTrimHTML($expected_html),
258  $this->brutallyTrimHTML($actual_html)
259  );
260  }
261 
262  public function testRenderEmptyFooter(): void
263  {
264  $footer = $this->getUIFactory()->mainControls()->footer();
265 
266  $renderer = $this->getDefaultRenderer();
267  $actual_html = $renderer->render($footer);
268 
269  $expected_html = '';
270 
271  $this->assertEquals($expected_html, $actual_html);
272  }
273 
274  public function getUIFactory(): NoUIFactory
275  {
276  return new class (
277  $this->createMock(I\SignalGeneratorInterface::class),
278  $this->createMock(I\Counter\Factory::class),
279  $this->createMock(I\Symbol\Factory::class),
283  ) extends NoUIFactory {
284  public function __construct(
285  protected I\SignalGeneratorInterface $signal_generator,
286  protected I\Counter\Factory $counter_factory,
287  protected I\Symbol\Factory $symbol_factory,
288  protected I\Button\Factory $button_factory,
289  protected I\Link\Factory $link_factory,
290  protected I\Listing\Factory $listing_factory,
291  ) {
292  }
293  public function mainControls(): I\MainControls\Factory
294  {
295  return new I\MainControls\Factory(
296  $this->signal_generator,
297  new I\MainControls\Slate\Factory(
298  $this->signal_generator,
299  $this->counter_factory,
300  $this->symbol_factory,
301  ),
302  );
303  }
304  public function button(): I\Button\Factory
305  {
306  return $this->button_factory;
307  }
308  public function link(): I\Link\Factory
309  {
310  return $this->link_factory;
311  }
312  public function listing(): I\Listing\Factory
313  {
314  return $this->listing_factory;
315  }
316  };
317  }
318 }
button(string $caption, string $cmd)
string $shy_html
Definition: FooterTest.php:40
$renderer
testRenderWithAdditionalLink()
Definition: FooterTest.php:157
I Link Factory $link_factory
Definition: FooterTest.php:35
testRenderWithModalsAndTrigger()
Definition: FooterTest.php:227
I Listing Unordered $unordered_mock
Definition: FooterTest.php:33
Interface Observer Contains several chained tasks and infos about them.
testRenderEmptyFooter()
Definition: FooterTest.php:262
I Link Standard $link_mock
Definition: FooterTest.php:30
ILIAS Data URI $uri_mock
Definition: FooterTest.php:37
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
I Symbol Icon Icon $icon_mock
Definition: FooterTest.php:31
string $link_html
Definition: FooterTest.php:38
string $unordered_html
Definition: FooterTest.php:41
testRenderWithAdditionalIcon()
Definition: FooterTest.php:179
string $icon_html
Definition: FooterTest.php:39
testRenderWithAdditionalText()
Definition: FooterTest.php:203
testRenderWithAdditionalLinkGroup()
Definition: FooterTest.php:129
testRenderWithPermanentUrl()
Definition: FooterTest.php:97
__construct(Container $dic, ilPlugin $plugin)
link(string $caption, string $href, bool $new_viewport=false)
I Listing Factory $listing_factory
Definition: FooterTest.php:36
I Button Factory $button_factory
Definition: FooterTest.php:34
I Button Shy $shy_mock
Definition: FooterTest.php:32