5 require_once(__DIR__ .
"/../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ .
"/../../Base.php");
8 use \ILIAS\UI\Component as
C;
9 use \ILIAS\UI\Implementation\Component\Signal;
18 return new \ILIAS\UI\Implementation\Component\Button\Factory();
22 ,
"primary" =>
"btn btn-default btn-primary" 23 ,
"shy" =>
"btn btn-link" 24 ,
"tag" =>
"btn btn-tag btn-tag-relevance-veryhigh" 28 ,
"primary" =>
"ilSubmitInactive disabled" 29 ,
"shy" =>
"ilSubmitInactive disabled" 30 ,
"tag" =>
"btn-tag-inactive" 38 $this->assertInstanceOf(
"ILIAS\\UI\\Component\\Button\\Factory",
$f);
39 $this->assertInstanceOf(
40 "ILIAS\\UI\\Component\\Button\\Standard",
41 $f->standard(
"label",
"http://www.ilias.de")
43 $this->assertInstanceOf(
44 "ILIAS\\UI\\Component\\Button\\Primary",
45 $f->primary(
"label",
"http://www.ilias.de")
47 $this->assertInstanceOf(
48 "ILIAS\\UI\\Component\\Button\\Close",
51 $this->assertInstanceOf(
52 "ILIAS\\UI\\Component\\Button\\Shy",
53 $f->shy(
"label",
"http://www.ilias.de")
64 $f->$factory_method($this,
"http://www.ilias.de");
65 $this->assertFalse(
"This should not happen");
77 $f->$factory_method(
"label", $this);
78 $this->assertFalse(
"This should not happen");
89 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
91 $this->assertEquals(
"label", $b->getLabel());
100 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
102 $b2 = $b->withLabel(
"label2");
104 $this->assertEquals(
"label", $b->getLabel());
105 $this->assertEquals(
"label2", $b2->getLabel());
114 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
116 $this->assertEquals(
"http://www.ilias.de", $b->getAction());
125 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
127 $this->assertTrue($b->isActive());
136 $b =
$f->$factory_method(
"label",
"http://www.ilias.de")
137 ->withUnavailableAction();
139 $this->assertFalse($b->isActive());
140 $this->assertEquals(
"http://www.ilias.de", $b->getAction());
149 foreach ([
"standard",
"primary"] as $method) {
150 $b =
$f->$method(
"label",
"http://www.ilias.de");
152 $this->assertFalse($b->hasLoadingAnimationOnClick());
154 $b = $b->withLoadingAnimationOnClick(
true);
156 $this->assertTrue($b->hasLoadingAnimationOnClick());
165 $ln =
"http://www.ilias.de";
167 $b =
$f->$factory_method(
"label", $ln);
172 $css_classes = self::$canonical_css_classes[$factory_method];
173 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" id=\"id_1\">" .
184 $ln =
"http://www.ilias.de";
186 $b =
$f->$factory_method(
"label", $ln)
187 ->withUnavailableAction();
192 $css_classes = self::$canonical_css_classes[$factory_method];
193 $css_class_inactive = self::$canonical_css_inactivation_classes[$factory_method];
194 $expected =
"<button class=\"$css_classes $css_class_inactive\" data-action=\"$ln\">" .
208 $expected =
"<button type=\"button\" class=\"close\" data-dismiss=\"modal\">" .
209 " <span aria-hidden=\"true\">×</span>" .
210 " <span class=\"sr-only\">Close</span>" .
212 $this->assertEquals($expected,
$html);
220 $ln =
"http://www.ilias.de";
224 $b =
$f->$factory_method(
"label", $ln)
225 ->withOnLoadCode(
function (
$id) use (&$ids) {
232 $this->assertCount(1, $ids);
235 $css_classes = self::$canonical_css_classes[$factory_method];
236 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" id=\"$id\">" .
248 ->withOnLoadCode(
function (
$id) use (&$ids) {
255 $this->assertCount(1, $ids);
258 $expected =
"<button type=\"button\" class=\"close\" data-dismiss=\"modal\" id=\"$id\">" .
259 " <span aria-hidden=\"true\">×</span>" .
260 " <span class=\"sr-only\">Close</span>" .
262 $this->assertEquals($expected,
$html);
268 $b =
$f->tag(
'tag',
'#');
270 $b->withRelevance(0);
271 $this->assertFalse(
"This should not happen");
273 $this->assertTrue(
true);
276 $b->withRelevance(
'notsoimportant');
277 $this->assertFalse(
"This should not happen");
279 $this->assertTrue(
true);
285 $expectations = array(
286 '<button class="btn btn-tag btn-tag-relevance-verylow" data-action="#" id="id_1">tag</button>',
287 '<button class="btn btn-tag btn-tag-relevance-low" data-action="#" id="id_2">tag</button>',
288 '<button class="btn btn-tag btn-tag-relevance-middle" data-action="#" id="id_3">tag</button>',
289 '<button class="btn btn-tag btn-tag-relevance-high" data-action="#" id="id_4">tag</button>',
290 '<button class="btn btn-tag btn-tag-relevance-veryhigh" data-action="#" id="id_5">tag</button>' 295 $t =
$f->tag(
'tag',
'#');
296 $possible_relevances = array(
303 foreach ($possible_relevances as
$w) {
305 $r->render(
$t->withRelevance($w))
307 $expected = $expectations[array_search($w, $possible_relevances)];
308 $this->assertEquals($expected,
$html);
316 $df = new \ILIAS\Data\Factory;
318 $bgcol = $df->color(
'#00ff00');
320 $b =
$f->tag(
'tag',
'#')
321 ->withBackgroundColor($bgcol);
323 $expected =
'<button class="btn btn-tag btn-tag-relevance-veryhigh" style="background-color: #00ff00; color: #000000;" data-action="#" id="id_1">tag</button>';
324 $this->assertEquals($expected,
$html);
326 $fcol = $df->color(
'#ddd');
327 $b = $b->withForegroundColor($fcol);
329 $expected =
'<button class="btn btn-tag btn-tag-relevance-veryhigh" style="background-color: #00ff00; color: #dddddd;" data-action="#" id="id_2">tag</button>';
330 $this->assertEquals($expected,
$html);
337 $df = new \ILIAS\Data\Factory;
339 $classes = array(
'cl1',
'cl2');
340 $b =
$f->tag(
'tag',
'#')
341 ->withClasses($classes);
342 $this->assertEquals($classes, $b->getClasses());
345 $expected =
'<button class="btn btn-tag btn-tag-relevance-veryhigh cl1 cl2" data-action="#" id="id_1">tag</button>';
346 $this->assertEquals($expected, $html);
354 $b =
$f->$factory_method(
"label",
"http://www.ilias.de")->withAriaLabel(
"ariatext");
355 $this->assertEquals(
"ariatext", $b->getAriaLabel());
364 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
365 $this->assertEquals(
false, $b->isAriaChecked());
366 $b2 =
$f->$factory_method(
"label",
"http://www.ilias.de")->withAriaChecked();
367 $this->assertEquals(
true, $b2->isAriaChecked());
377 if ($factory_method ==
"standard") {
378 $ln =
"http://www.ilias.de";
381 $b =
$f->$factory_method(
"label", $ln)->withAriaLabel(
"aria label text");
382 $aria_label = $b->getAriaLabel();
385 $css_classes = self::$canonical_css_classes[$factory_method];
386 $expected =
"<button class=\"$css_classes\" aria-label=\"$aria_label\" data-action=\"$ln\" id=\"id_1\">" .
400 if ($factory_method ==
"standard") {
401 $ln =
"http://www.ilias.de";
404 $b =
$f->$factory_method(
"label", $ln)->withAriaChecked();
407 $css_classes = self::$canonical_css_classes[$factory_method];
408 $expected =
"<button class=\"$css_classes\" aria-checked=\"true\" data-action=\"$ln\" id=\"id_1\">" .
421 $signal = $this->createMock(
C\Signal::class);
422 $button =
$f->$factory_method(
"label",
"http://www.example.com");
423 $this->assertEquals(
"http://www.example.com", $button->getAction());
425 $button = $button->withOnClick($signal);
427 $this->assertEquals([$signal], $button->getAction());
436 $signal1 = $this->createMock(
C\Signal::class);
437 $signal2 = $this->createMock(
C\Signal::class);
438 $button =
$f->$factory_method(
"label",
"http://www.example.com");
440 $button = $button->withOnClick($signal1)->appendOnClick($signal2);
442 $this->assertEquals([$signal1, $signal2], $button->getAction());
450 $ln =
"http://www.ilias.de";
452 $signal = $this->createMock(Signal::class);
453 $signal->method(
"__toString")
454 ->willReturn(
"MOCK_SIGNAL");
456 $b =
$f->$factory_method(
"label", $ln)
457 ->withOnClick($signal);
462 $css_classes = self::$canonical_css_classes[$factory_method];
463 $expected =
"<button class=\"$css_classes\" id=\"id_1\">" .
474 foreach ([
"primary",
"standard"] as $method) {
475 $ln =
"http://www.ilias.de";
478 $b =
$f->$method(
"label", $ln)
479 ->withLoadingAnimationOnClick(
true);
483 $css_classes = self::$canonical_css_classes[$method];
484 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" id=\"id_1\">" .
501 $signal = $this->createMock(
C\Signal::class);
503 $button =
$f->$factory_method(
"label", $signal);
505 $this->assertEquals([$signal], $button->getAction());
510 return array( array(
"standard")
if(!array_key_exists('StateId', $_REQUEST)) $id
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Provides common functionality for UI tests.
assertHTMLEquals($expected_html_as_string, $html_as_string)