ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $items = array(
120 $f->menu()->sub('sub', [
121 $this->button,
122 $this->glyph
123 ]),
124 $this->divider,
125 $this->button
126 );
127 $menu = $f->menu()->drilldown('root', $items);
128 $this->assertEquals(
129 $items,
130 $menu->getItems()
131 );
132 return $menu;
133 }
134
135 public function testWithWrongEntry(): void
136 {
137 $this->expectException(InvalidArgumentException::class);
138 $f = $this->getUIFactory();
139 $f->menu()->drilldown('label', [$this->legacy]);
140 }
141
142 #[\PHPUnit\Framework\Attributes\Depends('testWithEntries')]
143 public function testRendering(): void
144 {
145 $r = $this->getDefaultRenderer();
146 $f = $this->getUIFactory();
147
148 $items = [
149 $f->menu()->sub('1', [
150 $f->menu()->sub('1.1', []),
151 $f->menu()->sub('1.2', []),
152 ]),
153 $f->menu()->sub('2', [])
154 ];
155 $menu = $f->menu()->drilldown('root', $items);
156
157 $html = $r->render($menu);
158 $expected = file_get_contents(__DIR__ . "/drilldown_test.html");
159
160 $this->assertEquals(
161 $this->brutallyTrimHTML($expected),
162 $this->brutallyTrimHTML($html)
163 );
164 }
165
166 #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
167 public function testWithPersistenceId($menu): void
168 {
169 $this->assertNull($menu->getPersistenceId()) ;
170
171 $id = "some_id";
172 $this->assertEquals(
173 $id,
174 $menu->withPersistenceId($id)->getPersistenceId()
175 );
176 }
177}
$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)