ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
DrilldownTest.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 
26 use ILIAS\UI\Component as C;
27 
32 {
33  protected C\Symbol\Icon\Standard $icon;
34  protected C\Symbol\Glyph\Glyph $glyph;
35  protected C\Button\Standard $button;
36  protected C\Divider\Horizontal $divider;
37  protected C\Legacy\Legacy $legacy;
38 
39  public function getUIFactory(): NoUIFactory
40  {
41  return new class () extends NoUIFactory {
42  public function menu(): C\Menu\Factory
43  {
44  return new Menu\Factory(
45  new I\SignalGenerator()
46  );
47  }
48  public function button(): C\Button\Factory
49  {
50  return new I\Button\Factory();
51  }
52  public function legacy(string $content): C\Legacy\Legacy
53  {
54  return new I\Legacy\Legacy(
55  $content,
56  new I\SignalGenerator()
57  );
58  }
59  public function symbol(): \ILIAS\UI\Component\Symbol\Factory
60  {
61  return new I\Symbol\Factory(
62  new I\Symbol\Icon\Factory(),
63  new I\Symbol\Glyph\Factory(),
64  new I\Symbol\Avatar\Factory()
65  );
66  }
67  };
68  }
69 
70  public function setUp(): void
71  {
72  $icon_factory = new I\Symbol\Icon\Factory();
73  $glyph_factory = new I\Symbol\Glyph\Factory();
74  $button_factory = new I\Button\Factory();
75  $divider_factory = new I\Divider\Factory();
76  $this->icon = $icon_factory->standard('', '');
77  $this->glyph = $glyph_factory->user('');
78  $this->button = $button_factory->standard('', '');
79  $this->divider = $divider_factory->horizontal();
80  $this->legacy = $this->getUIFactory()->legacy('');
81  }
82 
83  public function testConstruction(): C\Menu\Drilldown
84  {
85  $f = $this->getUIFactory();
86  $menu = $f->menu()->drilldown('root', []);
87  $this->assertInstanceOf(
88  "ILIAS\\UI\\Component\\Menu\\Menu",
89  $menu
90  );
91  $this->assertInstanceOf(
92  "ILIAS\\UI\\Component\\Menu\\Drilldown",
93  $menu
94  );
95 
96  $menu = $f->menu()->drilldown('root', []);
97 
98  return $menu;
99  }
100 
104  public function testGetLabel(C\Menu\Drilldown $menu): void
105  {
106  $this->assertEquals(
107  'root',
108  $menu->getLabel()
109  );
110  }
111 
115  public function testGetItems($menu): void
116  {
117  $this->assertEquals(
118  [],
119  $menu->getItems()
120  );
121  }
122 
123  public function testWithEntries(): C\Menu\Drilldown
124  {
125  $f = $this->getUIFactory();
126  $items = array(
127  $f->menu()->sub('sub', [
128  $this->button,
129  $this->glyph
130  ]),
133  );
134  $menu = $f->menu()->drilldown('root', $items);
135  $this->assertEquals(
136  $items,
137  $menu->getItems()
138  );
139  return $menu;
140  }
141 
142  public function testWithWrongEntry(): void
143  {
144  $this->expectException(InvalidArgumentException::class);
145  $f = $this->getUIFactory();
146  $f->menu()->drilldown('label', [$this->legacy]);
147  }
148 
152  public function testRendering(): void
153  {
154  $r = $this->getDefaultRenderer();
155  $f = $this->getUIFactory();
156 
157  $items = [
158  $f->menu()->sub('1', [
159  $f->menu()->sub('1.1', []),
160  $f->menu()->sub('1.2', []),
161  ]),
162  $f->menu()->sub('2', [])
163  ];
164  $menu = $f->menu()->drilldown('root', $items);
165 
166  $html = $r->render($menu);
167  $expected = file_get_contents(__DIR__ . "/drilldown_test.html");
168 
169  $this->assertEquals(
170  $this->brutallyTrimHTML($expected),
171  $this->brutallyTrimHTML($html)
172  );
173  }
174 
178  public function testWithPersistenceId($menu): void
179  {
180  $this->assertNull($menu->getPersistenceId()) ;
181 
182  $id = "some_id";
183  $this->assertEquals(
184  $id,
185  $menu->withPersistenceId($id)->getPersistenceId()
186  );
187  }
188 }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
C Symbol Glyph Glyph $glyph
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
C Symbol Icon Standard $icon
C Divider Horizontal $divider
testGetItems($menu)
testConstruction
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...
Definition: Drilldown.php:21
testWithPersistenceId($menu)
testConstruction
Tests for the Drilldown.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
C Button Standard $button
C Legacy Legacy $legacy
testRendering()
testWithEntries
testGetLabel(C\Menu\Drilldown $menu)
testConstruction