StandardTest   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 206
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 26
eloc 53
c 1
b 0
f 0
dl 0
loc 206
rs 10

26 Methods

Rating   Name   Duplication   Size   Complexity  
A testTransformJsBacktick() 0 5 1
A testTransformAttrTrusted() 0 6 1
A testTransformUrlSpecial() 0 5 1
A tearDown() 0 3 1
A testTransformAttrArray() 0 5 1
A testTransformXmlValid() 0 5 1
A testTransformHtmlInvalid() 0 5 1
A testTransformXmlObject() 0 5 1
A testTransformAttrInvalid() 0 5 1
A testTransformJsApostroph() 0 5 1
A testTransformXmlInvalid() 0 5 1
A testTransformJsNewline() 0 5 1
A testTransformAttrValid() 0 5 1
A testTransformXmlTrusted() 0 5 1
A testTransformAttrNewline() 0 5 1
A testTransformUrlHtml() 0 5 1
A setUp() 0 4 1
A testTransformUrl() 0 5 1
A testTransformHtmlArray() 0 5 1
A testTransformAttrObject() 0 5 1
A testTransformHtmlObject() 0 5 1
A testTransformJsQuote() 0 5 1
A testTransform() 0 3 1
A testTransformHtmlTrusted() 0 5 1
A testTransformXmlArray() 0 5 1
A testTransformHtmlValid() 0 5 1
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>&quot;attri&#96;bute&apos;</a>', $enc->attr( '<a>"attri`bute\'</a>' ) );
58
	}
59
60
61
	public function testTransformAttrArray()
62
	{
63
		$enc = $this->object->transform();
64
65
		$this->assertEquals( '[&quot;\\u0026quot;&quot;]', $enc->attr( ['&quot;'] ) );
66
	}
67
68
69
	public function testTransformAttrObject()
70
	{
71
		$enc = $this->object->transform();
72
73
		$this->assertEquals( '{&quot;key&quot;:&quot;\\u0026quot;&quot;}', $enc->attr( (object) ['key' => '&quot;'] ) );
74
	}
75
76
77
	public function testTransformAttrNewline()
78
	{
79
		$enc = $this->object->transform();
80
81
		$this->assertEquals( '{&quot;key&quot;:&quot;\\\\n&quot;}', $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( '[&quot;\u0026quot;&quot;]', $enc->html( ['&quot;'] ) );
114
	}
115
116
117
	public function testTransformHtmlObject()
118
	{
119
		$enc = $this->object->transform();
120
121
		$this->assertEquals( '&quot;key&quot;:&quot;\u0026quot;&quot;', $enc->html( (object) ['key' => '&quot;'] ) );
122
	}
123
124
125
	public function testTransformJsApostroph()
126
	{
127
		$enc = $this->object->transform();
128
129
		$this->assertEquals( '&apos;', $enc->js( '\'' ) );
130
	}
131
132
133
	public function testTransformJsBacktick()
134
	{
135
		$enc = $this->object->transform();
136
137
		$this->assertEquals( '\&#96;', $enc->js( '`' ) );
138
	}
139
140
141
	public function testTransformJsQuote()
142
	{
143
		$enc = $this->object->transform();
144
145
		$this->assertEquals( '&quot;', $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 ]]&gt;&lt;b&gt;text&lt;/b&gt;', $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( ['&quot;'] ) );
186
	}
187
188
189
	public function testTransformXmlObject()
190
	{
191
		$enc = $this->object->transform();
192
193
		$this->assertEquals( '{"key":"\u0026quot;"}', $enc->xml( (object) ['key' => '&quot;'] ) );
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