1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MW\View\Helper\Encoder; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$view = new \Aimeos\MW\View\Standard(); |
21
|
|
|
$this->object = new \Aimeos\MW\View\Helper\Encoder\Standard( $view ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
protected function tearDown() |
26
|
|
|
{ |
27
|
|
|
$this->object = null; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
public function testTransform() |
32
|
|
|
{ |
33
|
|
|
$this->assertInstanceOf( \Aimeos\MW\View\Helper\Iface::class, $this->object->transform() ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testTransformAttrTrusted() |
38
|
|
|
{ |
39
|
|
|
$enc = $this->object->transform(); |
40
|
|
|
|
41
|
|
|
$this->assertEquals( '<a href=" ">', $enc->attr( '<a href=" |
42
|
|
|
">', $enc::TRUST, ' ' ) ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testTransformAttrValid() |
47
|
|
|
{ |
48
|
|
|
$enc = $this->object->transform(); |
49
|
|
|
|
50
|
|
|
$this->assertEquals( 'an attribute', $enc->attr( 'an attribute' ) ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testTransformAttrInvalid() |
55
|
|
|
{ |
56
|
|
|
$enc = $this->object->transform(); |
57
|
|
|
|
58
|
|
|
$this->assertEquals( '<a>"attribute\'</a>', $enc->attr( '<a>"attribute\'</a>' ) ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testTransformAttrArray() |
63
|
|
|
{ |
64
|
|
|
$enc = $this->object->transform(); |
65
|
|
|
|
66
|
|
|
$this->assertEquals( '["\u0026quot;"]', $enc->attr( ['"'] ) ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testTransformAttrObject() |
71
|
|
|
{ |
72
|
|
|
$enc = $this->object->transform(); |
73
|
|
|
|
74
|
|
|
$this->assertEquals( '{"key":"\u0026quot;"}', $enc->attr( (object) ['key' => '"'] ) ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testTransformHtmlTrusted() |
79
|
|
|
{ |
80
|
|
|
$enc = $this->object->transform(); |
81
|
|
|
|
82
|
|
|
$this->assertEquals( '<a>link</a>', $enc->html( '<a>link</a>', $enc::TRUST ) ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function testTransformHtmlValid() |
87
|
|
|
{ |
88
|
|
|
$enc = $this->object->transform(); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( 'a text', $enc->html( 'a text' ) ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
public function testTransformHtmlInvalid() |
95
|
|
|
{ |
96
|
|
|
$enc = $this->object->transform(); |
97
|
|
|
|
98
|
|
|
$this->assertEquals( '<a>text</a>', $enc->html( '<a>text</a>' ) ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
public function testTransformHtmlArray() |
103
|
|
|
{ |
104
|
|
|
$enc = $this->object->transform(); |
105
|
|
|
|
106
|
|
|
$this->assertEquals( '["\u0026quot;"]', $enc->html( ['"'] ) ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
public function testTransformHtmlObject() |
111
|
|
|
{ |
112
|
|
|
$enc = $this->object->transform(); |
113
|
|
|
|
114
|
|
|
$this->assertEquals( '{"key":"\u0026quot;"}', $enc->html( (object) ['key' => '"'] ) ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testTransformXmlTrusted() |
119
|
|
|
{ |
120
|
|
|
$enc = $this->object->transform(); |
121
|
|
|
|
122
|
|
|
$this->assertEquals( '<a>link</a>', $enc->xml( '<a>link</a>', $enc::TRUST ) ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
public function testTransformXmlValid() |
127
|
|
|
{ |
128
|
|
|
$enc = $this->object->transform(); |
129
|
|
|
|
130
|
|
|
$this->assertEquals( 'a "text"', $enc->xml( 'a "text"' ) ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testTransformXmlInvalid() |
135
|
|
|
{ |
136
|
|
|
$enc = $this->object->transform(); |
137
|
|
|
|
138
|
|
|
$this->assertEquals( 'a ]]><b>text</b>', $enc->xml( 'a ]]><b>text</b>' ) ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
public function testTransformXmlArray() |
143
|
|
|
{ |
144
|
|
|
$enc = $this->object->transform(); |
145
|
|
|
|
146
|
|
|
$this->assertEquals( '["\u0026quot;"]', $enc->html( ['"'] ) ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
public function testTransformXmlObject() |
151
|
|
|
{ |
152
|
|
|
$enc = $this->object->transform(); |
153
|
|
|
|
154
|
|
|
$this->assertEquals( '{"key":"\u0026quot;"}', $enc->html( (object) ['key' => '"'] ) ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testTransformUrl() |
159
|
|
|
{ |
160
|
|
|
$enc = $this->object->transform(); |
161
|
|
|
|
162
|
|
|
$this->assertEquals( '__-', $enc->url( ' _-' ) ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
public function testTransformUrlSpecial() |
167
|
|
|
{ |
168
|
|
|
$enc = $this->object->transform(); |
169
|
|
|
|
170
|
|
|
$this->assertEquals( '%5C%27%22%3B%23%2B%7E%2A%24%25%2F%28%29%3D%3F%26', $enc->url( '\\\'";#+~*$%/()=?&' ) ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
public function testTransformUrlHtml() |
175
|
|
|
{ |
176
|
|
|
$enc = $this->object->transform(); |
177
|
|
|
|
178
|
|
|
$this->assertEquals( 'test', $enc->url( '<p>test</p>' ) ); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|