ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
MessageBoxTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../../../vendor/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 static function getMessageboxTypeProvider(): 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  new IC\Listing\Workflow\Factory(),
73  new IC\Listing\CharacteristicValue\Factory(),
74  new IC\Listing\Entity\Factory(),
75  );
76  }
77  };
78  }
79 
80  #[\PHPUnit\Framework\Attributes\DataProvider('getMessageboxTypeProvider')]
81  public function testImplementsFactoryInterface(string $factory_method): void
82  {
83  $f = $this->getMessageBoxFactory();
84 
85  $this->assertInstanceOf("ILIAS\\UI\\Component\\MessageBox\\Factory", $f);
86  $this->assertInstanceOf("ILIAS\\UI\\Component\\MessageBox\\MessageBox", $f->$factory_method("Lorem ipsum dolor sit amet."));
87  }
88 
89  #[\PHPUnit\Framework\Attributes\DataProvider('getMessageboxTypeProvider')]
90  public function testMessageboxTypes(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 
99  #[\PHPUnit\Framework\Attributes\DataProvider('getMessageboxTypeProvider')]
100  public function testMessageboxMessagetext(string $factory_method): void
101  {
102  $f = $this->getMessageBoxFactory();
103  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
104 
105  $this->assertNotNull($g);
106  $this->assertEquals("Lorem ipsum dolor sit amet.", $g->getMessageText());
107  }
108 
109  #[\PHPUnit\Framework\Attributes\DataProvider('getMessageboxTypeProvider')]
110  public function testWithButtons(string $factory_method): void
111  {
112  $f = $this->getMessageBoxFactory();
113  $bf = $this->getButtonFactory();
114  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
115 
116  $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
117  $g2 = $g->withButtons($buttons);
118 
119  $this->assertEmpty($g->getButtons());
120  $this->assertNotEmpty($g2->getButtons());
121  }
122 
123  #[\PHPUnit\Framework\Attributes\DataProvider('getMessageboxTypeProvider')]
124  public function testWithLinks(string $factory_method): void
125  {
126  $f = $this->getMessageBoxFactory();
127  $lf = $this->getLinkFactory();
128  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
129 
130  $links = [
131  $lf->standard("Open Exercise Assignment", "#"),
132  $lf->standard("Open other screen", "#"),
133  ];
134  $g2 = $g->withLinks($links);
135 
136  $this->assertEmpty($g->getLinks());
137  $this->assertNotEmpty($g2->getLinks());
138  }
139 
140  #[\PHPUnit\Framework\Attributes\DataProvider('getMessageboxTypeProvider')]
141  public function testWithButtonsAndLinks(string $factory_method): void
142  {
143  $f = $this->getMessageBoxFactory();
144  $bf = $this->getButtonFactory();
145  $lf = $this->getLinkFactory();
146  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
147 
148  $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
149  $links = [
150  $lf->standard("Open Exercise Assignment", "#"),
151  $lf->standard("Open other screen", "#"),
152  ];
153  $g2 = $g->withButtons($buttons)->withLinks($links);
154 
155  $this->assertFalse(count($g->getButtons()) > 0 && count($g->getLinks()) > 0);
156  $this->assertTrue(count($g2->getButtons()) > 0 && count($g2->getLinks()) > 0);
157  }
158 
159  #[\PHPUnit\Framework\Attributes\DataProvider('getMessageboxTypeProvider')]
160  public function testRenderSimple(string $factory_method): void
161  {
162  $f = $this->getMessageBoxFactory();
163  $r = $this->getDefaultRenderer();
164  $g = $f->$factory_method("Lorem ipsum dolor sit amet.");
165  $css_classes = self::$canonical_css_classes[$factory_method];
166  $role_type = self::$canonical_role_types[$factory_method];
167 
168  $html = $this->normalizeHTML($r->render($g));
169  $expected = "<div class=\"alert $css_classes\" role=\"$role_type\">" .
170  "<div class=\"ilAccHeadingHidden\"><a name=\"il_message_focus\">" .
171  $g->getType() . "_message</a></div>Lorem ipsum dolor sit amet.</div>";
172  $this->assertHTMLEquals($expected, $html);
173  }
174 
175  #[\PHPUnit\Framework\Attributes\DataProvider('getMessageboxTypeProvider')]
176  public function testRenderWithButtons(string $factory_method): void
177  {
178  $f = $this->getMessageBoxFactory();
179  $bf = $this->getButtonFactory();
180  $r = $this->getDefaultRenderer();
181  $css_classes = self::$canonical_css_classes[$factory_method];
182  $role_type = self::$canonical_role_types[$factory_method];
183 
184  $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
185 
186  $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withButtons($buttons);
187 
188  $html = $this->normalizeHTML($r->render($g));
189  $expected = "<div class=\"alert $css_classes\" role=\"$role_type\">" .
190  "<div class=\"ilAccHeadingHidden\"><a name=\"il_message_focus\">" .
191  $g->getType() . "_message</a></div>Lorem ipsum dolor sit amet." .
192  "<div><button class=\"btn btn-default\" data-action=\"#\" id=\"id_1\">Confirm</button>" .
193  "<button class=\"btn btn-default\" data-action=\"#\" id=\"id_2\">Cancel</button></div></div>";
194  $this->assertHTMLEquals($expected, $html);
195  }
196 
197  #[\PHPUnit\Framework\Attributes\DataProvider('getMessageboxTypeProvider')]
198  public function testRenderWithLinks(string $factory_method): void
199  {
200  $f = $this->getMessageBoxFactory();
201  $lf = $this->getLinkFactory();
202  $r = $this->getDefaultRenderer();
203  $css_classes = self::$canonical_css_classes[$factory_method];
204  $role_type = self::$canonical_role_types[$factory_method];
205 
206  $links = [
207  $lf->standard("Open Exercise Assignment", "#"),
208  $lf->standard("Open other screen", "#"),
209  ];
210 
211  $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withLinks($links);
212 
213  $html = $this->normalizeHTML($r->render($g));
214  $expected = "<div class=\"alert $css_classes\" role=\"$role_type\">" .
215  "<div class=\"ilAccHeadingHidden\"><a name=\"il_message_focus\">" .
216  $g->getType() . "_message</a></div>Lorem ipsum dolor sit amet." .
217  "<ul><li><a href=\"#\" >Open Exercise Assignment</a></li>" .
218  "<li><a href=\"#\" >Open other screen</a></li></ul></div>";
219  $this->assertHTMLEquals($expected, $html);
220  }
221 
222  #[\PHPUnit\Framework\Attributes\DataProvider('getMessageboxTypeProvider')]
223  public function testRenderWithButtonsAndLinks(string $factory_method): void
224  {
225  $f = $this->getMessageBoxFactory();
226  $bf = $this->getButtonFactory();
227  $lf = $this->getLinkFactory();
228  $r = $this->getDefaultRenderer();
229  $css_classes = self::$canonical_css_classes[$factory_method];
230  $role_type = self::$canonical_role_types[$factory_method];
231 
232  $buttons = [$bf->standard("Confirm", "#"), $bf->standard("Cancel", "#")];
233  $links = [
234  $lf->standard("Open Exercise Assignment", "#"),
235  $lf->standard("Open other screen", "#"),
236  ];
237 
238  $g = $f->$factory_method("Lorem ipsum dolor sit amet.")->withButtons($buttons)->withLinks($links);
239 
240  $html = $this->normalizeHTML($r->render($g));
241  $expected = "<div class=\"alert $css_classes\" role=\"$role_type\">" .
242  "<div class=\"ilAccHeadingHidden\"><a name=\"il_message_focus\">" .
243  $g->getType() . "_message</a></div>Lorem ipsum dolor sit amet." .
244  "<div><button class=\"btn btn-default\" data-action=\"#\" id=\"id_1\">Confirm</button>" .
245  "<button class=\"btn btn-default\" data-action=\"#\" id=\"id_2\">Cancel</button></div>" .
246  "<ul><li><a href=\"#\" >Open Exercise Assignment</a></li>" .
247  "<li><a href=\"#\" >Open other screen</a></li></ul></div>";
248  $this->assertHTMLEquals($expected, $html);
249  }
250 }
static getMessageboxTypeProvider()
testWithButtons(string $factory_method)
testImplementsFactoryInterface(string $factory_method)
Test on Message Box implementation.
The progress of the process/task cannot be calculated (yet), but it has started processing.
Definition: Status.php:42
testRenderWithButtons(string $factory_method)
testWithButtonsAndLinks(string $factory_method)
testWithLinks(string $factory_method)
testRenderWithButtonsAndLinks(string $factory_method)
testRenderWithLinks(string $factory_method)
static array $canonical_role_types
testMessageboxTypes(string $factory_method)
testRenderSimple(string $factory_method)
testMessageboxMessagetext(string $factory_method)
static array $canonical_css_classes
$r