ILIAS  release_7 Revision v7.30-3-g800a261c036
BulkyLinkTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \ILIAS\UI\Component\Link as C;
9use \ILIAS\UI\Implementation\Component as I;
10
15{
19 protected $factory;
20
21 public function setUp() : void
22 {
23 $this->factory = new I\Link\Factory();
24 $this->glyph = new I\Symbol\Glyph\Glyph("briefcase", "briefcase");
25 $this->icon = new I\Symbol\Icon\Standard("someExample", "Example", "small", false);
26 $this->target = new \ILIAS\Data\URI("http://www.ilias.de");
27 }
28
29 public function testImplementsInterfaces()
30 {
31 $link = $this->factory->bulky($this->glyph, "label", $this->target);
32 $this->assertInstanceOf(C\Bulky::class, $link);
33 $this->assertInstanceOf(C\Link::class, $link);
34 }
35
36 public function testWrongConstruction()
37 {
38 $this->expectException(\TypeError::class);
39 $link = $this->factory->bulky('wrong param', "label", $this->target);
40 }
41
42 public function testWithAriaRole()
43 {
44 try {
45 $b = $this->factory->bulky($this->glyph, "label", $this->target)
46 ->withAriaRole(I\Button\Bulky::MENUITEM);
47 $this->assertEquals("menuitem", $b->getAriaRole());
48 } catch (\InvalidArgumentException $e) {
49 $this->assertFalse("This should not happen");
50 }
51 }
52
53 public function testWithAriaRoleIncorrect()
54 {
55 try {
56 $this->factory->bulky($this->glyph, "label", $this->target)
57 ->withAriaRole("loremipsum");
58 $this->assertFalse("This should not happen");
59 } catch (\InvalidArgumentException $e) {
60 $this->assertTrue(true);
61 }
62 }
63
64 public function testGetLabell()
65 {
66 $label = 'some label for the link';
67 $link = $this->factory->bulky($this->glyph, $label, $this->target);
68 $this->assertEquals($label, $link->getLabel());
69 }
70
71 public function testGetGlyphSymbol()
72 {
73 $link = $this->factory->bulky($this->glyph, "label", $this->target);
74 $this->assertEquals($this->glyph, $link->getSymbol());
75 $link = $this->factory->bulky($this->icon, "label", $this->target);
76 $this->assertEquals($this->icon, $link->getSymbol());
77 }
78
79 public function testGetAction()
80 {
81 $plain = "http://www.ilias.de";
82 $with_query = $plain . "?query1=1";
83 $with_multi_query = $with_query . "&query2=2";
84 $with_fragment = $plain . "#fragment";
85 $with_multi_query_and_fragment_uri = $with_multi_query . $with_fragment;
86
87 $plain_uri = new \ILIAS\Data\URI($plain);
88 $with_query_uri = new \ILIAS\Data\URI($with_query);
89 $with_multi_query_uri = new \ILIAS\Data\URI($with_multi_query);
90 $with_fragment_uri = new \ILIAS\Data\URI($with_fragment);
91 $with_multi_query_and_fragment_uri = new \ILIAS\Data\URI($with_multi_query_and_fragment_uri);
92
93 $this->assertEquals($plain, $this->factory->bulky($this->glyph, "label", $plain_uri)->getAction());
94 $this->assertEquals($with_query, $this->factory->bulky($this->glyph, "label", $with_query_uri)->getAction());
95 $this->assertEquals($with_multi_query, $this->factory->bulky($this->glyph, "label", $with_multi_query_uri)->getAction());
96 $this->assertEquals($with_fragment_uri, $this->factory->bulky($this->glyph, "label", $with_fragment_uri)->getAction());
97 $this->assertEquals($with_multi_query_and_fragment_uri, $this->factory->bulky($this->glyph, "label", $with_multi_query_and_fragment_uri)->getAction());
98 }
99
100 public function testRenderingGlyph()
101 {
102 $r = $this->getDefaultRenderer();
103 $b = $this->factory->bulky($this->glyph, "label", $this->target);
104
105 $expected = ''
106 . '<a class="il-link link-bulky" href="http://www.ilias.de">'
107 . ' <span class="glyph" aria-label="briefcase" role="img">'
108 . ' <span class="glyphicon glyphicon-briefcase" aria-hidden="true"></span>'
109 . ' </span>'
110 . ' <span class="bulky-label">label</span>'
111 . '</a>';
112
113 $this->assertHTMLEquals(
114 $expected,
115 $r->render($b)
116 );
117 }
118
119 public function testRenderingIcon()
120 {
121 $r = $this->getDefaultRenderer();
122 $b = $this->factory->bulky($this->icon, "label", $this->target);
123
124 $expected = ''
125 . '<a class="il-link link-bulky" href="http://www.ilias.de">'
126 . ' <img class="icon someExample small" src="./templates/default/images/icon_default.svg" alt="Example"/>'
127 . ' <span class="bulky-label">label</span>'
128 . '</a>';
129
130 $this->assertHTMLEquals(
131 $expected,
132 $r->render($b)
133 );
134 }
135 public function testRenderingWithId()
136 {
137 $r = $this->getDefaultRenderer();
138 $b = $this->factory->bulky($this->icon, "label", $this->target)
139 ->withAdditionalOnloadCode(function ($id) {
140 return '';
141 });
142
143 $expected = ''
144 . '<a class="il-link link-bulky" href="http://www.ilias.de" id="id_1">'
145 . '<img class="icon someExample small" src="./templates/default/images/icon_default.svg" alt="Example"/>'
146 . ' <span class="bulky-label">label</span>'
147 . '</a>';
148
149 $this->assertHTMLEquals(
150 $expected,
151 $r->render($b)
152 );
153 }
154
156 {
157 $r = $this->getDefaultRenderer();
158 $b = $this->factory->bulky($this->icon, "label", $this->target)
159 ->withAriaRole(I\Button\Bulky::MENUITEM);
160
161 $expected = ''
162 . '<a class="il-link link-bulky" href="http://www.ilias.de" role="menuitem">'
163 . '<img class="icon someExample small" src="./templates/default/images/icon_default.svg" alt="Example"/>'
164 . ' <span class="bulky-label">label</span>'
165 . '</a>';
166
167 $this->assertHTMLEquals(
168 $expected,
169 $r->render($b)
170 );
171 }
172}
Testing behavior of the Bulky Link.
testRenderWithAriaRoleMenuitem()
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:263
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311