ILIAS  release_8 Revision v8.24
DrilldownTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23
27
32{
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 ]),
131 $this->divider,
132 $this->button
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}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Tests for the Drilldown.
testGetLabel(C\Menu\Drilldown $menu)
@depends testConstruction
testWithPersistenceId($menu)
@depends testConstruction
C Legacy Legacy $legacy
C Symbol Icon Standard $icon
testRendering()
@depends testWithEntries
C Button Standard $button
C Divider Horizontal $divider
C Symbol Glyph Glyph $glyph
testGetItems($menu)
@depends testConstruction
Provides common functionality for UI tests.
Definition: Base.php:299
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
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...
Definition: Drilldown.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...