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