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;
20 return new \ILIAS\UI\Implementation\Component\Button\Factory();
24 ,
"primary" =>
"btn btn-default btn-primary" 25 ,
"shy" =>
"btn btn-link" 26 ,
"tag" =>
"btn btn-tag btn-tag-relevance-veryhigh" 33 $this->assertInstanceOf(
"ILIAS\\UI\\Component\\Button\\Factory",
$f);
34 $this->assertInstanceOf(
35 "ILIAS\\UI\\Component\\Button\\Standard",
36 $f->standard(
"label",
"http://www.ilias.de")
38 $this->assertInstanceOf(
39 "ILIAS\\UI\\Component\\Button\\Primary",
40 $f->primary(
"label",
"http://www.ilias.de")
42 $this->assertInstanceOf(
43 "ILIAS\\UI\\Component\\Button\\Close",
46 $this->assertInstanceOf(
47 "ILIAS\\UI\\Component\\Button\\Shy",
48 $f->shy(
"label",
"http://www.ilias.de")
57 $this->expectException(\InvalidArgumentException::class);
59 $f->$factory_method($this,
"http://www.ilias.de");
67 $this->expectException(\InvalidArgumentException::class);
69 $f->$factory_method(
"label", $this);
78 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
80 $this->assertEquals(
"label",
$b->getLabel());
89 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
91 $b2 =
$b->withLabel(
"label2");
93 $this->assertEquals(
"label",
$b->getLabel());
94 $this->assertEquals(
"label2", $b2->getLabel());
103 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
105 $this->assertEquals(
"http://www.ilias.de",
$b->getAction());
114 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
116 $this->assertTrue(
$b->isActive());
125 $b =
$f->$factory_method(
"label",
"http://www.ilias.de")
126 ->withUnavailableAction();
128 $this->assertFalse(
$b->isActive());
129 $this->assertEquals(
"http://www.ilias.de",
$b->getAction());
138 foreach ([
"standard",
"primary"] as $method) {
139 $b =
$f->$method(
"label",
"http://www.ilias.de");
141 $this->assertFalse(
$b->hasLoadingAnimationOnClick());
143 $b = $b->withLoadingAnimationOnClick(
true);
145 $this->assertTrue($b->hasLoadingAnimationOnClick());
154 $ln =
"http://www.ilias.de";
156 $b =
$f->$factory_method(
"label", $ln);
161 $css_classes = self::$canonical_css_classes[$factory_method];
162 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" id=\"id_1\">" .
173 $ln =
"http://www.ilias.de";
175 $b =
$f->$factory_method(
"label", $ln)
176 ->withUnavailableAction();
181 $css_classes = self::$canonical_css_classes[$factory_method];
182 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" disabled=\"disabled\">" .
196 $expected =
"<button type=\"button\" class=\"close\" aria-label=\"close\">" .
197 " <span aria-hidden=\"true\">×</span>" .
199 $this->assertEquals($expected, $html);
207 $ln =
"http://www.ilias.de";
211 $b =
$f->$factory_method(
"label", $ln)
212 ->withOnLoadCode(
function ($id) use (&$ids) {
219 $this->assertCount(1, $ids);
222 $css_classes = self::$canonical_css_classes[$factory_method];
223 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" id=\"$id\">" .
235 ->withOnLoadCode(
function ($id) use (&$ids) {
242 $this->assertCount(1, $ids);
245 $expected =
"<button type=\"button\" class=\"close\" aria-label=\"close\" id=\"$id\">" .
246 " <span aria-hidden=\"true\">×</span>" .
248 $this->assertEquals($expected, $html);
254 $b =
$f->tag(
'tag',
'#');
256 $b->withRelevance(0);
257 $this->assertFalse(
"This should not happen");
259 $this->assertTrue(
true);
262 $b->withRelevance(
'notsoimportant');
263 $this->assertFalse(
"This should not happen");
265 $this->assertTrue(
true);
271 $expectations = array(
272 '<button class="btn btn-tag btn-tag-relevance-verylow" data-action="#" id="id_1">tag</button>',
273 '<button class="btn btn-tag btn-tag-relevance-low" data-action="#" id="id_2">tag</button>',
274 '<button class="btn btn-tag btn-tag-relevance-middle" data-action="#" id="id_3">tag</button>',
275 '<button class="btn btn-tag btn-tag-relevance-high" data-action="#" id="id_4">tag</button>',
276 '<button class="btn btn-tag btn-tag-relevance-veryhigh" data-action="#" id="id_5">tag</button>' 281 $t =
$f->tag(
'tag',
'#');
282 $possible_relevances = array(
289 foreach ($possible_relevances as $w) {
291 $r->render($t->withRelevance($w))
293 $expected = $expectations[array_search($w, $possible_relevances)];
294 $this->assertEquals($expected, $html);
302 $df = new \ILIAS\Data\Factory;
304 $bgcol = $df->color(
'#00ff00');
306 $b =
$f->tag(
'tag',
'#')
307 ->withBackgroundColor($bgcol);
309 $expected =
'<button class="btn btn-tag btn-tag-relevance-veryhigh" style="background-color: #00ff00; color: #000000;" data-action="#" id="id_1">tag</button>';
310 $this->assertEquals($expected, $html);
312 $fcol = $df->color(
'#ddd');
313 $b =
$b->withForegroundColor($fcol);
315 $expected =
'<button class="btn btn-tag btn-tag-relevance-veryhigh" style="background-color: #00ff00; color: #dddddd;" data-action="#" id="id_2">tag</button>';
316 $this->assertEquals($expected, $html);
323 $df = new \ILIAS\Data\Factory;
325 $classes = array(
'cl1',
'cl2');
326 $b =
$f->tag(
'tag',
'#')
327 ->withClasses($classes);
328 $this->assertEquals($classes,
$b->getClasses());
331 $expected =
'<button class="btn btn-tag btn-tag-relevance-veryhigh cl1 cl2" data-action="#" id="id_1">tag</button>';
332 $this->assertEquals($expected, $html);
340 $b =
$f->$factory_method(
"label",
"http://www.ilias.de")->withAriaLabel(
"ariatext");
341 $this->assertEquals(
"ariatext",
$b->getAriaLabel());
350 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
352 $this->assertEquals(
false,
$b->isEngageable());
353 $b2 =
$f->$factory_method(
"label",
"http://www.ilias.de")->withEngagedState(
false);
354 $this->assertEquals(
true, $b2->isEngageable());
356 $this->assertTrue(self::NOT_APPLICABLE);
366 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
368 $b =
$b->withEngagedState(
false);
369 $this->assertEquals(
false,
$b->isEngaged());
370 $b2 =
$f->$factory_method(
"label",
"http://www.ilias.de")->withEngagedState(
true);
371 $this->assertEquals(
true, $b2->isEngaged());
373 $this->assertTrue(self::NOT_APPLICABLE);
382 $ln =
"http://www.ilias.de";
385 $b =
$f->$factory_method(
"label", $ln)->withAriaLabel(
"aria label text");
386 $aria_label =
$b->getAriaLabel();
389 $css_classes = self::$canonical_css_classes[$factory_method];
390 $expected =
"<button class=\"$css_classes\" aria-label=\"$aria_label\" data-action=\"$ln\" id=\"id_1\">" .
401 $ln =
"http://www.ilias.de";
404 $b =
$f->$factory_method(
"label", $ln);
406 $b =
$b->withEngagedState(
true);
409 $css_classes = self::$canonical_css_classes[$factory_method];
410 $css_classes .=
' engaged';
411 $expected =
"<button class=\"$css_classes\" aria-pressed=\"true\" data-action=\"$ln\" id=\"id_1\">" .
416 $this->assertTrue(self::NOT_APPLICABLE);
426 $signal = $this->createMock(
C\Signal::class);
427 $button =
$f->$factory_method(
"label",
"http://www.example.com");
428 $this->assertEquals(
"http://www.example.com", $button->getAction());
430 $button = $button->withOnClick($signal);
432 $this->assertEquals([$signal], $button->getAction());
441 $signal1 = $this->createMock(
C\Signal::class);
442 $signal2 = $this->createMock(
C\Signal::class);
443 $button =
$f->$factory_method(
"label",
"http://www.example.com");
445 $button = $button->withOnClick($signal1)->appendOnClick($signal2);
447 $this->assertEquals([$signal1, $signal2], $button->getAction());
455 $ln =
"http://www.ilias.de";
457 $signal = $this->createMock(Signal::class);
458 $signal->method(
"__toString")
459 ->willReturn(
"MOCK_SIGNAL");
461 $b =
$f->$factory_method(
"label", $ln)
462 ->withOnClick($signal);
467 $css_classes = self::$canonical_css_classes[$factory_method];
468 $expected =
"<button class=\"$css_classes\" id=\"id_1\">" .
479 foreach ([
"primary",
"standard"] as $method) {
480 $ln =
"http://www.ilias.de";
483 $b =
$f->$method(
"label", $ln)
484 ->withLoadingAnimationOnClick(
true);
488 $css_classes = self::$canonical_css_classes[$method];
489 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" id=\"id_1\">" .
506 $signal = $this->createMock(
C\Signal::class);
508 $button =
$f->$factory_method(
"label", $signal);
510 $this->assertEquals([$signal], $button->getAction());
515 return array( array(
"standard")
Provides common functionality for UI tests.
assertHTMLEquals($expected_html_as_string, $html_as_string)
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])