ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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;
9
14
18 public function getImageFactory() {
19 return new \ILIAS\UI\Implementation\Component\Image\Factory();
20 }
21
22
24 $f = $this->getImageFactory();
25
26 $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Factory", $f);
27 $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Image", $f->standard("source","alt"));
28 $this->assertInstanceOf("ILIAS\\UI\\Component\\Image\\Image", $f->responsive("source","alt"));
29 }
30
31 public function test_get_type() {
32 $f = $this->getImageFactory();
33 $i = $f->standard("source","alt");
34
35 $this->assertEquals($i::STANDARD, $i->getType());
36 }
37
38 public function test_get_source() {
39 $f = $this->getImageFactory();
40 $i = $f->standard("source","alt");
41
42 $this->assertEquals("source", $i->getSource());
43 }
44
45 public function test_get_alt() {
46 $f = $this->getImageFactory();
47 $i = $f->standard("source","alt");
48
49 $this->assertEquals("alt", $i->getAlt());
50 }
51
52
53 public function test_set_source() {
54 $f = $this->getImageFactory();
55 $i = $f->standard("source","alt");
56 $i = $i->withSource("newSource");
57 $this->assertEquals("newSource", $i->getSource());
58 }
59
60 public function test_set_alt() {
61 $f = $this->getImageFactory();
62 $i = $f->standard("source","alt");
63 $i = $i->withAlt("newAlt");
64 $this->assertEquals("newAlt", $i->getAlt());
65 }
66
67 public function test_invalid_source(){
68 $f = $this->getImageFactory();
69
70 try{
71 $f->standard(1,"alt");
72 $this->assertFalse("This should not happen");
73 }catch(InvalidArgumentException $e){}
74 }
75
76 public function test_invalid_alt(){
77 $f = $this->getImageFactory();
78
79 try{
80 $f->standard("source",1);
81 $this->assertFalse("This should not happen");
82 }catch(InvalidArgumentException $e){}
83 }
84
85 public function test_render_standard() {
86 $f = $this->getImageFactory();
87 $r = $this->getDefaultRenderer();
88 $i = $f->standard("source","alt");
89
90 $html = $this->normalizeHTML($r->render($i));
91
92 $expected = "<img src=\"source\" class=\"img-standard\" alt=\"alt\" />";
93
94 $this->assertEquals($expected, $html);
95 }
96
97 public function test_render_responsive() {
98 $f = $this->getImageFactory();
99 $r = $this->getDefaultRenderer();
100 $i = $f->responsive("source","alt");
101
102 $html = $this->normalizeHTML($r->render($i));
103
104 $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"alt\" />";
105
106 $this->assertEquals($expected, $html);
107 }
108
109 public function test_render_alt_escaping() {
110 $f = $this->getImageFactory();
111 $r = $this->getDefaultRenderer();
112 $i = $f->responsive("source","\"=test;\")(blah\"");
113
114 $html = $this->normalizeHTML($r->render($i));
115
116 $expected = "<img src=\"source\" class=\"img-responsive\" alt=\"&quot;=test;&quot;)(blah&quot;\" />";
117
118 $this->assertEquals($expected, $html);
119 }
120}
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:69
normalizeHTML($html)
Definition: Base.php:110
getDefaultRenderer()
Definition: Base.php:100
Test on button implementation.
Definition: ImageTest.php:13
test_invalid_source()
Definition: ImageTest.php:67
test_get_alt()
Definition: ImageTest.php:45
test_get_source()
Definition: ImageTest.php:38
test_get_type()
Definition: ImageTest.php:31
test_render_standard()
Definition: ImageTest.php:85
test_invalid_alt()
Definition: ImageTest.php:76
test_render_responsive()
Definition: ImageTest.php:97
getImageFactory()
Definition: ImageTest.php:18
test_set_alt()
Definition: ImageTest.php:60
test_implements_factory_interface()
Definition: ImageTest.php:23
test_render_alt_escaping()
Definition: ImageTest.php:109
test_set_source()
Definition: ImageTest.php:53
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79