ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ItemNotificationTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Timon Amstutz <timon.amstutz@ilub.unibe.ch Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \ILIAS\UI\Implementation as I;
9
14{
15 public function setUp() : void
16 {
17 $this->sig_gen = new I\Component\SignalGenerator();
18 }
19
20 public function getIcon()
21 {
22 return $this->getUIFactory()->symbol()->icon()->standard("name", "aria_label", "small", false);
23 }
24
25 public function getUIFactory()
26 {
27 $factory = new class extends NoUIFactory {
28 public function item()
29 {
30 return new I\Component\Item\Factory();
31 }
32 public function Link()
33 {
34 return new \ILIAS\UI\Implementation\Component\Link\Factory();
35 }
36 public function button()
37 {
38 return new I\Component\Button\Factory();
39 }
40 public function symbol() : ILIAS\UI\Component\Symbol\Factory
41 {
42 return new I\Component\Symbol\Factory(
43 new I\Component\Symbol\Icon\Factory(),
44 new I\Component\Symbol\Glyph\Factory(),
45 new I\Component\Symbol\Avatar\Factory()
46 );
47 }
48 public function mainControls() : ILIAS\UI\Component\MainControls\Factory
49 {
50 return new I\Component\MainControls\Factory(
51 $this->sig_gen,
52 new I\Component\MainControls\Slate\Factory(
53 $this->sig_gen,
54 new \ILIAS\UI\Implementation\Component\Counter\Factory(),
55 $this->symbol()
56 )
57 );
58 }
59 };
60 $factory->sig_gen = $this->sig_gen;
61 return $factory;
62 }
63
65 {
66 $f = $this->getUIFactory()->item();
67
68 $this->assertInstanceOf("ILIAS\\UI\\Component\\Item\\Notification", $f->notification("title", $this->getIcon()));
69 }
70
71
72 public function testGetTitle()
73 {
74 $f = $this->getUIFactory()->item();
75 $c = $f->standard("title");
76
77 $this->assertEquals($c->getTitle(), "title");
78 }
79
80 public function testGetTitleAsLink()
81 {
82 $f = $this->getUIFactory()->item();
83 $title_link = $this->getUIFactory()->link()->standard("TestLink", "");
84 $c = $f->standard($title_link, $this->getIcon());
85
86 $this->assertEquals($c->getTitle(), $title_link);
87 }
88
89
90 public function testWithDescription()
91 {
92 $f = $this->getUIFactory()->item();
93
94 $c = $f->notification("title", $this->getIcon())->withDescription("description");
95
96 $this->assertEquals($c->getDescription(), "description");
97 }
98
99 public function testWithProperties()
100 {
101 $f = $this->getUIFactory()->item();
102
103 $props = array("prop1" => "val1", "prop2" => "val2");
104 $c = $f->notification("title", $this->getIcon())->withProperties($props);
105
106 $this->assertEquals($c->getProperties(), $props);
107 }
108
109 public function testWithActions()
110 {
111 $f = $this->getUIFactory()->item();
112
113 $actions = new I\Component\Dropdown\Standard(array(
114 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
115 new I\Component\Button\Shy("GitHub", "https://www.github.com")
116 ));
117 $c = $f->notification("title", $this->getIcon())->withActions($actions);
118
119 $this->assertEquals($c->getActions(), $actions);
120 }
121
122 public function testWithLeadIcon()
123 {
124 $f = $this->getUIFactory()->item();
125
126 $c = $f->notification("title", $this->getIcon());
127 $this->assertEquals($c->getLeadIcon(), $this->getIcon());
128 $icon2 = $this->getIcon()->withIsOutlined(true);
129
130 $this->assertEquals($c->withLeadIcon($icon2)->getLeadIcon(), $icon2);
131 }
132
133 public function testWithCloseAction()
134 {
135 $f = $this->getUIFactory()->item();
136
137 $c = $f->notification("title", $this->getIcon())->withCloseAction("closeAction");
138
139 $this->assertEquals($c->getCloseAction(), "closeAction");
140 }
141
143 {
144 $f = $this->getUIFactory()->item();
145
146 $content = new I\Component\Legacy\Legacy("someContent", $this->sig_gen);
147 $c = $f->notification("title", $this->getIcon())->withAdditionalContent($content);
148
149 $this->assertEquals($c->getAdditionalContent(), $content);
150 }
151
153 {
154 $f = $this->getUIFactory()->item();
155
156 $aggregate = $f->notification("title_aggregate", $this->getIcon());
157 $c = $f->notification("title", $this->getIcon())
158 ->withAggregateNotifications([$aggregate,$aggregate]);
159
160
161 $this->assertEquals($c->getAggregateNotifications(), [$aggregate,$aggregate]);
162 }
163
164 public function testRenderFullyFeatured()
165 {
166 $f = $this->getUIFactory()->item();
167 $r = $this->getDefaultRenderer(new class implements \ILIAS\UI\Implementation\Render\JavaScriptBinding {
168 public function createId()
169 {
170 return "id";
171 }
172 public $on_load_code = array();
173 public function addOnLoadCode($code)
174 {
175 $this->on_load_code[] = $code;
176 }
177 public function getOnLoadCodeAsync()
178 {
179 }
180 });
181
182 $props = array("prop1" => "val1", "prop2" => "val2");
183 $content = new I\Component\Legacy\Legacy("someContent", $this->sig_gen);
184 $actions = new I\Component\Dropdown\Standard(array(
185 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
186 new I\Component\Button\Shy("GitHub", "https://www.github.com")
187 ));
188 $title_link = $this->getUIFactory()->link()->standard("TestLink", "");
189 $aggregate = $f->notification("title_aggregate", $this->getIcon());
190
191 $c = $f->notification($title_link, $this->getIcon())
192 ->withDescription("description")
193 ->withProperties($props)
194 ->withAdditionalContent($content)
195 ->withAggregateNotifications([$aggregate])
196 ->withCloseAction("closeAction")
197 ->withActions($actions)
198 ;
199
200 $html = $this->brutallyTrimHTML($r->render($c));
201 $expected = <<<EOT
202<span class="il-item-notification-replacement-container">
203 <div class="il-item il-notification-item" id="id">
204 <div class="media">
205 <div class="media-left">
206 <div class="icon name small" aria-label="aria_label"></div>
207 </div>
208 <div class="media-body">
209 <h4 class="il-item-notification-title">
210 <a href="">TestLink</a>
211 </h4>
212 <button type="button" class="close" data-dismiss="modal" id="id">
213 <span aria-hidden="true">&times;</span>
214 <span class="sr-only">Close</span>
215 </button>
216 <div class="il-item-description">description</div>
217 <div class="dropdown">
218 <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="actions" aria-haspopup="true" aria-expanded="false">
219 <span class="caret"></span>
220 </button>
221 <ul class="dropdown-menu">
222 <li>
223 <button class="btn btn-link" data-action="https://www.ilias.de" id="id">ILIAS</button>
224 </li>
225 <li>
226 <button class="btn btn-link" data-action="https://www.github.com" id="id">GitHub</button>
227 </li>
228 </ul>
229 </div>
230 <div class="il-item-additional-content">someContent</div>
231 <hr class="il-item-divider">
232 <div class="row il-item-properties">
233 <div class="col-md-12">
234 <div class="row">
235 <div class="col-sm-3 il-item-property-name">prop1</div>
236 <div class="col-sm-9 il-item-property-value il-multi-line-cap-3">val1</div>
237 </div>
238 </div>
239 <div class="col-md-12">
240 <div class="row">
241 <div class="col-sm-3 il-item-property-name">prop2</div>
242 <div class="col-sm-9 il-item-property-value il-multi-line-cap-3">val2</div>
243 </div>
244 </div>
245 </div>
246 <div class="il-aggregate-notifications" data-aggregatedby="id">
247 <div class="il-maincontrols-slate il-maincontrols-slate-notification">
248 <div class="il-maincontrols-slate-notification-title">
249 <button class="btn btn-bulky" data-action="">
250 <span class="glyph" aria-label="back">
251 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
252 </span>
253 <span class="bulky-label">back</span>
254 </button>
255 </div>
256 <div class="il-maincontrols-slate-content">
257 <span class="il-item-notification-replacement-container">
258 <div class="il-item il-notification-item" id="id">
259 <div class="media">
260 <div class="media-left">
261 <div class="icon name small" aria-label="aria_label"></div>
262 </div>
263 <div class="media-body">
264 <h4 class="il-item-notification-title">title_aggregate</h4>
265 <div class="il-aggregate-notifications" data-aggregatedby="id">
266 <div class="il-maincontrols-slate il-maincontrols-slate-notification">
267 <div class="il-maincontrols-slate-notification-title">
268 <button class="btn btn-bulky" data-action="">
269 <span class="glyph" aria-label="back">
270 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
271 </span>
272 <span class="bulky-label">back</span>
273 </button>
274 </div>
275 <div class="il-maincontrols-slate-content"></div>
276 </div>
277 </div>
278 </div>
279 </div>
280 </div>
281 </span>
282 </div>
283 </div>
284 </div>
285 </div>
286 </div>
287 </div>
288 </span>
289EOT;
290
291 $this->assertEquals($this->brutallyTrimHTML($expected), $html);
292 }
293}
back()
Definition: back.php:2
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:225
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:346
Test Notification Items.
This is how a factory for buttons looks like.
Definition: Factory.php:13
$factory
Definition: metadata.php:58
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.