ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
MainBarTest.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 
24 use ILIAS\UI\Component as C;
28 use ILIAS\Data;
30 
35 {
36  protected I\Button\Factory $button_factory;
37  protected I\Link\Factory $link_factory;
38  protected I\Symbol\Icon\Factory $icon_factory;
39  protected I\MainControls\Factory $factory;
40  protected C\MainControls\MainBar $mainbar;
41 
42  public function setUp(): void
43  {
44  $sig_gen = new I\SignalGenerator();
45  $this->button_factory = new I\Button\Factory();
46  $this->link_factory = new I\Link\Factory();
47  $this->icon_factory = new I\Symbol\Icon\Factory();
48  $counter_factory = new I\Counter\Factory();
49  $slate_factory = new I\MainControls\Slate\Factory(
50  $sig_gen,
51  $counter_factory,
52  new I\Symbol\Factory(
53  new I\Symbol\Icon\Factory(),
54  new I\Symbol\Glyph\Factory(),
55  new I\Symbol\Avatar\Factory()
56  )
57  );
58  $this->factory = new I\MainControls\Factory($sig_gen, $slate_factory);
59 
60  $this->mainbar = $this->factory->mainBar();
61  }
62 
63  public function testConstruction(): void
64  {
65  $this->assertInstanceOf(
66  "ILIAS\\UI\\Component\\MainControls\\MainBar",
67  $this->mainbar
68  );
69  }
70 
71  protected function getButton(): C\Button\Bulky
72  {
73  $symbol = $this->icon_factory->custom('', '');
74  return $this->button_factory->bulky($symbol, 'TestEntry', '#');
75  }
76 
77  protected function getLink(): C\Link\Bulky
78  {
79  $symbol = $this->icon_factory->custom('', '');
80  $target = new Data\URI("http://www.ilias.de");
81  return $this->link_factory->bulky($symbol, 'TestEntry', $target);
82  }
83 
87  protected function getSlate()
88  {
89  $mock = $this->getMockBuilder(Legacy::class)
90  ->disableOriginalConstructor()
91  ->getMock();
92 
93  return $mock;
94  }
95 
96  public function testAddEntry(): C\MainControls\MainBar
97  {
98  $btn = $this->getButton();
99  $lnk = $this->getLink();
100  $mb = $this->mainbar
101  ->withAdditionalEntry('testbtn', $btn)
102  ->withAdditionalEntry('testlnk', $lnk);
103 
104  $entries = $mb->getEntries();
105  $expected = [
106  'testbtn' => $btn,
107  'testlnk' => $lnk,
108  ];
109  $this->assertEquals($expected, $entries);
110  return $mb;
111  }
112 
113  public function testDisallowedEntry(): void
114  {
115  $this->expectException(InvalidArgumentException::class);
116  $this->mainbar->withAdditionalEntry('test', 'wrong_param');
117  }
118 
119  public function testDouplicateIdEntry(): void
120  {
121  $this->expectException(InvalidArgumentException::class);
122  $btn = $this->getButton();
123  $this->mainbar
124  ->withAdditionalEntry('test', $btn)
125  ->withAdditionalEntry('test', $btn);
126  }
127 
128  public function testDisallowedToolEntry(): void
129  {
130  $this->expectException(\TypeError::class);
131  $this->mainbar->withAdditionalToolEntry('test', 'wrong_param');
132  }
133 
134  public function testAddToolEntryWithoutToolsButton(): void
135  {
136  $this->expectException(LogicException::class);
137  $this->mainbar->withAdditionalToolEntry('test', $this->getSlate());
138  }
139 
140  public function testAddToolEntry(): void
141  {
142  $slate = $this->getSlate();
143  $mb = $this->mainbar
144  ->withToolsButton($this->getButton())
145  ->withAdditionalToolEntry('test', $slate);
146  $entries = $mb->getToolEntries();
147  $this->assertEquals($slate, $entries['test']);
148  }
149 
150  public function testDouplicateIdToolEntry(): void
151  {
152  $this->expectException(InvalidArgumentException::class);
153  $btn = $this->getButton();
154  $slate = $this->getSlate();
155  $this->mainbar
156  ->withToolsButton($btn)
157  ->withAdditionalToolEntry('test', $slate)
158  ->withAdditionalToolEntry('test', $slate);
159  }
160 
161  #[\PHPUnit\Framework\Attributes\Depends('testAddEntry')]
162  public function testActive(C\MainControls\MainBar $mb): void
163  {
164  $mb = $mb->withActive('testbtn');
165  $this->assertEquals('testbtn', $mb->getActive());
166  }
167 
168  public function testWithInvalidActive(): void
169  {
170  $this->expectException(InvalidArgumentException::class);
171  $this->mainbar->withActive('this-is-not-a-valid-entry');
172  }
173 
174  public function testSignalsPresent(): void
175  {
176  $this->assertInstanceOf(Signal::class, $this->mainbar->getEntryClickSignal());
177  $this->assertInstanceOf(Signal::class, $this->mainbar->getToolsClickSignal());
178  $this->assertInstanceOf(Signal::class, $this->mainbar->getToolsRemovalSignal());
179  $this->assertInstanceOf(Signal::class, $this->mainbar->getDisengageAllSignal());
180  }
181 
182  public function getUIFactory(): NoUIFactory
183  {
184  $factory = new class () extends NoUIFactory {
185  public I\Button\Factory $button_factory;
186 
187  public function button(): I\Button\Factory
188  {
189  return $this->button_factory;
190  }
191  public function symbol(): I\Symbol\Factory
192  {
193  $f_icon = new I\Symbol\Icon\Factory();
194  $f_glyph = new I\Symbol\Glyph\Factory();
195  $f_avatar = new I\Symbol\Avatar\Factory();
196 
197  return new I\Symbol\Factory($f_icon, $f_glyph, $f_avatar);
198  }
199  public function mainControls(): I\MainControls\Factory
200  {
201  $sig_gen = new I\SignalGenerator();
202  $counter_factory = new I\Counter\Factory();
203  $symbol_factory = new I\Symbol\Factory(
204  new I\Symbol\Icon\Factory(),
205  new I\Symbol\Glyph\Factory(),
206  new I\Symbol\Avatar\Factory()
207  );
208  $slate_factory = new I\MainControls\Slate\Factory($sig_gen, $counter_factory, $symbol_factory);
209  return new I\MainControls\Factory($sig_gen, $slate_factory);
210  }
211  public function legacy(): I\Legacy\Factory
212  {
213  $sig_gen = new I\SignalGenerator();
214  return new I\Legacy\Factory($sig_gen);
215  }
216  };
217  $factory->button_factory = $this->button_factory;
218  return $factory;
219  }
220 
221  public function testRendering(): void
222  {
223  $r = $this->getDefaultRenderer();
224  $icon = $this->icon_factory->custom('', '');
225 
226  $sf = $this->factory->slate();
227  $slate = $sf->combined('1', $icon)
228  ->withAdditionalEntry(
229  $sf->combined('1.1', $icon)
230  ->withAdditionalEntry(
231  $sf->combined('1.1.1', $icon)
232  )
233  );
234 
235  $toolslate = $sf->legacy('Help', $icon, new I\Legacy\Content('Help', new I\SignalGenerator()));
236 
237  $mb = $this->factory->mainBar()
238  ->withAdditionalEntry('test1', $this->getButton())
239  ->withAdditionalEntry('test2', $this->getButton())
240  ->withAdditionalEntry('slate', $slate)
241  ->withToolsButton($this->getButton())
242  ->withAdditionalToolEntry('tool1', $toolslate);
243 
244  $html = $r->render($mb);
245 
246  $expected = <<<EOT
247  <div class="il-maincontrols-mainbar" id="id_16">
248  <nav class="il-mainbar" aria-label="mainbar_aria_label">
249  <div class="il-mainbar-tools-button">
250  <button class="btn btn-bulky" id="id_14">
251  <img class="icon custom small" src="" alt=""/>
252  <span class="bulky-label">TestEntry</span>
253  </button>
254  </div>
255  <div class="il-mainbar-triggers">
256  <ul class="il-mainbar-entries" role="menubar" style="visibility: hidden">
257  <li role="none">
258  <button class="btn btn-bulky" data-action="#" id="id_1" role="menuitem">
259  <img class="icon custom small" src="" alt=""/>
260  <span class="bulky-label">TestEntry</span>
261  </button>
262  </li>
263  <li role="none">
264  <button class="btn btn-bulky" data-action="#" id="id_2" role="menuitem">
265  <img class="icon custom small" src="" alt=""/>
266  <span class="bulky-label">TestEntry</span>
267  </button>
268  </li>
269  <li role="none">
270  <button class="btn btn-bulky" id="id_3" role="menuitem">
271  <img class="icon custom small" src="" alt=""/>
272  <span class="bulky-label">1</span>
273  </button>
274  </li>
275  <li role="none">
276  <button class="btn btn-bulky" id="id_9" role="menuitem">
277  <span class="glyph" role="img">
278  <span class="glyphicon glyphicon-option-horizontal" aria-hidden="true"></span>
279  </span>
280  <span class="bulky-label">mainbar_more_label</span>
281  </button>
282  </li>
283  </ul>
284  </div>
285  </nav>
286  <div class="il-mainbar-slates">
287  <div class="il-mainbar-tools-entries">
288  <ul class="il-mainbar-tools-entries-bg" role="menubar">
289  <li class="il-mainbar-tool-trigger-item" role="none">
290  <button class="btn btn-bulky" id="id_11" role="menuitem">
291  <img class="icon custom small" src="" alt=""/>
292  <span class="bulky-label">Help</span>
293  </button>
294  </li>
295  </ul>
296  </div>
297  <div class="il-maincontrols-slate disengaged" id="id_8" data-depth-level="1" role="menu">
298  <div class="il-maincontrols-slate-content" data-replace-marker="content">
299  <ul>
300  <li>
301  <button class="btn btn-bulky" id="id_4">
302  <img class="icon custom small" src="" alt=""/>
303  <span class="bulky-label">1.1</span>
304  </button>
305  <div class="il-maincontrols-slate disengaged" id="id_7" data-depth-level="2">
306  <div class="il-maincontrols-slate-content" data-replace-marker="content">
307  <ul>
308  <li>
309  <button class="btn btn-bulky" id="id_5">
310  <img class="icon custom small" src="" alt=""/>
311  <span class="bulky-label">1.1.1</span>
312  </button>
313  <div class="il-maincontrols-slate disengaged" id="id_6" data-depth-level="3">
314  <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
315  </div>
316  </li>
317  </ul>
318  </div>
319  </div>
320  </li>
321  </ul>
322  </div>
323  </div>
324  <div class="il-maincontrols-slate disengaged" id="id_10" data-depth-level="1" role="menu">
325  <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
326  </div>
327  <div class="il-maincontrols-slate disengaged" id="id_13" data-depth-level="1" role="menu">
328  <div class="il-maincontrols-slate-content" data-replace-marker="content">Help</div>
329  </div>
330  <div class="il-mainbar-close-slates">
331  <button class="btn btn-bulky" id="id_15">
332  <span class="glyph" role="img">
333  <span class="glyphicon glyphicon-triangle-left" aria-hidden="true"></span>
334  </span>
335  <span class="bulky-label">close</span>
336  </button>
337  </div>
338  </div>
339  </div>
340 EOT;
341 
342  $this->assertEquals(
343  $this->brutallyTrimHTML($expected),
344  $this->brutallyTrimHTML($html)
345  );
346  }
347 }
button(string $caption, string $cmd)
I Button Factory $button_factory
Definition: MainBarTest.php:36
factory()
C MainControls MainBar $mainbar
Definition: MainBarTest.php:40
mainbar()
expected output: > ILIAS shows a link "Full Screen Page Layout".
Definition: mainbar.php:52
testWithInvalidActive()
I Symbol Icon Factory $icon_factory
Definition: MainBarTest.php:38
I Link Factory $link_factory
Definition: MainBarTest.php:37
close()
description: > Example for rendring a close glyph.
Definition: close.php:41
legacy()
expected output: > ILIAS shows the rendered Component.
Definition: legacy.php:29
Builds data types.
Definition: Factory.php:35
testAddToolEntryWithoutToolsButton()
testDisallowedToolEntry()
I MainControls Factory $factory
Definition: MainBarTest.php:39
Tests for the Main Bar.
Definition: MainBarTest.php:34
testDouplicateIdToolEntry()
testActive(C\MainControls\MainBar $mb)
testDouplicateIdEntry()
$r