Passed
Push — master ( 4a458b...4e4594 )
by Aimeos
05:29
created

StandardTest::testTransformHtmlArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
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>&quot;attribute\'</a>', $enc->attr( '<a>"attribute\'</a>' ) );
59
	}
60
61
62
	public function testTransformAttrArray()
63
	{
64
		$enc = $this->object->transform();
65
66
		$this->assertEquals( '[&quot;\u0026quot;&quot;]', $enc->attr( ['&quot;'] ) );
67
	}
68
69
70
	public function testTransformAttrObject()
71
	{
72
		$enc = $this->object->transform();
73
74
		$this->assertEquals( '{&quot;key&quot;:&quot;\u0026quot;&quot;}', $enc->attr( (object) ['key' => '&quot;'] ) );
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( '&lt;a&gt;text&lt;/a&gt;', $enc->html( '<a>text</a>' ) );
99
	}
100
101
102
	public function testTransformHtmlArray()
103
	{
104
		$enc = $this->object->transform();
105
106
		$this->assertEquals( '[&quot;\u0026quot;&quot;]', $enc->html( ['&quot;'] ) );
107
	}
108
109
110
	public function testTransformHtmlObject()
111
	{
112
		$enc = $this->object->transform();
113
114
		$this->assertEquals( '{&quot;key&quot;:&quot;\u0026quot;&quot;}', $enc->html( (object) ['key' => '&quot;'] ) );
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 ]]&gt;&lt;b&gt;text&lt;/b&gt;', $enc->xml( 'a ]]><b>text</b>' ) );
139
	}
140
141
142
	public function testTransformXmlArray()
143
	{
144
		$enc = $this->object->transform();
145
146
		$this->assertEquals( '[&quot;\u0026quot;&quot;]', $enc->html( ['&quot;'] ) );
147
	}
148
149
150
	public function testTransformXmlObject()
151
	{
152
		$enc = $this->object->transform();
153
154
		$this->assertEquals( '{&quot;key&quot;:&quot;\u0026quot;&quot;}', $enc->html( (object) ['key' => '&quot;'] ) );
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