ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MessageBoxTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2018 Thomas Famula <famula@leifos.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \ILIAS\UI\Component as C;
9use \ILIAS\UI\Implementation\Component as IC;
10
15{
16 public function getMessageBoxFactory()
17 {
18 return new \ILIAS\UI\Implementation\Component\MessageBox\Factory();
19 }
20 public function getButtonFactory()
21 {
22 return new \ILIAS\UI\Implementation\Component\Button\Factory();
23 }
24 public function getLinkFactory()
25 {
26 return new \ILIAS\UI\Implementation\Component\Link\Factory();
27 }
28
29 public function messagebox_type_provider()
30 {
31 return array( array(C\MessageBox\MessageBox::FAILURE)
32 , array(C\MessageBox\MessageBox::SUCCESS)
33 , array(C\MessageBox\MessageBox::INFO)
34 , array(C\MessageBox\MessageBox::CONFIRMATION)
35 );
36 }
37
38 public static $canonical_css_classes = array( C\MessageBox\MessageBox::FAILURE => "alert-danger"
39 , C\MessageBox\MessageBox::SUCCESS => "alert-success"
40 , C\MessageBox\MessageBox::INFO => "alert-info"
41 , C\MessageBox\MessageBox::CONFIRMATION => "alert-warning"
42 );
43
44 public function getUIFactory()
45 {
46 return new \ILIAS\UI\Implementation\Factory(
47 $this->createMock(C\Counter\Factory::class),
48 $this->createMock(C\Glyph\Factory::class),
49 $this->createMock(C\Button\Factory::class),
50 new IC\Listing\Factory(),
51 $this->createMock(C\Image\Factory::class),
52 $this->createMock(C\Panel\Factory::class),
53 $this->createMock(C\Modal\Factory::class),
54 $this->createMock(C\Dropzone\Factory::class),
55 $this->createMock(C\Popover\Factory::class),
56 $this->createMock(C\Divider\Factory::class),
57 $this->createMock(C\Link\Factory::class),
58 $this->createMock(C\Dropdown\Factory::class),
59 $this->createMock(C\Item\Factory::class),
60 $this->createMock(C\Icon\Factory::class),
61 $this->createMock(C\ViewControl\Factory::class),
62 $this->createMock(C\Chart\Factory::class),
63 $this->createMock(C\Input\Factory::class),
64 $this->createMock(C\Table\Factory::class),
65 $this->createMock(C\MessageBox\Factory::class),
66 $this->createMock(C\Card\Factory::class)
67 );
68 }
69
70
74 public function test_implements_factory_interface($factory_method)
75 {
76 $f = $this->getMessageBoxFactory();
77
78 $this->assertInstanceOf("ILIAS\\UI\\Component\\MessageBox\\Factory", $f);
79 $this->assertInstanceOf("ILIAS\\UI\\Component\\MessageBox\\MessageBox", $f->$factory_method("Lorem ipsum dolor sit amet."));
80 }
81
85 public function test_messagebox_types($factory_method)
86 {
87 $f = $this->getMessageBoxFactory();
88 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
89
90 $this->assertNotNull($g);
91 $this->assertEquals($factory_method, $g->getType());
92 }
93
97 public function test_messagebox_messagetext($factory_method)
98 {
99 $f = $this->getMessageBoxFactory();
100 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
101
102 $this->assertNotNull($g);
103 $this->assertEquals("Lorem ipsum dolor sit amet.", $g->getMessageText());
104 }
105
109 public function test_with_buttons($factory_method)
110 {
111 $f = $this->getMessageBoxFactory();
112 $bf = $this->getButtonFactory();
113 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
114
115 $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
116 $g2 = $g->withButtons($buttons);
117
118 $this->assertFalse(count($g->getButtons()) > 0);
119 $this->assertTrue(count($g2->getButtons()) > 0);
120 }
121
125 public function test_with_links($factory_method)
126 {
127 $f = $this->getMessageBoxFactory();
128 $lf = $this->getLinkFactory();
129 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
130
131 $links = [
132 $lf->standard("Open Exercise Assignment", "#"),
133 $lf->standard("Open other screen", "#"),
134 ];
135 $g2 = $g->withLinks($links);
136
137 $this->assertFalse(count($g->getLinks()) > 0);
138 $this->assertTrue(count($g2->getLinks()) > 0);
139 }
140
144 public function test_with_buttons_and_links($factory_method)
145 {
146 $f = $this->getMessageBoxFactory();
147 $bf = $this->getButtonFactory();
148 $lf = $this->getLinkFactory();
149 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
150
151 $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
152 $links = [
153 $lf->standard("Open Exercise Assignment", "#"),
154 $lf->standard("Open other screen", "#"),
155 ];
156 $g2 = $g->withButtons($buttons)->withLinks($links);
157
158 $this->assertFalse(count($g->getButtons()) > 0 && count($g->getLinks()) > 0);
159 $this->assertTrue(count($g2->getButtons()) > 0 && count($g2->getLinks()) > 0);
160 }
161
165 public function test_render_simple($factory_method)
166 {
167 $f = $this->getMessageBoxFactory();
168 $r = $this->getDefaultRenderer();
169 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
170 $css_classes = self::$canonical_css_classes[$factory_method];
171
172 $html = $this->normalizeHTML($r->render($g));
173 $expected = "<div class=\"alert $css_classes\" role=\"alert\">" .
174 "<h5 class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
175 $g->getType() . "_message</a></h5>Lorem ipsum dolor sit amet.</div>";
176 $this->assertHTMLEquals($expected, $html);
177 }
178
182 public function test_render_with_buttons($factory_method)
183 {
184 $f = $this->getMessageBoxFactory();
185 $bf = $this->getButtonFactory();
186 $r = $this->getDefaultRenderer();
187 $css_classes = self::$canonical_css_classes[$factory_method];
188
189 $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
190
191 $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withButtons($buttons);
192
193 $html = $this->normalizeHTML($r->render($g));
194 $expected = "<div class=\"alert $css_classes\" role=\"alert\">" .
195 "<h5 class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
196 $g->getType() . "_message</a></h5>Lorem ipsum dolor sit amet." .
197 "<div><button class=\"btn btn-default\" data-action=\"#\" id=\"id_1\">Confirm</button>" .
198 "<button class=\"btn btn-default\" data-action=\"#\" id=\"id_2\">Cancel</button></div></div>";
199 $this->assertHTMLEquals($expected, $html);
200 }
201
205 public function test_render_with_links($factory_method)
206 {
207 $f = $this->getMessageBoxFactory();
208 $lf = $this->getLinkFactory();
209 $r = $this->getDefaultRenderer();
210 $css_classes = self::$canonical_css_classes[$factory_method];
211
212 $links = [
213 $lf->standard("Open Exercise Assignment", "#"),
214 $lf->standard("Open other screen", "#"),
215 ];
216
217 $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withLinks($links);
218
219 $html = $this->normalizeHTML($r->render($g));
220 $expected = "<div class=\"alert $css_classes\" role=\"alert\">" .
221 "<h5 class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
222 $g->getType() . "_message</a></h5>Lorem ipsum dolor sit amet." .
223 "<ul><li><a href=\"#\" >Open Exercise Assignment</a></li>" .
224 "<li><a href=\"#\" >Open other screen</a></li></ul></div>";
225 $this->assertHTMLEquals($expected, $html);
226 }
227
231 public function test_render_with_buttons_and_links($factory_method)
232 {
233 $f = $this->getMessageBoxFactory();
234 $bf = $this->getButtonFactory();
235 $lf = $this->getLinkFactory();
236 $r = $this->getDefaultRenderer();
237 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
238 $css_classes = self::$canonical_css_classes[$factory_method];
239
240 $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
241 $links = [
242 $lf->standard("Open Exercise Assignment", "#"),
243 $lf->standard("Open other screen", "#"),
244 ];
245
246 $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withButtons($buttons)->withLinks($links);
247
248 $html = $this->normalizeHTML($r->render($g));
249 $expected = "<div class=\"alert $css_classes\" role=\"alert\">" .
250 "<h5 class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
251 $g->getType() . "_message</a></h5>Lorem ipsum dolor sit amet." .
252 "<div><button class=\"btn btn-default\" data-action=\"#\" id=\"id_1\">Confirm</button>" .
253 "<button class=\"btn btn-default\" data-action=\"#\" id=\"id_2\">Cancel</button></div>" .
254 "<ul><li><a href=\"#\" >Open Exercise Assignment</a></li>" .
255 "<li><a href=\"#\" >Open other screen</a></li></ul></div>";
256 $this->assertHTMLEquals($expected, $html);
257 }
258}
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:192
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:270
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
normalizeHTML($html)
Definition: Base.php:261
Test on Message Box implementation.
test_messagebox_messagetext($factory_method)
@dataProvider messagebox_type_provider
test_with_buttons_and_links($factory_method)
@dataProvider messagebox_type_provider
test_with_buttons($factory_method)
@dataProvider messagebox_type_provider
test_render_simple($factory_method)
@dataProvider messagebox_type_provider
test_render_with_links($factory_method)
@dataProvider messagebox_type_provider
test_implements_factory_interface($factory_method)
@dataProvider messagebox_type_provider
test_with_links($factory_method)
@dataProvider messagebox_type_provider
test_render_with_buttons($factory_method)
@dataProvider messagebox_type_provider
test_messagebox_types($factory_method)
@dataProvider messagebox_type_provider
test_render_with_buttons_and_links($factory_method)
@dataProvider messagebox_type_provider
static $canonical_css_classes
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
$links