ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
DrilldownTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 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\Implementation\Component\Menu;
9 use \ILIAS\UI\Implementation\Component as I;
10 use \ILIAS\UI\Component as C;
11 
16 {
17  public function getUIFactory()
18  {
19  $factory = new class extends NoUIFactory {
20  public function menu() : C\Menu\Factory
21  {
22  return new Menu\Factory();
23  }
24  public function button()
25  {
26  return new I\Button\Factory();
27  }
28  public function legacy($content)
29  {
30  return new I\Legacy\Legacy($content, new I\SignalGenerator());
31  }
32  };
33  return $factory;
34  }
35 
36  public function setUp() : void
37  {
38  $icon_factory = new I\Symbol\Icon\Factory();
39  $glyph_factory = new I\Symbol\Glyph\Factory();
40  $button_factory = new I\Button\Factory();
41  $divider_factory = new I\Divider\Factory();
42  $this->icon = $icon_factory->standard('', '');
43  $this->glyph = $glyph_factory->user('');
44  $this->button = $button_factory->standard('', '');
45  $this->divider = $divider_factory->horizontal();
46  $this->legacy = $this->getUIFactory()->legacy('');
47  }
48 
49  public function testConstruction()
50  {
51  $f = $this->getUIFactory();
52  $menu = $f->menu()->drilldown('root', []);
53  $this->assertInstanceOf(
54  "ILIAS\\UI\\Component\\Menu\\Menu",
55  $menu
56  );
57  $this->assertInstanceOf(
58  "ILIAS\\UI\\Component\\Menu\\LabeledMenu",
59  $menu
60  );
61  $this->assertInstanceOf(
62  "ILIAS\\UI\\Component\\Menu\\Drilldown",
63  $menu
64  );
65 
66  return $menu;
67  }
68 
72  public function testGetLabel($menu)
73  {
74  $this->assertEquals(
75  'root',
76  $menu->getLabel()
77  );
78  }
79 
83  public function testWithLabel($menu)
84  {
85  $this->assertEquals(
86  'new label',
87  $menu->withLabel('new label')->getLabel()
88  );
89  }
90 
94  public function testWithClickableLabel($menu)
95  {
96  $this->assertEquals(
97  $this->button,
98  $menu->withLabel($this->button)->getLabel()
99  );
100  }
101 
105  public function testGetItems($menu)
106  {
107  $this->assertEquals(
108  [],
109  $menu->getItems()
110  );
111  }
112 
113  public function testWithEntries()
114  {
115  $f = $this->getUIFactory();
116  $items = array(
117  $f->menu()->sub('sub', [
118  $this->button,
119  $this->glyph
120  ]),
121  $this->divider,
122  $this->button
123  );
124  $menu = $f->menu()->drilldown('root', $items);
125  $this->assertEquals(
126  $items,
127  $menu->getItems()
128  );
129  return $menu;
130  }
131 
132  public function testWithWrongLabel()
133  {
134  $this->expectException(\InvalidArgumentException::class);
135  $f = $this->getUIFactory();
136  $menu = $f->menu()->drilldown($this->divider, []);
137  }
138 
139  public function testWithWrongEntry()
140  {
141  $this->expectException(\InvalidArgumentException::class);
142  $f = $this->getUIFactory();
143  $menu = $f->menu()->drilldown('label', [$this->legacy]);
144  }
145 
146 
147  public function brutallyTrimHTML($html)
148  {
149  $html = str_replace(["\n", "\t"], "", $html);
150  $html = preg_replace('# {2,}#', " ", $html);
151  return trim($html);
152  }
153 
157  public function testRendering($menu)
158  {
159  $r = $this->getDefaultRenderer();
160  $html = $r->render($menu);
161  $expected = <<<EOT
162  <div class="il-drilldown" id="id_3">
163  <ul class="il-drilldown-structure">
164  <li class="il-menu-item" id="id_1">
165  <span class="il-menu-item-label">
166  <button class="btn btn-link" data-action="">root</button>
167  </span>
168 
169  <ul class="il-menu-level">
170  <li class="il-menu-item" id="id_2">
171  <span class="il-menu-item-label">
172  <button class="btn btn-link" data-action="">sub</button>
173  </span>
174 
175  <ul class="il-menu-level">
176  <li class="il-menu-item" id="">
177  <span class="il-menu-item-label">
178  <button class="btn btn-default" data-action=""></button>
179  </span>
180  </li>
181  </ul>
182 
183  <ul class="il-menu-level">
184  <li class="il-menu-item" id="">
185  <span class="il-menu-item-label">
186  <a class="glyph" href="" aria-label="show_who_is_online"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a>
187  </span>
188  </li>
189  </ul>
190  </li>
191  </ul>
192  <ul class="il-menu-level">
193  <li class="il-menu-item" id="">
194  <span class="il-menu-item-label">
195  <hr />
196  </span>
197  </li>
198  </ul>
199 
200  <ul class="il-menu-level">
201  <li class="il-menu-item" id="">
202  <span class="il-menu-item-label">
203  <button class="btn btn-default" data-action=""></button>
204  </span>
205  </li>
206  </ul>
207  </li>
208  </ul>
209 
210  <ul class="il-drilldown-backlink"></ul>
211  <ul class="il-drilldown-current"></ul>
212  <ul class="il-drilldown-visible"></ul>
213  </div>
214 EOT;
215 
216  $this->assertEquals(
217  $this->brutallyTrimHTML($expected),
218  $this->brutallyTrimHTML($html)
219  );
220  }
221 }
testRendering($menu)
testWithEntries
testWithClickableLabel($menu)
testConstruction
testGetLabel($menu)
testConstruction
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
testGetItems($menu)
testConstruction
Provides common functionality for UI tests.
Definition: Base.php:224
testWithLabel($menu)
testConstruction
brutallyTrimHTML($html)
Tests for the Drilldown.
legacy()
Definition: legacy.php:3
$factory
Definition: metadata.php:58