ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
MetaBarTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2018 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once("libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 use \ILIAS\UI\Implementation as I;
10 use \ILIAS\UI\Implementation\Component\MainControls\Slate\Legacy;
11 use \ILIAS\UI\Component\Signal;
12 
17 {
18  public function setUp() : void
19  {
20  $sig_gen = new I\Component\SignalGenerator();
21  $this->button_factory = new I\Component\Button\Factory($sig_gen);
22  $this->icon_factory = new I\Component\Symbol\Icon\Factory();
23  $this->counter_factory = new I\Component\Counter\Factory();
24 
25  $slate_factory = new I\Component\MainControls\Slate\Factory(
26  $sig_gen,
27  $this->counter_factory,
28  new I\Component\Symbol\Factory(
29  new I\Component\Symbol\Icon\Factory(),
30  new I\Component\Symbol\Glyph\Factory(),
31  new I\Component\Symbol\Avatar\Factory()
32  )
33  );
34 
35  $this->factory = new I\Component\MainControls\Factory($sig_gen, $slate_factory);
36  $this->metabar = $this->factory->metabar();
37  }
38 
39  public function testConstruction()
40  {
41  $this->assertInstanceOf(
42  "ILIAS\\UI\\Component\\MainControls\\MetaBar",
43  $this->metabar
44  );
45  }
46 
47  protected function getButton()
48  {
49  $symbol = $this->icon_factory->custom('', '');
50  return $this->button_factory->bulky($symbol, 'TestEntry', '#');
51  }
52 
53  protected function getSlate()
54  {
55  $mock = $this->getMockBuilder(Legacy::class)
56  ->disableOriginalConstructor()
57  ->setMethods(["transformToLegacyComponent"])
58  ->getMock();
59 
60  $mock->method('transformToLegacyComponent')->willReturn('content');
61  return $mock;
62  }
63 
64  public function testAddEntry()
65  {
66  $button = $this->getButton();
67  $slate = $this->getSlate();
68  $mb = $this->metabar
69  ->withAdditionalEntry('button', $button)
70  ->withAdditionalEntry('slate', $slate);
71  $entries = $mb->getEntries();
72  $this->assertEquals($button, $entries['button']);
73  $this->assertEquals($slate, $entries['slate']);
74  }
75 
76  public function testDisallowedEntry()
77  {
78  $this->expectException(\InvalidArgumentException::class);
79  $mb = $this->metabar->withAdditionalEntry('test', 'wrong_param');
80  }
81 
82  public function testSignalsPresent()
83  {
84  $this->assertInstanceOf(Signal::class, $this->metabar->getEntryClickSignal());
85  }
86 
87  public function getUIFactory()
88  {
89  $factory = new class extends NoUIFactory {
90  public function button()
91  {
92  return $this->button_factory;
93  }
94  public function mainControls() : C\MainControls\Factory
95  {
96  return $this->mc_factory;
97  }
98  public function symbol() : C\Symbol\Factory
99  {
100  return new I\Component\Symbol\Factory(
101  new I\Component\Symbol\Icon\Factory(),
102  new I\Component\Symbol\Glyph\Factory(),
103  new I\Component\Symbol\Avatar\Factory()
104  );
105  }
106  public function counter() : C\Counter\Factory
107  {
108  return $this->counter_factory;
109  }
110  };
111  $factory->button_factory = $this->button_factory;
112  $factory->mc_factory = $this->factory;
113  $factory->counter_factory = $this->counter_factory;
114  return $factory;
115  }
116 
117  public function brutallyTrimHTML($html)
118  {
119  $html = str_replace(["\n", "\r", "\t"], "", $html);
120  $html = preg_replace('# {2,}#', " ", $html);
121  $html = preg_replace('/<!--(.|\s)*?-->/', '', $html);
122  $html = str_replace('> <', '><', $html);
123  return trim($html);
124  }
125 
126  public function testRendering()
127  {
128  $r = $this->getDefaultRenderer();
129 
130  $button = $this->getButton();
131  $slate = $this->getSlate();
132  $mb = $this->metabar
133  ->withAdditionalEntry('button', $button)
134  ->withAdditionalEntry('button2', $button);
135 
136  $html = $r->render($mb);
137 
138  $expected = '
139  <ul class="il-maincontrols-metabar" role="menubar" style="visibility: hidden" aria-label="metabar_aria_label" id="id_5" >
140  <li role="none">
141  <button class="btn btn-bulky" data-action="#" id="id_1" role="menuitem" >
142  <img class="icon custom small" src="" alt=""/><span class="bulky-label">TestEntry</span>
143  </button>
144  </li>
145  <li role="none">
146  <button class="btn btn-bulky" data-action="#" id="id_2" role="menuitem" >
147  <img class="icon custom small" src="" alt=""/><span class="bulky-label">TestEntry</span>
148  </button>
149  </li>
150  <li role="none">
151  <button class="btn btn-bulky" id="id_3" role="menuitem" aria-haspopup="true" >
152  <span class="glyph" aria-label="disclose" role="img">
153  <span class="glyphicon glyphicon-option-vertical" aria-hidden="true"></span>
154  <span class="il-counter"><span class="badge badge-notify il-counter-status" style="display:none">0</span></span>
155  <span class="il-counter"><span class="badge badge-notify il-counter-novelty" style="display:none">0</span></span>
156  </span>
157  <span class="bulky-label">more</span>
158  </button>
159  <div class="il-metabar-slates">
160  <div class="il-maincontrols-slate disengaged" id="id_4" role="menu">
161  <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
162  </div>
163  </div>
164  </li>
165  </ul>
166 ';
167 
168  $this->assertEquals(
169  $this->brutallyTrimHTML($expected),
170  $this->brutallyTrimHTML($html)
171  );
172  }
173 
174 
175  public function testAcceptsBulkyLinkAsEntry() : void
176  {
177  $r = $this->getDefaultRenderer();
178 
179  $bulky_link = $this->createMock(ILIAS\UI\Component\Link\Bulky::class);
180  $mb = $this->metabar
181  ->withAdditionalEntry('bulky link', $bulky_link);
182 
183  $this->assertTrue(true); // Should not throw...
184  }
185 }
Class Factory.
brutallyTrimHTML($html)
Class ChatMainBarProvider .
testSignalsPresent()
Definition: MetaBarTest.php:82
metabar()
Definition: metabar.php:2
Tests for the Meta Bar.
Definition: MetaBarTest.php:16
Provides common functionality for UI tests.
Definition: Base.php:262
testDisallowedEntry()
Definition: MetaBarTest.php:76
testAcceptsBulkyLinkAsEntry()
$factory
Definition: metadata.php:58
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311