ILIAS  release_8 Revision v8.24
ImageTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . "/../../../../libs/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 test_implements_factory_interface(): 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 test_get_type(): 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 test_get_source(): void
60 {
61 $f = $this->getImageFactory();
62 $i = $f->standard("source", "alt");
63
64 $this->assertEquals("source", $i->getSource());
65 }
66
67 public function test_get_alt(): void
68 {
69 $f = $this->getImageFactory();
70 $i = $f->standard("source", "alt");
71
72 $this->assertEquals("alt", $i->getAlt());
73 }
74
75 public function test_set_source(): 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 test_set_alt(): 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 test_set_string_action(): 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 test_set_signal_action(): 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 test_invalid_source(): void
109 {
110 $this->expectException(TypeError::class);
111 $f = $this->getImageFactory();
112 $f->standard(1, "alt");
113 }
114
115 public function test_invalid_alt(): void
116 {
117 $this->expectException(TypeError::class);
118 $f = $this->getImageFactory();
119 $f->standard("source", 1);
120 }
121
122 public function test_render_standard(): void
123 {
124 $f = $this->getImageFactory();
125 $r = $this->getDefaultRenderer();
126 $i = $f->standard("source", "alt");
127
128 $html = $this->normalizeHTML($r->render($i));
129
130 $expected = "<img src=\"source\" class=\"img-standard\" alt=\"alt\" />";
131
132 $this->assertEquals($expected, $html);
133 }
134
135 public function test_render_responsive(): void
136 {
137 $f = $this->getImageFactory();
138 $r = $this->getDefaultRenderer();
139 $i = $f->responsive("source", "alt");
140
141 $html = $this->normalizeHTML($r->render($i));
142
143 $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"alt\" />";
144
145 $this->assertEquals($expected, $html);
146 }
147
148 public function test_render_alt_escaping(): void
149 {
150 $f = $this->getImageFactory();
151 $r = $this->getDefaultRenderer();
152 $i = $f->responsive("source", "\"=test;\")(blah\"");
153
154 $html = $this->normalizeHTML($r->render($i));
155
156 $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"&quot;=test;&quot;)(blah&quot;\" />";
157
158 $this->assertEquals($expected, $html);
159 }
160
161 public function test_render_with_string_action(): void
162 {
163 $f = $this->getImageFactory();
164 $r = $this->getDefaultRenderer();
165 $i = $f->standard("source", "alt")->withAction("action");
166
167 $html = $this->normalizeHTML($r->render($i));
168
169 $expected = "<a href=\"action\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
170
171 $this->assertEquals($expected, $html);
172 }
173
174 public function test_render_with_signal_action(): void
175 {
176 $f = $this->getImageFactory();
177 $r = $this->getDefaultRenderer();
178 $signal = $this->createMock(Signal::class);
179
180 $i = $f->standard("source", "alt")->withAction($signal);
181
182 $html = $this->normalizeHTML($r->render($i));
183
184 $expected = "<a href=\"#\" id=\"id_1\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
185
186 $this->assertEquals($expected, $html);
187 }
188
190 {
191 $f = $this->getImageFactory();
192 $r = $this->getDefaultRenderer();
193
194 $i = $f->standard("source", "alt")->withAction("#");
195
196 $html = $this->normalizeHTML($r->render($i));
197
198 $expected = "<a href=\"#\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
199
200 $this->assertEquals($expected, $html);
201 }
202
203 public function test_with_additional_on_load_code(): void
204 {
205 $f = $this->getImageFactory();
206 $r = $this->getDefaultRenderer();
207
208 $i = $f->standard("source", "alt")->withAction("#")->withOnLoadCode(function ($id) {
209 return "Something";
210 });
211
212 $html = $this->normalizeHTML($r->render($i));
213
214 $expected = "<a href=\"#\"><img src=\"source\" class=\"img-standard\" id='id_1' alt=\"alt\" /></a>";
215
216 $this->assertEquals($expected, $html);
217 }
218}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Provides common functionality for UI tests.
Definition: Base.php:299
normalizeHTML(string $html)
Definition: Base.php:422
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Test on button implementation.
Definition: ImageTest.php:32
test_invalid_source()
Definition: ImageTest.php:108
test_get_alt()
Definition: ImageTest.php:67
test_get_source()
Definition: ImageTest.php:59
test_get_type()
Definition: ImageTest.php:51
test_render_standard()
Definition: ImageTest.php:122
test_invalid_alt()
Definition: ImageTest.php:115
test_render_responsive()
Definition: ImageTest.php:135
test_render_with_signal_action()
Definition: ImageTest.php:174
getImageFactory()
Definition: ImageTest.php:36
test_with_additional_on_load_code()
Definition: ImageTest.php:203
test_set_alt()
Definition: ImageTest.php:83
test_implements_factory_interface()
Definition: ImageTest.php:42
test_render_with_string_action()
Definition: ImageTest.php:161
test_render_alt_escaping()
Definition: ImageTest.php:148
test_with_empty_action_and_no_additional_on_load_code()
Definition: ImageTest.php:189
test_set_source()
Definition: ImageTest.php:75
test_set_string_action()
Definition: ImageTest.php:91
test_set_signal_action()
Definition: ImageTest.php:99
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...