ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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  return trim($html);
123  }
124 
125  public function testRendering()
126  {
127  $r = $this->getDefaultRenderer();
128 
129  $button = $this->getButton();
130  $slate = $this->getSlate();
131  $mb = $this->metabar
132  ->withAdditionalEntry('button', $button)
133  ->withAdditionalEntry('button2', $button);
134 
135  $html = $r->render($mb);
136 
137  $expected = <<<EOT
138 <div class="il-maincontrols-metabar" id="id_5" role="menubar" aria-label="metabar_aria_label">
139  <div class="il-metabar-entries" style="visibility: hidden">
140  <button class="btn btn-bulky" data-action="#" id="id_1" >
141  <div class="icon custom small" aria-label="">
142  <img src="" />
143  </div>
144  <span class="bulky-label">TestEntry</span>
145  </button>
146  <button class="btn btn-bulky" data-action="#" id="id_2" >
147  <div class="icon custom small" aria-label="">
148  <img src="" />
149  </div>
150  <span class="bulky-label">TestEntry</span>
151  </button>
152  <button class="btn btn-bulky" id="id_3" role="menuitem" aria-haspopup="true" aria-pressed="false" >
153  <span class="glyph" aria-label="disclose">
154  <span class="glyphicon glyphicon-option-vertical" aria-hidden="true"></span>
155  <span class="il-counter">
156  <span class="badge badge-notify il-counter-status" style="display:none">0</span>
157  </span>
158  <span class="il-counter">
159  <span class="badge badge-notify il-counter-novelty" style="display:none">0</span>
160  </span>
161  </span>
162  <span class="bulky-label">more</span>
163  </button>
164  </div>
165  <div class="il-metabar-slates">
166  <div class="il-maincontrols-slate disengaged" id="id_4" role="menu">
167  <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
168  </div>
169  </div>
170 </div>
171 EOT;
172 
173  $this->assertEquals(
174  $this->brutallyTrimHTML($expected),
175  $this->brutallyTrimHTML($html)
176  );
177  }
178 }
brutallyTrimHTML($html)
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
more()
Definition: more.php:2
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:224
testDisallowedEntry()
Definition: MetaBarTest.php:76
$factory
Definition: metadata.php:58