ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ItemNotificationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
27
32{
33 protected I\Component\SignalGenerator $sig_gen;
34
35 public function setUp(): void
36 {
37 $this->sig_gen = new I\Component\SignalGenerator();
38 }
39
40 public function getIcon(): C\Symbol\Icon\Standard
41 {
42 return $this->getUIFactory()->symbol()->icon()->standard("name", "aria_label", "small", false);
43 }
44
45 public function getUIFactory(): NoUIFactory
46 {
47 $factory = new class () extends NoUIFactory {
48 public I\Component\SignalGenerator $sig_gen;
49
50 public function item(): I\Component\Item\Factory
51 {
52 return new I\Component\Item\Factory();
53 }
54
55 public function Link(): I\Component\Link\Factory
56 {
57 return new I\Component\Link\Factory();
58 }
59
60 public function button(): I\Component\Button\Factory
61 {
62 return new I\Component\Button\Factory();
63 }
64
65 public function symbol(): I\Component\Symbol\Factory
66 {
67 return new I\Component\Symbol\Factory(
68 new I\Component\Symbol\Icon\Factory(),
69 new I\Component\Symbol\Glyph\Factory(),
70 new I\Component\Symbol\Avatar\Factory()
71 );
72 }
73
74 public function mainControls(): I\Component\MainControls\Factory
75 {
76 return new I\Component\MainControls\Factory(
77 $this->sig_gen,
78 new I\Component\MainControls\Slate\Factory(
79 $this->sig_gen,
80 new I\Component\Counter\Factory(),
81 $this->symbol()
82 )
83 );
84 }
85 };
86 $factory->sig_gen = $this->sig_gen;
87 return $factory;
88 }
89
90 public function testImplementsFactoryInterface(): void
91 {
92 $f = $this->getUIFactory()->item();
93
94 $this->assertInstanceOf("ILIAS\\UI\\Component\\Item\\Notification", $f->notification("title", $this->getIcon()));
95 }
96
97 public function testGetTitle(): void
98 {
99 $f = $this->getUIFactory()->item();
100 $c = $f->standard("title");
101
102 $this->assertEquals("title", $c->getTitle());
103 }
104
105 public function testGetTitleAsLink(): void
106 {
107 $f = $this->getUIFactory()->item();
108 $title_link = $this->getUIFactory()->link()->standard("TestLink", "");
109 $c = $f->standard($title_link);
110
111 $this->assertEquals($c->getTitle(), $title_link);
112 }
113
114 public function testWithDescription(): void
115 {
116 $f = $this->getUIFactory()->item();
117
118 $c = $f->notification("title", $this->getIcon())->withDescription("description");
119
120 $this->assertEquals("description", $c->getDescription());
121 }
122
123 public function testWithProperties(): void
124 {
125 $f = $this->getUIFactory()->item();
126
127 $props = array("prop1" => "val1", "prop2" => "val2");
128 $c = $f->notification("title", $this->getIcon())->withProperties($props);
129
130 $this->assertEquals($c->getProperties(), $props);
131 }
132
133 public function testWithActions(): void
134 {
135 $f = $this->getUIFactory()->item();
136
137 $actions = new I\Component\Dropdown\Standard(array(
138 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
139 new I\Component\Button\Shy("GitHub", "https://www.github.com")
140 ));
141 $c = $f->notification("title", $this->getIcon())->withActions($actions);
142
143 $this->assertEquals($c->getActions(), $actions);
144 }
145
146 public function testWithLeadIcon(): void
147 {
148 $f = $this->getUIFactory()->item();
149
150 $c = $f->notification("title", $this->getIcon());
151 $this->assertEquals($c->getLeadIcon(), $this->getIcon());
152 $icon2 = $this->getIcon();
153
154 $this->assertEquals($c->withLeadIcon($icon2)->getLeadIcon(), $icon2);
155 }
156
157 public function testWithCloseAction(): void
158 {
159 $f = $this->getUIFactory()->item();
160
161 $c = $f->notification("title", $this->getIcon())->withCloseAction("closeAction");
162
163 $this->assertEquals("closeAction", $c->getCloseAction());
164 }
165
166 public function testWithAdditionalContent(): void
167 {
168 $f = $this->getUIFactory()->item();
169
170 $content = new I\Component\Legacy\Content("someContent", $this->sig_gen);
171 $c = $f->notification("title", $this->getIcon())->withAdditionalContent($content);
172
173 $this->assertEquals($c->getAdditionalContent(), $content);
174 }
175
176 public function testWithAggregateNotifications(): void
177 {
178 $f = $this->getUIFactory()->item();
179
180 $aggregate = $f->notification("title_aggregate", $this->getIcon());
181 $c = $f->notification("title", $this->getIcon())
182 ->withAggregateNotifications([$aggregate,$aggregate]);
183
184
185 $this->assertEquals($c->getAggregateNotifications(), [$aggregate,$aggregate]);
186 }
187
188 public function testRenderFullyFeatured(): void
189 {
190 $f = $this->getUIFactory()->item();
191 $r = $this->getDefaultRenderer(new class () implements JavaScriptBinding {
192 public array $on_load_code = array();
193
194 public function createId(): string
195 {
196 return "id";
197 }
198
199 public function addOnLoadCode(string $code): void
200 {
201 $this->on_load_code[] = $code;
202 }
203
204 public function getOnLoadCodeAsync(): string
205 {
206 }
207 });
208
209 $props = array("prop1" => "val1", "prop2" => "val2");
210 $content = new I\Component\Legacy\Content("someContent", $this->sig_gen);
211 $actions = new I\Component\Dropdown\Standard(array(
212 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
213 new I\Component\Button\Shy("GitHub", "https://www.github.com")
214 ));
215 $title_link = $this->getUIFactory()->link()->standard("TestLink", "");
216 $aggregate = $f->notification("title_aggregate", $this->getIcon());
217
218 $c = $f->notification($title_link, $this->getIcon())
219 ->withDescription("description")
220 ->withProperties($props)
221 ->withAdditionalContent($content)
222 ->withAggregateNotifications([$aggregate])
223 ->withCloseAction("closeAction")
224 ->withActions($actions)
225 ;
226
227 $html = $this->brutallyTrimHTML($r->render($c));
228 $expected = <<<EOT
229<div class="il-item-notification-replacement-container">
230 <div class="il-item il-notification-item" id="id">
231 <div class="media">
232 <div class="media-left">
233 <img class="icon name small" src="./assets/images/standard/icon_default.svg" alt="aria_label"/>
234 </div>
235 <div class="media-body">
236 <h4 class="il-item-notification-title">
237 <a href="">TestLink</a>
238 </h4>
239 <button type="button" class="close" aria-label="close" id="id">
240 <span aria-hidden="true">&times;</span>
241 </button>
242 <div class="il-item-description">description</div>
243 <div class="dropdown" id="id">
244 <button class="btn btn-default dropdown-toggle" type="button" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_menu">
245 <span class="caret"></span>
246 </button>
247 <ul id="id_menu" class="dropdown-menu">
248 <li>
249 <button class="btn btn-link" data-action="https://www.ilias.de" id="id">ILIAS</button>
250 </li>
251 <li>
252 <button class="btn btn-link" data-action="https://www.github.com" id="id">GitHub</button>
253 </li>
254 </ul>
255 </div>
256 <div class="il-item-additional-content">someContent</div>
257 <hr class="il-item-divider">
258 <div class="row il-item-properties">
259 <div class="col-sm-12 il-multi-line-cap-3">
260 <span class="il-item-property-name">prop1</span><span class="il-item-property-value">val1</span>
261 </div>
262 <div class="col-sm-12 il-multi-line-cap-3">
263 <span class="il-item-property-name">prop2</span><span class="il-item-property-value">val2</span>
264 </div>
265 </div>
266 <div class="il-aggregate-notifications" data-aggregatedby="id">
267 <div class="il-maincontrols-slate il-maincontrols-slate-notification">
268 <div class="il-maincontrols-slate-notification-title">
269 <button class="btn btn-bulky" data-action="">
270 <span class="glyph" role="img">
271 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
272 </span>
273 <span class="bulky-label">back</span>
274 </button>
275 </div>
276 <div class="il-maincontrols-slate-content">
277 <div class="il-item-notification-replacement-container">
278 <div class="il-item il-notification-item" id="id">
279 <div class="media">
280 <div class="media-left">
281 <img class="icon name small" src="./assets/images/standard/icon_default.svg" alt="aria_label"/>
282 </div>
283 <div class="media-body">
284 <h4 class="il-item-notification-title">title_aggregate</h4>
285 <div class="il-aggregate-notifications" data-aggregatedby="id">
286 <div class="il-maincontrols-slate il-maincontrols-slate-notification">
287 <div class="il-maincontrols-slate-notification-title">
288 <button class="btn btn-bulky" data-action="">
289 <span class="glyph" role="img">
290 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
291 </span>
292 <span class="bulky-label">back</span>
293 </button>
294 </div>
295 <div class="il-maincontrols-slate-content"></div>
296 </div>
297 </div>
298 </div>
299 </div>
300 </div>
301 </div>
302 </div>
303 </div>
304 </div>
305 </div>
306 </div>
307 </div>
308 </div>
309EOT;
310
311 $this->assertEquals($this->brutallyTrimHTML($expected), $html);
312 }
313}
Provides common functionality for UI tests.
Definition: Base.php:337
Test Notification Items.
I Component SignalGenerator $sig_gen
$c
Definition: deliver.php:25
Provides methods to interface with javascript.
button(string $caption, string $cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.