19 declare(strict_types=1);
21 require_once(__DIR__ .
"/../../../../../../vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ .
"/../../Base.php");
43 "standard" =>
"btn btn-default",
44 "primary" =>
"btn btn-default btn-primary",
45 "shy" =>
"btn btn-link",
46 "tag" =>
"btn btn-tag btn-tag-relevance-veryhigh" 53 $this->assertInstanceOf(
"ILIAS\\UI\\Component\\Button\\Factory",
$f);
54 $this->assertInstanceOf(
55 "ILIAS\\UI\\Component\\Button\\Standard",
56 $f->standard(
"label",
"http://www.ilias.de")
58 $this->assertInstanceOf(
59 "ILIAS\\UI\\Component\\Button\\Primary",
60 $f->primary(
"label",
"http://www.ilias.de")
62 $this->assertInstanceOf(
63 "ILIAS\\UI\\Component\\Button\\Close",
66 $this->assertInstanceOf(
67 "ILIAS\\UI\\Component\\Button\\Shy",
68 $f->shy(
"label",
"http://www.ilias.de")
72 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 75 $this->expectException(TypeError::class);
77 $f->$factory_method($this,
"http://www.ilias.de");
80 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 83 $this->expectException(InvalidArgumentException::class);
85 $f->$factory_method(
"label", $this);
88 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 92 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
94 $this->assertEquals(
"label",
$b->getLabel());
97 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 101 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
103 $b2 =
$b->withLabel(
"label2");
105 $this->assertEquals(
"label",
$b->getLabel());
106 $this->assertEquals(
"label2", $b2->getLabel());
109 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 113 $glyph =
new Glyph(
C\Symbol\
Glyph\Glyph::LIKE,
'');
114 $b =
$f->$factory_method(
'',
'')
115 ->withSymbol($glyph);
116 $this->assertEquals($glyph,
$b->getSymbol());
119 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 123 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
125 $this->assertEquals(
"http://www.ilias.de",
$b->getAction());
128 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 132 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
134 $this->assertTrue(
$b->isActive());
137 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 141 $b =
$f->$factory_method(
"label",
"http://www.ilias.de")
142 ->withUnavailableAction();
144 $this->assertFalse(
$b->isActive());
145 $this->assertEquals(
"http://www.ilias.de",
$b->getAction());
147 $b = $b->withUnavailableAction(
false);
148 $this->assertTrue($b->isActive());
157 foreach ([
"standard",
"primary"] as $method) {
158 $b =
$f->$method(
"label",
"http://www.ilias.de");
160 $this->assertFalse(
$b->hasLoadingAnimationOnClick());
162 $b = $b->withLoadingAnimationOnClick(
true);
164 $this->assertTrue($b->hasLoadingAnimationOnClick());
168 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 171 $ln =
"http://www.ilias.de";
173 $b =
$f->$factory_method(
"label", $ln);
174 $r = $this->getDefaultRenderer();
176 $html = $this->normalizeHTML(
$r->render(
$b));
178 $css_classes = self::$canonical_css_classes[$factory_method];
179 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" id=\"id_1\">" .
182 $this->assertHTMLEquals($expected, $html);
185 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 188 $ln =
"http://www.ilias.de";
190 $b =
$f->$factory_method(
"label", $ln)
191 ->withUnavailableAction();
192 $r = $this->getDefaultRenderer();
194 $html = $this->normalizeHTML(
$r->render(
$b));
196 $css_classes = self::$canonical_css_classes[$factory_method];
197 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" disabled=\"disabled\">" .
200 $this->assertHTMLEquals($expected, $html);
206 $r = $this->getDefaultRenderer();
209 $html = $this->normalizeHTML(
$r->render(
$b));
211 $expected =
"<button type=\"button\" class=\"close\" aria-label=\"close\">" .
212 " <span aria-hidden=\"true\">×</span>" .
214 $this->assertEquals($expected, $html);
220 $r = $this->getDefaultRenderer();
223 $html = $this->normalizeHTML(
$r->render(
$b));
225 $expected =
"<button type=\"button\" class=\"minimize\" aria-label=\"minimize\">" .
226 " <span aria-hidden=\"true\">−</span>" .
228 $this->assertEquals($expected, $html);
231 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 234 $ln =
"http://www.ilias.de";
236 $r = $this->getDefaultRenderer();
238 $b =
$f->$factory_method(
"label", $ln)
239 ->withOnLoadCode(
function (
$id) use (&$ids):
string {
244 $html = $this->normalizeHTML(
$r->render(
$b));
246 $this->assertCount(1, $ids);
249 $css_classes = self::$canonical_css_classes[$factory_method];
250 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" id=\"$id\">" .
253 $this->assertHTMLEquals($expected, $html);
259 $r = $this->getDefaultRenderer();
262 ->withOnLoadCode(
function (
$id) use (&$ids):
string {
267 $html = $this->normalizeHTML(
$r->render(
$b));
269 $this->assertCount(1, $ids);
272 $expected =
"<button type=\"button\" class=\"close\" aria-label=\"close\" id=\"$id\">" .
273 " <span aria-hidden=\"true\">×</span>" .
275 $this->assertEquals($expected, $html);
281 $b =
$f->tag(
'tag',
'#');
283 $this->expectException(TypeError::class);
284 $b->withRelevance(0);
286 $this->expectException(TypeError::class);
287 $b->withRelevance(
'notsoimportant');
292 $expectations = array(
293 '<button class="btn btn-tag btn-tag-relevance-verylow" data-action="#" id="id_1">tag</button>',
294 '<button class="btn btn-tag btn-tag-relevance-low" data-action="#" id="id_2">tag</button>',
295 '<button class="btn btn-tag btn-tag-relevance-middle" data-action="#" id="id_3">tag</button>',
296 '<button class="btn btn-tag btn-tag-relevance-high" data-action="#" id="id_4">tag</button>',
297 '<button class="btn btn-tag btn-tag-relevance-veryhigh" data-action="#" id="id_5">tag</button>' 301 $r = $this->getDefaultRenderer();
302 $t =
$f->tag(
'tag',
'#');
303 $possible_relevances = array(
310 foreach ($possible_relevances as $w) {
311 $html = $this->normalizeHTML(
312 $r->render($t->withRelevance($w))
314 $expected = $expectations[array_search($w, $possible_relevances)];
315 $this->assertEquals($expected, $html);
322 $r = $this->getDefaultRenderer();
323 $df = new \ILIAS\Data\Factory();
325 $bgcol = $df->color(
'#00ff00');
327 $b =
$f->tag(
'tag',
'#')
328 ->withBackgroundColor($bgcol);
329 $html = $this->normalizeHTML(
$r->render(
$b));
330 $expected =
'<button class="btn btn-tag btn-tag-relevance-veryhigh" style="background-color: #00ff00; color: #000000;" data-action="#" id="id_1">tag</button>';
331 $this->assertEquals($expected, $html);
333 $fcol = $df->color(
'#ddd');
334 $b =
$b->withForegroundColor($fcol);
335 $html = $this->normalizeHTML(
$r->render(
$b));
336 $expected =
'<button class="btn btn-tag btn-tag-relevance-veryhigh" style="background-color: #00ff00; color: #dddddd;" data-action="#" id="id_2">tag</button>';
337 $this->assertEquals($expected, $html);
343 $r = $this->getDefaultRenderer();
344 $df = new \ILIAS\Data\Factory();
346 $classes = array(
'cl1',
'cl2');
347 $b =
$f->tag(
'tag',
'#')
348 ->withClasses($classes);
349 $this->assertEquals($classes,
$b->getClasses());
351 $html = $this->normalizeHTML(
$r->render(
$b));
352 $expected =
'<button class="btn btn-tag btn-tag-relevance-veryhigh cl1 cl2" data-action="#" id="id_1">tag</button>';
353 $this->assertEquals($expected, $html);
356 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 360 $b =
$f->$factory_method(
"label",
"http://www.ilias.de")->withAriaLabel(
"ariatext");
361 $this->assertEquals(
"ariatext",
$b->getAriaLabel());
364 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 368 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
370 $this->assertEquals(
false,
$b->isEngageable());
371 $b2 =
$f->$factory_method(
"label",
"http://www.ilias.de")->withEngagedState(
false);
372 $this->assertEquals(
true, $b2->isEngageable());
374 $this->assertTrue(self::NOT_APPLICABLE);
378 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 382 $b =
$f->$factory_method(
"label",
"http://www.ilias.de");
384 $b =
$b->withEngagedState(
false);
385 $this->assertEquals(
false,
$b->isEngaged());
386 $b2 =
$f->$factory_method(
"label",
"http://www.ilias.de")->withEngagedState(
true);
387 $this->assertEquals(
true, $b2->isEngaged());
389 $this->assertTrue(self::NOT_APPLICABLE);
393 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 396 $ln =
"http://www.ilias.de";
398 $r = $this->getDefaultRenderer();
399 $b =
$f->$factory_method(
"label", $ln)->withAriaLabel(
"aria label text");
400 $aria_label =
$b->getAriaLabel();
402 $html = $this->normalizeHTML(
$r->render(
$b));
403 $css_classes = self::$canonical_css_classes[$factory_method];
404 $expected =
"<button class=\"$css_classes\" aria-label=\"$aria_label\" data-action=\"$ln\" id=\"id_1\">" .
407 $this->assertHTMLEquals($expected, $html);
410 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 413 $ln =
"http://www.ilias.de";
415 $r = $this->getDefaultRenderer();
416 $b =
$f->$factory_method(
"label", $ln);
418 $b =
$b->withEngagedState(
true);
420 $html = $this->normalizeHTML(
$r->render(
$b));
421 $css_classes = self::$canonical_css_classes[$factory_method];
422 $css_classes .=
' engaged';
423 $expected =
"<button class=\"$css_classes\" aria-pressed=\"true\" data-action=\"$ln\" id=\"id_1\">" .
426 $this->assertHTMLEquals($expected, $html);
428 $this->assertTrue(self::NOT_APPLICABLE);
432 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 436 $signal = $this->createMock(
C\Signal::class);
437 $button =
$f->$factory_method(
"label",
"http://www.example.com");
438 $this->assertEquals(
"http://www.example.com", $button->getAction());
440 $button = $button->withOnClick($signal);
442 $this->assertEquals([$signal], $button->getAction());
445 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 449 $signal1 = $this->createMock(
C\Signal::class);
450 $signal2 = $this->createMock(
C\Signal::class);
451 $button =
$f->$factory_method(
"label",
"http://www.example.com");
453 $button = $button->withOnClick($signal1)->appendOnClick($signal2);
455 $this->assertEquals([$signal1, $signal2], $button->getAction());
458 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 461 $ln =
"http://www.ilias.de";
463 $signal = $this->createMock(Signal::class);
464 $signal->method(
"__toString")
465 ->willReturn(
"MOCK_SIGNAL");
467 $b =
$f->$factory_method(
"label", $ln)
468 ->withOnClick($signal);
469 $r = $this->getDefaultRenderer();
471 $html = $this->normalizeHTML(
$r->render(
$b));
473 $css_classes = self::$canonical_css_classes[$factory_method];
474 $expected =
"<button class=\"$css_classes\" id=\"id_1\">" .
477 $this->assertHTMLEquals($expected, $html);
485 foreach ([
"primary",
"standard"] as $method) {
486 $ln =
"http://www.ilias.de";
488 $r = $this->getDefaultRenderer();
489 $b =
$f->$method(
"label", $ln)
490 ->withLoadingAnimationOnClick(
true);
492 $html = $this->normalizeHTML(
$r->render(
$b));
494 $css_classes = self::$canonical_css_classes[$method];
495 $expected =
"<button class=\"$css_classes\" data-action=\"$ln\" id=\"id_1\">" .
498 $this->assertHTMLEquals($expected, $html);
502 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 506 $r = $this->getDefaultRenderer();
507 $ln =
"http://www.ilias.de";
510 $f->$factory_method(
"label", $ln)
511 ->withHelpTopics(
new Help\
Topic(
"a"),
new Help\
Topic(
"b"));
513 $css_classes = self::$canonical_css_classes[$factory_method];
515 "<div class=\"c-tooltip__container\">" .
516 "<button class=\"$css_classes\" aria-describedby=\"id_2\" data-action=\"$ln\" id=\"id_1\" >" .
519 "<div id=\"id_2\" role=\"tooltip\" class=\"c-tooltip c-tooltip--hidden\">" .
520 "<p>tooltip: a</p>" .
521 "<p>tooltip: b</p>" .
525 $html = $this->normalizeHTML(
$r->render($button));
526 $this->assertHTMLEquals($expected, $html);
532 #[\PHPUnit\Framework\Attributes\DataProvider('getButtonTypeProvider')] 536 $signal = $this->createMock(
C\Signal::class);
538 $button =
$f->$factory_method(
"label", $signal);
540 $this->assertEquals([$signal], $button->getAction());
556 $r = $this->getDefaultRenderer();
557 $glyph =
new Glyph(
C\Symbol\
Glyph\Glyph::LIKE,
'The Glyph Label');
558 $button =
$f->standard(
'The Button Label',
'')
559 ->withSymbol($glyph);
562 $this->assertStringContainsString(
563 'aria-label="The Glyph Label"',
568 $expected = $this->brutallyTrimHTML(
570 <button class="btn btn-default" data-action=""> 571 <span class="glyph" role="img"> 572 <span class="glyphicon il-glyphicon-like" aria-hidden="true"></span> 577 $html = $this->brutallyTrimHTML(
$r->render($button));
578 $this->assertHTMLEquals($expected, $html);
This is just a class that marks a string as a help topic.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins