ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
MetaBarTest.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;
29 
34 {
35  protected I\Component\Button\Factory $button_factory;
36  protected I\Component\Symbol\Icon\Factory $icon_factory;
37  protected I\Component\Counter\Factory $counter_factory;
38  protected I\Component\MainControls\Factory $factory;
39  protected C\MainControls\MetaBar $metabar;
40 
41  public function setUp(): void
42  {
43  $sig_gen = new I\Component\SignalGenerator();
44  $this->button_factory = new I\Component\Button\Factory();
45  $this->icon_factory = new I\Component\Symbol\Icon\Factory();
46  $this->counter_factory = new I\Component\Counter\Factory();
47 
48  $slate_factory = new I\Component\MainControls\Slate\Factory(
49  $sig_gen,
50  $this->counter_factory,
51  new I\Component\Symbol\Factory(
52  new I\Component\Symbol\Icon\Factory(),
53  new I\Component\Symbol\Glyph\Factory(),
54  new I\Component\Symbol\Avatar\Factory()
55  )
56  );
57 
58  $this->factory = new I\Component\MainControls\Factory($sig_gen, $slate_factory);
59  $this->metabar = $this->factory->metabar();
60  }
61 
62  public function testConstruction(): void
63  {
64  $this->assertInstanceOf(
65  "ILIAS\\UI\\Component\\MainControls\\MetaBar",
66  $this->metabar
67  );
68  }
69 
70  protected function getButton(): C\Button\Bulky
71  {
72  $symbol = $this->icon_factory->custom('', '');
73  return $this->button_factory->bulky($symbol, 'TestEntry', '#');
74  }
75 
79  protected function getSlate()
80  {
81  $mock = $this->getMockBuilder(Legacy::class)
82  ->disableOriginalConstructor()
83  ->getMock();
84 
85  return $mock;
86  }
87 
88  public function testAddEntry(): void
89  {
90  $button = $this->getButton();
91  $slate = $this->getSlate();
92  $mb = $this->metabar
93  ->withAdditionalEntry('button', $button)
94  ->withAdditionalEntry('slate', $slate);
95  $entries = $mb->getEntries();
96  $this->assertEquals($button, $entries['button']);
97  $this->assertEquals($slate, $entries['slate']);
98  }
99 
100  public function testDisallowedEntry(): void
101  {
102  $this->expectException(InvalidArgumentException::class);
103  $this->metabar->withAdditionalEntry('test', 'wrong_param');
104  }
105 
106  public function testSignalsPresent(): void
107  {
108  $this->assertInstanceOf(Signal::class, $this->metabar->getEntryClickSignal());
109  }
110 
111  public function getUIFactory(): NoUIFactory
112  {
113  $factory = new class () extends NoUIFactory {
114  public C\Button\Factory $button_factory;
115  public C\MainControls\Factory $mc_factory;
116  public C\Counter\Factory $counter_factory;
117 
118  public function button(): C\Button\Factory
119  {
120  return $this->button_factory;
121  }
122  public function mainControls(): C\MainControls\Factory
123  {
124  return $this->mc_factory;
125  }
126  public function symbol(): C\Symbol\Factory
127  {
128  return new I\Component\Symbol\Factory(
129  new I\Component\Symbol\Icon\Factory(),
130  new I\Component\Symbol\Glyph\Factory(),
131  new I\Component\Symbol\Avatar\Factory()
132  );
133  }
134  public function counter(): C\Counter\Factory
135  {
136  return $this->counter_factory;
137  }
138  };
139  $factory->button_factory = $this->button_factory;
140  $factory->mc_factory = $this->factory;
141  $factory->counter_factory = $this->counter_factory;
142  return $factory;
143  }
144 
145  public function brutallyTrimHTML(string $html): string
146  {
147  $html = str_replace(["\n", "\r", "\t"], "", $html);
148  $html = preg_replace('# {2,}#', " ", $html);
149  $html = preg_replace('/<!--(.|\s)*?-->/', '', $html);
150  $html = str_replace('> <', '><', $html);
151  return trim($html);
152  }
153 
154  public function testRendering(): void
155  {
156  $r = $this->getDefaultRenderer();
157 
158  $button = $this->getButton();
159  $mb = $this->metabar
160  ->withAdditionalEntry('button', $button)
161  ->withAdditionalEntry('button2', $button);
162 
163  $html = $r->render($mb);
164 
165  $expected = '
166  <ul class="il-maincontrols-metabar" role="menubar" style="visibility: hidden" aria-label="metabar_aria_label" id="id_5" >
167  <li role="none">
168  <button class="btn btn-bulky" data-action="#" id="id_1" role="menuitem" >
169  <img class="icon custom small" src="" alt=""/><span class="bulky-label">TestEntry</span>
170  </button>
171  </li>
172  <li role="none">
173  <button class="btn btn-bulky" data-action="#" id="id_2" role="menuitem" >
174  <img class="icon custom small" src="" alt=""/><span class="bulky-label">TestEntry</span>
175  </button>
176  </li>
177  <li role="none">
178  <button class="btn btn-bulky" id="id_3" role="menuitem" aria-haspopup="true" >
179  <span class="glyph" role="img">
180  <span class="glyphicon glyphicon-option-vertical" aria-hidden="true"></span>
181  <span class="il-counter"><span class="badge badge-notify il-counter-status" style="display:none">0</span></span>
182  <span class="il-counter"><span class="badge badge-notify il-counter-novelty" style="display:none">0</span></span>
183  </span>
184  <span class="bulky-label">show_more</span>
185  </button>
186  <div class="il-metabar-slates">
187  <div class="il-maincontrols-slate disengaged" id="id_4" role="menu">
188  <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
189  </div>
190  </div>
191  </li>
192  </ul>
193 ';
194 
195  $this->assertEquals(
196  $this->brutallyTrimHTML($expected),
197  $this->brutallyTrimHTML($html)
198  );
199  }
200 
201 
202  public function testAcceptsBulkyLinkAsEntry(): void
203  {
204  $r = $this->getDefaultRenderer();
205 
206  $bulky_link = $this->createMock(ILIAS\UI\Component\Link\Bulky::class);
207  $mb = $this->metabar
208  ->withAdditionalEntry('bulky link', $bulky_link);
209 
210  $this->assertTrue(true); // Should not throw...
211  }
212 }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Class Factory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
I Component Button Factory $button_factory
Definition: MetaBarTest.php:35
Class ChatMainBarProvider .
I Component Symbol Icon Factory $icon_factory
Definition: MetaBarTest.php:36
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
C MainControls MetaBar $metabar
Definition: MetaBarTest.php:39
Tests for the Meta Bar.
Definition: MetaBarTest.php:33
Provides common functionality for UI tests.
Definition: Base.php:298
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
brutallyTrimHTML(string $html)
I Component Counter Factory $counter_factory
Definition: MetaBarTest.php:37
testAcceptsBulkyLinkAsEntry()
I Component MainControls Factory $factory
Definition: MetaBarTest.php:38