ILIAS  release_7 Revision v7.30-3-g800a261c036
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<div 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 <img class="icon name small" src="./templates/default/images/icon_default.svg" alt="aria_label"/>
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" aria-label="close" id="id">
213 <span aria-hidden="true">&times;</span>
214 </button>
215 <div class="il-item-description">description</div>
216 <div class="dropdown">
217 <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="actions" aria-haspopup="true" aria-expanded="false">
218 <span class="caret"></span>
219 </button>
220 <ul class="dropdown-menu">
221 <li>
222 <button class="btn btn-link" data-action="https://www.ilias.de" id="id">ILIAS</button>
223 </li>
224 <li>
225 <button class="btn btn-link" data-action="https://www.github.com" id="id">GitHub</button>
226 </li>
227 </ul>
228 </div>
229 <div class="il-item-additional-content">someContent</div>
230 <hr class="il-item-divider">
231 <div class="row il-item-properties">
232 <div class="col-sm-12 il-multi-line-cap-3">
233 <span class="il-item-property-name">prop1</span><span class="il-item-property-value">val1</span>
234 </div>
235 <div class="col-sm-12 il-multi-line-cap-3">
236 <span class="il-item-property-name">prop2</span><span class="il-item-property-value">val2</span>
237 </div>
238 </div>
239 <div class="il-aggregate-notifications" data-aggregatedby="id">
240 <div class="il-maincontrols-slate il-maincontrols-slate-notification">
241 <div class="il-maincontrols-slate-notification-title">
242 <button class="btn btn-bulky" data-action="">
243 <span class="glyph" aria-label="back" role="img">
244 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
245 </span>
246 <span class="bulky-label">back</span>
247 </button>
248 </div>
249 <div class="il-maincontrols-slate-content">
250 <div class="il-item-notification-replacement-container">
251 <div class="il-item il-notification-item" id="id">
252 <div class="media">
253 <div class="media-left">
254 <img class="icon name small" src="./templates/default/images/icon_default.svg" alt="aria_label"/>
255 </div>
256 <div class="media-body">
257 <h4 class="il-item-notification-title">title_aggregate</h4>
258 <div class="il-aggregate-notifications" data-aggregatedby="id">
259 <div class="il-maincontrols-slate il-maincontrols-slate-notification">
260 <div class="il-maincontrols-slate-notification-title">
261 <button class="btn btn-bulky" data-action="">
262 <span class="glyph" aria-label="back" role="img">
263 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
264 </span>
265 <span class="bulky-label">back</span>
266 </button>
267 </div>
268 <div class="il-maincontrols-slate-content"></div>
269 </div>
270 </div>
271 </div>
272 </div>
273 </div>
274 </div>
275 </div>
276 </div>
277 </div>
278 </div>
279 </div>
280 </div>
281 </div>
282EOT;
283
284 $this->assertEquals($this->brutallyTrimHTML($expected), $html);
285 }
286}
back()
Definition: back.php:2
An exception for terminatinating execution or to throw for unit testing.
Builds a Color from either hex- or rgb values.
Definition: Factory.php:14
Provides common functionality for UI tests.
Definition: Base.php:263
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
Test Notification Items.
$c
Definition: cli.php:37
$factory
Definition: metadata.php:58
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.