ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
DrilldownTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/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(): I\Menu\Factory
43 {
44 return new Menu\Factory(
45 new I\SignalGenerator(),
46 );
47 }
48 public function button(): I\Button\Factory
49 {
50 return new I\Button\Factory();
51 }
52 public function legacy(): I\Legacy\Factory
53 {
54 return new I\Legacy\Factory(new I\SignalGenerator());
55 }
56 public function symbol(): I\Symbol\Factory
57 {
58 return new I\Symbol\Factory(
59 new I\Symbol\Icon\Factory(),
60 new I\Symbol\Glyph\Factory(),
61 new I\Symbol\Avatar\Factory()
62 );
63 }
64 };
65 }
66
67 public function setUp(): void
68 {
69 $icon_factory = new I\Symbol\Icon\Factory();
70 $glyph_factory = new I\Symbol\Glyph\Factory();
71 $button_factory = new I\Button\Factory();
72 $divider_factory = new I\Divider\Factory();
73 $this->icon = $icon_factory->standard('', '');
74 $this->glyph = $glyph_factory->user('');
75 $this->button = $button_factory->standard('', '');
76 $this->divider = $divider_factory->horizontal();
77 $this->legacy = $this->getUIFactory()->legacy()->content('');
78 }
79
80 public function testConstruction(): C\Menu\Drilldown
81 {
82 $f = $this->getUIFactory();
83 $menu = $f->menu()->drilldown('root', []);
84 $this->assertInstanceOf(
85 "ILIAS\\UI\\Component\\Menu\\Menu",
86 $menu
87 );
88 $this->assertInstanceOf(
89 "ILIAS\\UI\\Component\\Menu\\Drilldown",
90 $menu
91 );
92
93 $menu = $f->menu()->drilldown('root', []);
94
95 return $menu;
96 }
97
98 #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
99 public function testGetLabel(C\Menu\Drilldown $menu): void
100 {
101 $this->assertEquals(
102 'root',
103 $menu->getLabel()
104 );
105 }
106
107 #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
108 public function testGetItems($menu): void
109 {
110 $this->assertEquals(
111 [],
112 $menu->getItems()
113 );
114 }
115
116 public function testWithEntries(): C\Menu\Drilldown
117 {
118 $f = $this->getUIFactory();
119 $glyph_button = $f->button()->shy('', '')->withSymbol($this->glyph);
120 $items = array(
121 $f->menu()->sub('sub', [
122 $this->button,
123 $glyph_button
124 ]),
125 $this->divider,
126 $this->button
127 );
128 $menu = $f->menu()->drilldown('root', $items);
129 $this->assertEquals(
130 $items,
131 $menu->getItems()
132 );
133 return $menu;
134 }
135
136 public function testWithWrongEntry(): void
137 {
138 $this->expectException(InvalidArgumentException::class);
139 $f = $this->getUIFactory();
140 $f->menu()->drilldown('label', [$this->legacy]);
141 }
142
143 #[\PHPUnit\Framework\Attributes\Depends('testWithEntries')]
144 public function testRendering(): void
145 {
146 $r = $this->getDefaultRenderer();
147 $f = $this->getUIFactory();
148
149 $items = [
150 $f->menu()->sub('1', [
151 $f->menu()->sub('1.1', []),
152 $f->menu()->sub('1.2', []),
153 ]),
154 $f->menu()->sub('2', [])
155 ];
156 $menu = $f->menu()->drilldown('root', $items);
157
158 $html = $r->render($menu);
159 $expected = file_get_contents(__DIR__ . "/drilldown_test.html");
160
161 $this->assertEquals(
162 $this->brutallyTrimHTML($expected),
163 $this->brutallyTrimHTML($html)
164 );
165 }
166
167 #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
168 public function testWithPersistenceId($menu): void
169 {
170 $this->assertNull($menu->getPersistenceId()) ;
171
172 $id = "some_id";
173 $this->assertEquals(
174 $id,
175 $menu->withPersistenceId($id)->getPersistenceId()
176 );
177 }
178}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Tests for the Drilldown.
testGetLabel(C\Menu\Drilldown $menu)
testWithPersistenceId($menu)
C Symbol Icon Standard $icon
C Button Standard $button
C Legacy Content $legacy
C Divider Horizontal $divider
C Symbol Glyph Glyph $glyph
Provides common functionality for UI tests.
Definition: Base.php:337
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes a symbol.
Definition: Symbol.php:30
button(string $caption, string $cmd)