ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
14 {
15 
19  public function getImageFactory()
20  {
21  return new \ILIAS\UI\Implementation\Component\Image\Factory();
22  }
23 
24 
26  {
27  $f = $this->getImageFactory();
28 
29  $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Factory", $f);
30  $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Image", $f->standard("source", "alt"));
31  $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Image", $f->responsive("source", "alt"));
32  }
33 
34  public function test_get_type()
35  {
36  $f = $this->getImageFactory();
37  $i = $f->standard("source", "alt");
38 
39  $this->assertEquals($i::STANDARD, $i->getType());
40  }
41 
42  public function test_get_source()
43  {
44  $f = $this->getImageFactory();
45  $i = $f->standard("source", "alt");
46 
47  $this->assertEquals("source", $i->getSource());
48  }
49 
50  public function test_get_alt()
51  {
52  $f = $this->getImageFactory();
53  $i = $f->standard("source", "alt");
54 
55  $this->assertEquals("alt", $i->getAlt());
56  }
57 
58 
59  public function test_set_source()
60  {
61  $f = $this->getImageFactory();
62  $i = $f->standard("source", "alt");
63  $i = $i->withSource("newSource");
64  $this->assertEquals("newSource", $i->getSource());
65  }
66 
67  public function test_set_alt()
68  {
69  $f = $this->getImageFactory();
70  $i = $f->standard("source", "alt");
71  $i = $i->withAlt("newAlt");
72  $this->assertEquals("newAlt", $i->getAlt());
73  }
74 
75  public function test_set_action()
76  {
77  $f = $this->getImageFactory();
78  $i = $f->standard("source", "alt");
79  $i = $i->withAction("newAction");
80  $this->assertEquals("newAction", $i->getAction());
81  }
82 
83  public function test_invalid_source()
84  {
85  $f = $this->getImageFactory();
86 
87  try {
88  $f->standard(1, "alt");
89  $this->assertFalse("This should not happen");
90  } catch (InvalidArgumentException $e) {
91  }
92  }
93 
94  public function test_invalid_alt()
95  {
96  $f = $this->getImageFactory();
97 
98  try {
99  $f->standard("source", 1);
100  $this->assertFalse("This should not happen");
101  } catch (InvalidArgumentException $e) {
102  }
103  }
104 
105  public function test_render_standard()
106  {
107  $f = $this->getImageFactory();
108  $r = $this->getDefaultRenderer();
109  $i = $f->standard("source", "alt");
110 
111  $html = $this->normalizeHTML($r->render($i));
112 
113  $expected = "<img src=\"source\" class=\"img-standard\" alt=\"alt\" />";
114 
115  $this->assertEquals($expected, $html);
116  }
117 
118  public function test_render_responsive()
119  {
120  $f = $this->getImageFactory();
121  $r = $this->getDefaultRenderer();
122  $i = $f->responsive("source", "alt");
123 
124  $html = $this->normalizeHTML($r->render($i));
125 
126  $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"alt\" />";
127 
128  $this->assertEquals($expected, $html);
129  }
130 
131  public function test_render_alt_escaping()
132  {
133  $f = $this->getImageFactory();
134  $r = $this->getDefaultRenderer();
135  $i = $f->responsive("source", "\"=test;\")(blah\"");
136 
137  $html = $this->normalizeHTML($r->render($i));
138 
139  $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"&quot;=test;&quot;)(blah&quot;\" />";
140 
141  $this->assertEquals($expected, $html);
142  }
143 
144  public function test_render_with_action()
145  {
146  $f = $this->getImageFactory();
147  $r = $this->getDefaultRenderer();
148  $i = $f->standard("source", "alt")->withAction("action");
149 
150  $html = $this->normalizeHTML($r->render($i));
151 
152  $expected = "<a href=\"action\"><img src=\"source\" class=\"img-standard\" alt=\"alt\" /></a>";
153 
154  $this->assertEquals($expected, $html);
155  }
156 }
test_render_with_action()
Definition: ImageTest.php:144
test_invalid_alt()
Definition: ImageTest.php:94
Test on button implementation.
Definition: ImageTest.php:13
test_render_responsive()
Definition: ImageTest.php:118
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
test_get_alt()
Definition: ImageTest.php:50
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:177
test_set_source()
Definition: ImageTest.php:59
test_get_type()
Definition: ImageTest.php:34
test_set_action()
Definition: ImageTest.php:75
getImageFactory()
Definition: ImageTest.php:19
test_implements_factory_interface()
Definition: ImageTest.php:25
test_get_source()
Definition: ImageTest.php:42
test_render_standard()
Definition: ImageTest.php:105
test_invalid_source()
Definition: ImageTest.php:83
$i
Definition: disco.tpl.php:19
test_render_alt_escaping()
Definition: ImageTest.php:131
test_set_alt()
Definition: ImageTest.php:67
$html
Definition: example_001.php:87