ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
MessageBoxTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
24 use ILIAS\UI\Component as C;
26 
31 {
32  public function getMessageBoxFactory(): IC\MessageBox\Factory
33  {
34  return new IC\MessageBox\Factory();
35  }
36  public function getButtonFactory(): IC\Button\Factory
37  {
38  return new IC\Button\Factory();
39  }
40  public function getLinkFactory(): IC\Link\Factory
41  {
42  return new IC\Link\Factory();
43  }
44 
45  public function messagebox_type_provider(): array
46  {
47  return array( array(C\MessageBox\MessageBox::FAILURE)
48  , array(C\MessageBox\MessageBox::SUCCESS)
49  , array(C\MessageBox\MessageBox::INFO)
50  , array(C\MessageBox\MessageBox::CONFIRMATION)
51  );
52  }
53 
54  public static array $canonical_css_classes = array( C\MessageBox\MessageBox::FAILURE => "alert-danger"
55  , C\MessageBox\MessageBox::SUCCESS => "alert-success"
56  , C\MessageBox\MessageBox::INFO => "alert-info"
57  , C\MessageBox\MessageBox::CONFIRMATION => "alert-warning"
58  );
59 
60  public static array $canonical_role_types = array( C\MessageBox\MessageBox::FAILURE => "alert"
61  , C\MessageBox\MessageBox::SUCCESS => "status"
62  , C\MessageBox\MessageBox::INFO => "status"
63  , C\MessageBox\MessageBox::CONFIRMATION => "status"
64  );
65 
66  public function getUIFactory(): NoUIFactory
67  {
68  return new class () extends NoUIFactory {
69  public function listing(): IC\Listing\Factory
70  {
71  return new IC\Listing\Factory();
72  }
73  };
74  }
75 
79  public function test_implements_factory_interface(string $factory_method): void
80  {
81  $f = $this->getMessageBoxFactory();
82 
83  $this->assertInstanceOf("ILIAS\\UI\\Component\\MessageBox\\Factory", $f);
84  $this->assertInstanceOf("ILIAS\\UI\\Component\\MessageBox\\MessageBox", $f->$factory_method("Lorem ipsum dolor sit amet."));
85  }
86 
90  public function test_messagebox_types(string $factory_method): void
91  {
92  $f = $this->getMessageBoxFactory();
93  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
94 
95  $this->assertNotNull($g);
96  $this->assertEquals($factory_method, $g->getType());
97  }
98 
102  public function test_messagebox_messagetext(string $factory_method): void
103  {
104  $f = $this->getMessageBoxFactory();
105  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
106 
107  $this->assertNotNull($g);
108  $this->assertEquals("Lorem ipsum dolor sit amet.", $g->getMessageText());
109  }
110 
114  public function test_with_buttons(string $factory_method): void
115  {
116  $f = $this->getMessageBoxFactory();
117  $bf = $this->getButtonFactory();
118  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
119 
120  $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
121  $g2 = $g->withButtons($buttons);
122 
123  $this->assertEmpty($g->getButtons());
124  $this->assertNotEmpty($g2->getButtons());
125  }
126 
130  public function test_with_links(string $factory_method): void
131  {
132  $f = $this->getMessageBoxFactory();
133  $lf = $this->getLinkFactory();
134  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
135 
136  $links = [
137  $lf->standard("Open Exercise Assignment", "#"),
138  $lf->standard("Open other screen", "#"),
139  ];
140  $g2 = $g->withLinks($links);
141 
142  $this->assertEmpty($g->getLinks());
143  $this->assertNotEmpty($g2->getLinks());
144  }
145 
149  public function test_with_buttons_and_links(string $factory_method): void
150  {
151  $f = $this->getMessageBoxFactory();
152  $bf = $this->getButtonFactory();
153  $lf = $this->getLinkFactory();
154  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
155 
156  $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
157  $links = [
158  $lf->standard("Open Exercise Assignment", "#"),
159  $lf->standard("Open other screen", "#"),
160  ];
161  $g2 = $g->withButtons($buttons)->withLinks($links);
162 
163  $this->assertFalse(count($g->getButtons()) > 0 && count($g->getLinks()) > 0);
164  $this->assertTrue(count($g2->getButtons()) > 0 && count($g2->getLinks()) > 0);
165  }
166 
170  public function test_render_simple(string $factory_method): void
171  {
172  $f = $this->getMessageBoxFactory();
173  $r = $this->getDefaultRenderer();
174  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
175  $css_classes = self::$canonical_css_classes[$factory_method];
176  $role_type = self::$canonical_role_types[$factory_method];
177 
178  $html = $this->normalizeHTML($r->render($g));
179  $expected = "<div class=\"alert $css_classes\" role=\"$role_type\">" .
180  "<div class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
181  $g->getType() . "_message</a></div>Lorem ipsum dolor sit amet.</div>";
182  $this->assertHTMLEquals($expected, $html);
183  }
184 
188  public function test_render_with_buttons(string $factory_method): void
189  {
190  $f = $this->getMessageBoxFactory();
191  $bf = $this->getButtonFactory();
192  $r = $this->getDefaultRenderer();
193  $css_classes = self::$canonical_css_classes[$factory_method];
194  $role_type = self::$canonical_role_types[$factory_method];
195 
196  $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
197 
198  $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withButtons($buttons);
199 
200  $html = $this->normalizeHTML($r->render($g));
201  $expected = "<div class=\"alert $css_classes\" role=\"$role_type\">" .
202  "<div class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
203  $g->getType() . "_message</a></div>Lorem ipsum dolor sit amet." .
204  "<div><button class=\"btn btn-default\" data-action=\"#\" id=\"id_1\">Confirm</button>" .
205  "<button class=\"btn btn-default\" data-action=\"#\" id=\"id_2\">Cancel</button></div></div>";
206  $this->assertHTMLEquals($expected, $html);
207  }
208 
212  public function test_render_with_links(string $factory_method): void
213  {
214  $f = $this->getMessageBoxFactory();
215  $lf = $this->getLinkFactory();
216  $r = $this->getDefaultRenderer();
217  $css_classes = self::$canonical_css_classes[$factory_method];
218  $role_type = self::$canonical_role_types[$factory_method];
219 
220  $links = [
221  $lf->standard("Open Exercise Assignment", "#"),
222  $lf->standard("Open other screen", "#"),
223  ];
224 
225  $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withLinks($links);
226 
227  $html = $this->normalizeHTML($r->render($g));
228  $expected = "<div class=\"alert $css_classes\" role=\"$role_type\">" .
229  "<div class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
230  $g->getType() . "_message</a></div>Lorem ipsum dolor sit amet." .
231  "<ul><li><a href=\"#\" >Open Exercise Assignment</a></li>" .
232  "<li><a href=\"#\" >Open other screen</a></li></ul></div>";
233  $this->assertHTMLEquals($expected, $html);
234  }
235 
239  public function test_render_with_buttons_and_links(string $factory_method): void
240  {
241  $f = $this->getMessageBoxFactory();
242  $bf = $this->getButtonFactory();
243  $lf = $this->getLinkFactory();
244  $r = $this->getDefaultRenderer();
245  $css_classes = self::$canonical_css_classes[$factory_method];
246  $role_type = self::$canonical_role_types[$factory_method];
247 
248  $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
249  $links = [
250  $lf->standard("Open Exercise Assignment", "#"),
251  $lf->standard("Open other screen", "#"),
252  ];
253 
254  $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withButtons($buttons)->withLinks($links);
255 
256  $html = $this->normalizeHTML($r->render($g));
257  $expected = "<div class=\"alert $css_classes\" role=\"$role_type\">" .
258  "<div class=\"ilAccHeadingHidden\"><a id=\"il_message_focus\" name=\"il_message_focus\">" .
259  $g->getType() . "_message</a></div>Lorem ipsum dolor sit amet." .
260  "<div><button class=\"btn btn-default\" data-action=\"#\" id=\"id_1\">Confirm</button>" .
261  "<button class=\"btn btn-default\" data-action=\"#\" id=\"id_2\">Cancel</button></div>" .
262  "<ul><li><a href=\"#\" >Open Exercise Assignment</a></li>" .
263  "<li><a href=\"#\" >Open other screen</a></li></ul></div>";
264  $this->assertHTMLEquals($expected, $html);
265  }
266 }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
test_render_with_buttons(string $factory_method)
messagebox_type_provider
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
test_render_with_buttons_and_links(string $factory_method)
messagebox_type_provider
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
test_render_simple(string $factory_method)
messagebox_type_provider
test_messagebox_types(string $factory_method)
messagebox_type_provider
test_implements_factory_interface(string $factory_method)
messagebox_type_provider
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
test_messagebox_messagetext(string $factory_method)
messagebox_type_provider
Provides common functionality for UI tests.
Definition: Base.php:298
test_with_buttons_and_links(string $factory_method)
messagebox_type_provider
static array $canonical_role_types
test_with_buttons(string $factory_method)
messagebox_type_provider
test_render_with_links(string $factory_method)
messagebox_type_provider
static array $canonical_css_classes
test_with_links(string $factory_method)
messagebox_type_provider
normalizeHTML(string $html)
Definition: Base.php:422