ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 use \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  $f = $this->getImageFactory();
96 
97  try {
98  $f->standard(1, "alt");
99  $this->assertFalse("This should not happen");
100  } catch (InvalidArgumentException $e) {
101  }
102  }
103 
104  public function test_invalid_alt()
105  {
106  $f = $this->getImageFactory();
107 
108  try {
109  $f->standard("source", 1);
110  $this->assertFalse("This should not happen");
111  } catch (InvalidArgumentException $e) {
112  }
113  }
114 
115  public function test_render_standard()
116  {
117  $f = $this->getImageFactory();
118  $r = $this->getDefaultRenderer();
119  $i = $f->standard("source", "alt");
120 
121  $html = $this->normalizeHTML($r->render($i));
122 
123  $expected = "<img src=\"source\" class=\"img-standard\" alt=\"alt\" />";
124 
125  $this->assertEquals($expected, $html);
126  }
127 
128  public function test_render_responsive()
129  {
130  $f = $this->getImageFactory();
131  $r = $this->getDefaultRenderer();
132  $i = $f->responsive("source", "alt");
133 
134  $html = $this->normalizeHTML($r->render($i));
135 
136  $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"alt\" />";
137 
138  $this->assertEquals($expected, $html);
139  }
140 
141  public function test_render_alt_escaping()
142  {
143  $f = $this->getImageFactory();
144  $r = $this->getDefaultRenderer();
145  $i = $f->responsive("source", "\"=test;\")(blah\"");
146 
147  $html = $this->normalizeHTML($r->render($i));
148 
149  $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"&quot;=test;&quot;)(blah&quot;\" />";
150 
151  $this->assertEquals($expected, $html);
152  }
153 
155  {
156  $f = $this->getImageFactory();
157  $r = $this->getDefaultRenderer();
158  $i = $f->standard("source", "alt")->withAction("action");
159 
160  $html = $this->normalizeHTML($r->render($i));
161 
162  $expected = "<a href=\"action\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
163 
164  $this->assertEquals($expected, $html);
165  }
166 
168  {
169  $f = $this->getImageFactory();
170  $r = $this->getDefaultRenderer();
171  $signal = $this->createMock(Signal::class);
172 
173  $i = $f->standard("source", "alt")->withAction($signal);
174 
175  $html = $this->normalizeHTML($r->render($i));
176 
177  $expected = "<a id=\"id_1\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
178 
179  $this->assertEquals($expected, $html);
180  }
181 }
test_render_with_signal_action()
Definition: ImageTest.php:167
test_invalid_alt()
Definition: ImageTest.php:104
test_set_string_action()
Definition: ImageTest.php:76
test_set_signal_action()
Definition: ImageTest.php:84
Test on button implementation.
Definition: ImageTest.php:14
test_render_responsive()
Definition: ImageTest.php:128
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
test_render_with_string_action()
Definition: ImageTest.php:154
normalizeHTML($html)
Definition: Base.php:261
test_get_alt()
Definition: ImageTest.php:51
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:191
test_set_source()
Definition: ImageTest.php:60
test_get_type()
Definition: ImageTest.php:35
getImageFactory()
Definition: ImageTest.php:20
test_implements_factory_interface()
Definition: ImageTest.php:26
test_get_source()
Definition: ImageTest.php:43
test_render_standard()
Definition: ImageTest.php:115
test_invalid_source()
Definition: ImageTest.php:93
$i
Definition: disco.tpl.php:19
test_render_alt_escaping()
Definition: ImageTest.php:141
test_set_alt()
Definition: ImageTest.php:68
$html
Definition: example_001.php:87