ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ImageTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \ILIAS\UI\Component as C;
9use \ILIAS\UI\Implementation\Component\Signal;
10
15{
16
20 public function getImageFactory()
21 {
22 return new \ILIAS\UI\Implementation\Component\Image\Factory();
23 }
24
25
27 {
28 $f = $this->getImageFactory();
29
30 $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Factory", $f);
31 $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Image", $f->standard("source", "alt"));
32 $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Image", $f->responsive("source", "alt"));
33 }
34
35 public function test_get_type()
36 {
37 $f = $this->getImageFactory();
38 $i = $f->standard("source", "alt");
39
40 $this->assertEquals($i::STANDARD, $i->getType());
41 }
42
43 public function test_get_source()
44 {
45 $f = $this->getImageFactory();
46 $i = $f->standard("source", "alt");
47
48 $this->assertEquals("source", $i->getSource());
49 }
50
51 public function test_get_alt()
52 {
53 $f = $this->getImageFactory();
54 $i = $f->standard("source", "alt");
55
56 $this->assertEquals("alt", $i->getAlt());
57 }
58
59
60 public function test_set_source()
61 {
62 $f = $this->getImageFactory();
63 $i = $f->standard("source", "alt");
64 $i = $i->withSource("newSource");
65 $this->assertEquals("newSource", $i->getSource());
66 }
67
68 public function test_set_alt()
69 {
70 $f = $this->getImageFactory();
71 $i = $f->standard("source", "alt");
72 $i = $i->withAlt("newAlt");
73 $this->assertEquals("newAlt", $i->getAlt());
74 }
75
76 public function test_set_string_action()
77 {
78 $f = $this->getImageFactory();
79 $i = $f->standard("source", "alt");
80 $i = $i->withAction("newAction");
81 $this->assertEquals("newAction", $i->getAction());
82 }
83
84 public function test_set_signal_action()
85 {
86 $f = $this->getImageFactory();
87 $signal = $this->createMock(C\Signal::class);
88 $i = $f->standard("source", "alt");
89 $i = $i->withAction($signal);
90 $this->assertEquals([$signal], $i->getAction());
91 }
92
93 public function test_invalid_source()
94 {
95 $this->expectException(\InvalidArgumentException::class);
96 $f = $this->getImageFactory();
97 $f->standard(1, "alt");
98 }
99
100 public function test_invalid_alt()
101 {
102 $this->expectException(\InvalidArgumentException::class);
103 $f = $this->getImageFactory();
104 $f->standard("source", 1);
105 }
106
107 public function test_render_standard()
108 {
109 $f = $this->getImageFactory();
110 $r = $this->getDefaultRenderer();
111 $i = $f->standard("source", "alt");
112
113 $html = $this->normalizeHTML($r->render($i));
114
115 $expected = "<img src=\"source\" class=\"img-standard\" alt=\"alt\" />";
116
117 $this->assertEquals($expected, $html);
118 }
119
120 public function test_render_responsive()
121 {
122 $f = $this->getImageFactory();
123 $r = $this->getDefaultRenderer();
124 $i = $f->responsive("source", "alt");
125
126 $html = $this->normalizeHTML($r->render($i));
127
128 $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"alt\" />";
129
130 $this->assertEquals($expected, $html);
131 }
132
133 public function test_render_alt_escaping()
134 {
135 $f = $this->getImageFactory();
136 $r = $this->getDefaultRenderer();
137 $i = $f->responsive("source", "\"=test;\")(blah\"");
138
139 $html = $this->normalizeHTML($r->render($i));
140
141 $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"&quot;=test;&quot;)(blah&quot;\" />";
142
143 $this->assertEquals($expected, $html);
144 }
145
147 {
148 $f = $this->getImageFactory();
149 $r = $this->getDefaultRenderer();
150 $i = $f->standard("source", "alt")->withAction("action");
151
152 $html = $this->normalizeHTML($r->render($i));
153
154 $expected = "<a href=\"action\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
155
156 $this->assertEquals($expected, $html);
157 }
158
160 {
161 $f = $this->getImageFactory();
162 $r = $this->getDefaultRenderer();
163 $signal = $this->createMock(Signal::class);
164
165 $i = $f->standard("source", "alt")->withAction($signal);
166
167 $html = $this->normalizeHTML($r->render($i));
168
169 $expected = "<a href=\"#\" id=\"id_1\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
170
171 $this->assertEquals($expected, $html);
172 }
173
175 {
176 $f = $this->getImageFactory();
177 $r = $this->getDefaultRenderer();
178
179 $i = $f->standard("source", "alt")->withAction("#");
180
181 $html = $this->normalizeHTML($r->render($i));
182
183 $expected = "<a href=\"#\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
184
185 $this->assertEquals($expected, $html);
186 }
187
189 {
190 $f = $this->getImageFactory();
191 $r = $this->getDefaultRenderer();
192
193 $i = $f->standard("source", "alt")->withAction("#")->withOnLoadCode(function ($id) {
194 return "Something";
195 });
196
197 $html = $this->normalizeHTML($r->render($i));
198
199 $expected = "<a href=\"#\"><img src=\"source\" class=\"img-standard\" id='id_1' alt=\"alt\" /></a>";
200
201 $this->assertEquals($expected, $html);
202 }
203}
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:225
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
normalizeHTML($html)
Definition: Base.php:317
Test on button implementation.
Definition: ImageTest.php:15
test_invalid_source()
Definition: ImageTest.php:93
test_get_alt()
Definition: ImageTest.php:51
test_get_source()
Definition: ImageTest.php:43
test_get_type()
Definition: ImageTest.php:35
test_render_standard()
Definition: ImageTest.php:107
test_invalid_alt()
Definition: ImageTest.php:100
test_render_responsive()
Definition: ImageTest.php:120
test_render_with_signal_action()
Definition: ImageTest.php:159
getImageFactory()
Definition: ImageTest.php:20
test_with_additional_on_load_code()
Definition: ImageTest.php:188
test_set_alt()
Definition: ImageTest.php:68
test_implements_factory_interface()
Definition: ImageTest.php:26
test_render_with_string_action()
Definition: ImageTest.php:146
test_render_alt_escaping()
Definition: ImageTest.php:133
test_with_empty_action_and_no_additional_on_load_code()
Definition: ImageTest.php:174
test_set_source()
Definition: ImageTest.php:60
test_set_string_action()
Definition: ImageTest.php:76
test_set_signal_action()
Definition: ImageTest.php:84
$i
Definition: metadata.php:24