ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ImageTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
27
32{
36 public function getImageFactory(): Factory
37 {
38 return new Factory();
39 }
40
41
42 public function testImplementsFactoryInterface(): void
43 {
44 $f = $this->getImageFactory();
45
46 $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Factory", $f);
47 $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Image", $f->standard("source", "alt"));
48 $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Image", $f->responsive("source", "alt"));
49 }
50
51 public function testGetType(): void
52 {
53 $f = $this->getImageFactory();
54 $i = $f->standard("source", "alt");
55
56 $this->assertEquals($i::STANDARD, $i->getType());
57 }
58
59 public function testGetSource(): void
60 {
61 $f = $this->getImageFactory();
62 $i = $f->standard("source", "alt");
63
64 $this->assertEquals("source", $i->getSource());
65 }
66
67 public function testGetAlt(): void
68 {
69 $f = $this->getImageFactory();
70 $i = $f->standard("source", "alt");
71
72 $this->assertEquals("alt", $i->getAlt());
73 }
74
75 public function testSetSource(): void
76 {
77 $f = $this->getImageFactory();
78 $i = $f->standard("source", "alt");
79 $i = $i->withSource("newSource");
80 $this->assertEquals("newSource", $i->getSource());
81 }
82
83 public function testSetAlt(): void
84 {
85 $f = $this->getImageFactory();
86 $i = $f->standard("source", "alt");
87 $i = $i->withAlt("newAlt");
88 $this->assertEquals("newAlt", $i->getAlt());
89 }
90
91 public function testSetStringAction(): void
92 {
93 $f = $this->getImageFactory();
94 $i = $f->standard("source", "alt");
95 $i = $i->withAction("newAction");
96 $this->assertEquals("newAction", $i->getAction());
97 }
98
99 public function testSetSignalAction(): void
100 {
101 $f = $this->getImageFactory();
102 $signal = $this->createMock(C\Signal::class);
103 $i = $f->standard("source", "alt");
104 $i = $i->withAction($signal);
105 $this->assertEquals([$signal], $i->getAction());
106 }
107
108 public function testSetAdditionalHighResSources(): void
109 {
110 $additional_sources = [
111 600 => 'image1',
112 300 => 'image2'
113 ];
114 $f = $this->getImageFactory();
115 $i = $f->standard("source", "alt");
116 foreach($additional_sources as $min_width_in_pixels => $source) {
117 $i = $i->withAdditionalHighResSource($source, $min_width_in_pixels);
118 }
119 $this->assertEquals($additional_sources, $i->getAdditionalHighResSources());
120 }
121
122 public function testInvalidSource(): void
123 {
124 $this->expectException(TypeError::class);
125 $f = $this->getImageFactory();
126 $f->standard(1, "alt");
127 }
128
129 public function testInvalidAlt(): void
130 {
131 $this->expectException(TypeError::class);
132 $f = $this->getImageFactory();
133 $f->standard("source", 1);
134 }
135
137 {
138 $this->expectException(TypeError::class);
139 $f = $this->getImageFactory();
140 $f->standard("source", 1)->withAdditionalHighResSource(
141 1,
142 1
143 );
144 }
145
147 {
148 $this->expectException(TypeError::class);
149 $f = $this->getImageFactory();
150 $f->standard("source", 1)->withAdditionalHighResSource(
151 '#',
152 '#'
153 );
154 }
155
156 public function testRenderStandard(): void
157 {
158 $f = $this->getImageFactory();
159 $r = $this->getDefaultRenderer();
160 $i = $f->standard("source", "alt");
161
162 $html = $this->normalizeHTML($r->render($i));
163
164 $expected = "<img src=\"source\" class=\"img-standard\" alt=\"alt\" />";
165
166 $this->assertEquals($expected, $html);
167 }
168
169 public function testRenderResponsive(): void
170 {
171 $f = $this->getImageFactory();
172 $r = $this->getDefaultRenderer();
173 $i = $f->responsive("source", "alt");
174
175 $html = $this->normalizeHTML($r->render($i));
176
177 $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"alt\" />";
178
179 $this->assertEquals($expected, $html);
180 }
181
182 public function testRenderAltEscaping(): void
183 {
184 $f = $this->getImageFactory();
185 $r = $this->getDefaultRenderer();
186 $i = $f->responsive("source", "\"=test;\")(blah\"");
187
188 $html = $this->normalizeHTML($r->render($i));
189
190 $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"&quot;=test;&quot;)(blah&quot;\" />";
191
192 $this->assertEquals($expected, $html);
193 }
194
195 public function testRenderWithStringAction(): void
196 {
197 $f = $this->getImageFactory();
198 $r = $this->getDefaultRenderer();
199 $i = $f->standard("source", "alt")->withAction("action");
200
201 $html = $this->normalizeHTML($r->render($i));
202
203 $expected = "<a href=\"action\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
204
205 $this->assertEquals($expected, $html);
206 }
207
208 public function testRenderWithSignalAction(): void
209 {
210 $f = $this->getImageFactory();
211 $r = $this->getDefaultRenderer();
212 $signal = $this->createMock(Signal::class);
213
214 $i = $f->standard("source", "alt")->withAction($signal);
215
216 $html = $this->normalizeHTML($r->render($i));
217
218 $expected = "<a href=\"#\" id=\"id_1\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
219
220 $this->assertEquals($expected, $html);
221 }
222
224 {
225 $f = $this->getImageFactory();
226 $r = $this->getDefaultRenderer();
227
228 $i = $f->standard("source", "alt")->withAction("#");
229
230 $html = $this->normalizeHTML($r->render($i));
231
232 $expected = "<a href=\"#\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
233
234 $this->assertEquals($expected, $html);
235 }
236
237 public function testWithAdditionalOnLoadCode(): void
238 {
239 $f = $this->getImageFactory();
240 $r = $this->getDefaultRenderer();
241
242 $i = $f->standard("source", "alt")->withAction("#")->withOnLoadCode(function ($id) {
243 return "Something";
244 });
245
246 $html = $this->normalizeHTML($r->render($i));
247
248 $expected = "<a href=\"#\"><img src=\"source\" class=\"img-standard\" id='id_1' alt=\"alt\" /></a>";
249
250 $this->assertEquals($expected, $html);
251 }
252}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Provides common functionality for UI tests.
Definition: Base.php:337
Test on button implementation.
Definition: ImageTest.php:32
testImplementsFactoryInterface()
Definition: ImageTest.php:42
testSetSignalAction()
Definition: ImageTest.php:99
testSetSource()
Definition: ImageTest.php:75
testSetAdditionalHighResSources()
Definition: ImageTest.php:108
testSetStringAction()
Definition: ImageTest.php:91
testGetType()
Definition: ImageTest.php:51
testGetSource()
Definition: ImageTest.php:59
testRenderAltEscaping()
Definition: ImageTest.php:182
testRenderWithStringAction()
Definition: ImageTest.php:195
testRenderStandard()
Definition: ImageTest.php:156
testInvalidSource()
Definition: ImageTest.php:122
getImageFactory()
Definition: ImageTest.php:36
testWithEmptyActionAndNoAdditionalOnLoadCode()
Definition: ImageTest.php:223
testSetAlt()
Definition: ImageTest.php:83
testRenderWithSignalAction()
Definition: ImageTest.php:208
testGetAlt()
Definition: ImageTest.php:67
testInvalidAdditionalHighResSourceSize()
Definition: ImageTest.php:146
testInvalidAdditionalHighResSource()
Definition: ImageTest.php:136
testWithAdditionalOnLoadCode()
Definition: ImageTest.php:237
testInvalidAlt()
Definition: ImageTest.php:129
testRenderResponsive()
Definition: ImageTest.php:169