ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $factory = new class extends NoUIFactory {
47 public function listing()
48 {
49 return new IC\Listing\Factory();
50 }
51 };
52 return $factory;
53 }
54
58 public function test_implements_factory_interface($factory_method)
59 {
60 $f = $this->getMessageBoxFactory();
61
62 $this->assertInstanceOf("ILIAS\\UI\\Component\\MessageBox\\Factory", $f);
63 $this->assertInstanceOf("ILIAS\\UI\\Component\\MessageBox\\MessageBox", $f->$factory_method("Lorem ipsum dolor sit amet."));
64 }
65
69 public function test_messagebox_types($factory_method)
70 {
71 $f = $this->getMessageBoxFactory();
72 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
73
74 $this->assertNotNull($g);
75 $this->assertEquals($factory_method, $g->getType());
76 }
77
81 public function test_messagebox_messagetext($factory_method)
82 {
83 $f = $this->getMessageBoxFactory();
84 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
85
86 $this->assertNotNull($g);
87 $this->assertEquals("Lorem ipsum dolor sit amet.", $g->getMessageText());
88 }
89
93 public function test_with_buttons($factory_method)
94 {
95 $f = $this->getMessageBoxFactory();
96 $bf = $this->getButtonFactory();
97 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
98
99 $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
100 $g2 = $g->withButtons($buttons);
101
102 $this->assertFalse(count($g->getButtons()) > 0);
103 $this->assertTrue(count($g2->getButtons()) > 0);
104 }
105
109 public function test_with_links($factory_method)
110 {
111 $f = $this->getMessageBoxFactory();
112 $lf = $this->getLinkFactory();
113 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
114
115 $links = [
116 $lf->standard("Open Exercise Assignment", "#"),
117 $lf->standard("Open other screen", "#"),
118 ];
119 $g2 = $g->withLinks($links);
120
121 $this->assertFalse(count($g->getLinks()) > 0);
122 $this->assertTrue(count($g2->getLinks()) > 0);
123 }
124
128 public function test_with_buttons_and_links($factory_method)
129 {
130 $f = $this->getMessageBoxFactory();
131 $bf = $this->getButtonFactory();
132 $lf = $this->getLinkFactory();
133 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
134
135 $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
136 $links = [
137 $lf->standard("Open Exercise Assignment", "#"),
138 $lf->standard("Open other screen", "#"),
139 ];
140 $g2 = $g->withButtons($buttons)->withLinks($links);
141
142 $this->assertFalse(count($g->getButtons()) > 0 && count($g->getLinks()) > 0);
143 $this->assertTrue(count($g2->getButtons()) > 0 && count($g2->getLinks()) > 0);
144 }
145
149 public function test_render_simple($factory_method)
150 {
151 $f = $this->getMessageBoxFactory();
152 $r = $this->getDefaultRenderer();
153 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
154 $css_classes = self::$canonical_css_classes[$factory_method];
155
156 $html = $this->normalizeHTML($r->render($g));
157 $expected = "<div class=\"alert $css_classes\" role=\"alert\">" .
158 "<h5 class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
159 $g->getType() . "_message</a></h5>Lorem ipsum dolor sit amet.</div>";
160 $this->assertHTMLEquals($expected, $html);
161 }
162
166 public function test_render_with_buttons($factory_method)
167 {
168 $f = $this->getMessageBoxFactory();
169 $bf = $this->getButtonFactory();
170 $r = $this->getDefaultRenderer();
171 $css_classes = self::$canonical_css_classes[$factory_method];
172
173 $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
174
175 $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withButtons($buttons);
176
177 $html = $this->normalizeHTML($r->render($g));
178 $expected = "<div class=\"alert $css_classes\" role=\"alert\">" .
179 "<h5 class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
180 $g->getType() . "_message</a></h5>Lorem ipsum dolor sit amet." .
181 "<div><button class=\"btn btn-default\" data-action=\"#\" id=\"id_1\">Confirm</button>" .
182 "<button class=\"btn btn-default\" data-action=\"#\" id=\"id_2\">Cancel</button></div></div>";
183 $this->assertHTMLEquals($expected, $html);
184 }
185
189 public function test_render_with_links($factory_method)
190 {
191 $f = $this->getMessageBoxFactory();
192 $lf = $this->getLinkFactory();
193 $r = $this->getDefaultRenderer();
194 $css_classes = self::$canonical_css_classes[$factory_method];
195
196 $links = [
197 $lf->standard("Open Exercise Assignment", "#"),
198 $lf->standard("Open other screen", "#"),
199 ];
200
201 $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withLinks($links);
202
203 $html = $this->normalizeHTML($r->render($g));
204 $expected = "<div class=\"alert $css_classes\" role=\"alert\">" .
205 "<h5 class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
206 $g->getType() . "_message</a></h5>Lorem ipsum dolor sit amet." .
207 "<ul><li><a href=\"#\" >Open Exercise Assignment</a></li>" .
208 "<li><a href=\"#\" >Open other screen</a></li></ul></div>";
209 $this->assertHTMLEquals($expected, $html);
210 }
211
215 public function test_render_with_buttons_and_links($factory_method)
216 {
217 $f = $this->getMessageBoxFactory();
218 $bf = $this->getButtonFactory();
219 $lf = $this->getLinkFactory();
220 $r = $this->getDefaultRenderer();
221 $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
222 $css_classes = self::$canonical_css_classes[$factory_method];
223
224 $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
225 $links = [
226 $lf->standard("Open Exercise Assignment", "#"),
227 $lf->standard("Open other screen", "#"),
228 ];
229
230 $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withButtons($buttons)->withLinks($links);
231
232 $html = $this->normalizeHTML($r->render($g));
233 $expected = "<div class=\"alert $css_classes\" role=\"alert\">" .
234 "<h5 class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
235 $g->getType() . "_message</a></h5>Lorem ipsum dolor sit amet." .
236 "<div><button class=\"btn btn-default\" data-action=\"#\" id=\"id_1\">Confirm</button>" .
237 "<button class=\"btn btn-default\" data-action=\"#\" id=\"id_2\">Cancel</button></div>" .
238 "<ul><li><a href=\"#\" >Open Exercise Assignment</a></li>" .
239 "<li><a href=\"#\" >Open other screen</a></li></ul></div>";
240 $this->assertHTMLEquals($expected, $html);
241 }
242}
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:263
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
normalizeHTML($html)
Definition: Base.php:363
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
$factory
Definition: metadata.php:58