|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Kint_Object_BlobTest extends KintTestCase |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
public function blobProvider() |
|
6
|
|
|
{ |
|
7
|
|
|
$p = new Kint_Parser(); |
|
|
|
|
|
|
8
|
|
|
$b = Kint_Object::blank('$v'); |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
Kint_Object_Blob::$char_encodings = array( |
|
11
|
|
|
'ASCII', |
|
12
|
|
|
'UTF-8', |
|
13
|
|
|
); |
|
14
|
|
|
|
|
15
|
|
|
$strings = array( |
|
16
|
|
|
'empty' => array( |
|
17
|
|
|
'', |
|
18
|
|
|
'ASCII', |
|
19
|
|
|
'string', |
|
20
|
|
|
), |
|
21
|
|
|
'ASCII' => array( |
|
22
|
|
|
"The quick brown fox jumps<br>\r\n\tover the lazy dog", |
|
23
|
|
|
'ASCII', |
|
24
|
|
|
'string', |
|
25
|
|
|
), |
|
26
|
|
|
'UTF-8' => array( |
|
27
|
|
|
"El zorro marrón rápido salta sobre<br>\r\n\tel perro perezoso", |
|
28
|
|
|
'UTF-8', |
|
29
|
|
|
'UTF-8 string', |
|
30
|
|
|
), |
|
31
|
|
|
'fail' => array( |
|
32
|
|
|
"The quick brown fox jumps<br>\r\n\tover the lazy dog\x90\x1b", |
|
33
|
|
|
false, |
|
34
|
|
|
'binary string', |
|
35
|
|
|
), |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
if (!defined('HHVM_VERSION')) { |
|
39
|
|
|
Kint_Object_Blob::$char_encodings[] = 'SJIS'; |
|
40
|
|
|
Kint_Object_Blob::$char_encodings[] = 'EUC-JP'; |
|
41
|
|
|
Kint_Object_Blob::$char_encodings[] = 'Windows-1252'; |
|
42
|
|
|
$strings['SJIS'] = array( |
|
43
|
|
|
mb_convert_encoding("キント最強<br>\r\n\tASCII", 'SJIS', 'UTF-8'), |
|
44
|
|
|
'SJIS', |
|
45
|
|
|
'SJIS string', |
|
46
|
|
|
); |
|
47
|
|
|
$strings['EUC-JP'] = array( |
|
48
|
|
|
mb_convert_encoding("キント最強<br>\r\n\tASCII", 'EUC-JP', 'UTF-8'), |
|
49
|
|
|
'EUC-JP', |
|
50
|
|
|
'EUC-JP string', |
|
51
|
|
|
); |
|
52
|
|
|
$strings['yuck'] = array( |
|
53
|
|
|
mb_convert_encoding("El zorro marrón rápido salta sobre<br>\r\n\tel perro perezoso", 'Windows-1252', 'UTF-8'), |
|
54
|
|
|
'Windows-1252', |
|
55
|
|
|
'Windows-1252 string', |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
foreach ($strings as $encoding => &$string) { |
|
60
|
|
|
array_unshift($string, $p->parse($string[0], clone $b)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $strings; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @dataProvider blobProvider |
|
68
|
|
|
*/ |
|
69
|
|
|
public function testGetType(Kint_Object_Blob $object, $string, $encoding, $type) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
$this->assertEquals($type, $object->getType()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @dataProvider blobProvider |
|
76
|
|
|
*/ |
|
77
|
|
|
public function testGetValueShort(Kint_Object_Blob $object, $string, $encoding) |
|
78
|
|
|
{ |
|
79
|
|
|
if ($encoding) { |
|
80
|
|
|
$string = mb_convert_encoding($string, 'UTF-8', $encoding); |
|
|
|
|
|
|
81
|
|
|
$string = '"'.$string.'"'; |
|
|
|
|
|
|
82
|
|
|
$string = mb_convert_encoding($string, $encoding, 'UTF-8'); |
|
|
|
|
|
|
83
|
|
|
} else { |
|
84
|
|
|
$string = '"'.$string.'"'; |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals($string, $object->getValueShort()); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function testTransplant() |
|
91
|
|
|
{ |
|
92
|
|
|
$p = new Kint_Parser(); |
|
|
|
|
|
|
93
|
|
|
$b = Kint_Object::blank('$v'); |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
$string = 'How now brown cow'; |
|
96
|
|
|
|
|
97
|
|
|
$o = $p->parse($string, clone $b); |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
$this->assertNotFalse($o->encoding); |
|
|
|
|
|
|
100
|
|
|
$this->assertNotNull($o->encoding); |
|
101
|
|
|
$this->assertNotEmpty($o->encoding); |
|
102
|
|
|
|
|
103
|
|
|
$o2 = $o->transplant(new Kint_Object_Blob()); |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
$o->hints[] = 'string'; |
|
106
|
|
|
|
|
107
|
|
|
$this->assertEquals($o, $o2); |
|
108
|
|
|
$this->assertNotSame($o, $o2); |
|
109
|
|
|
$this->assertSame($o->encoding, $o2->encoding); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @dataProvider blobProvider |
|
114
|
|
|
*/ |
|
115
|
|
|
public function testStrlen(Kint_Object_Blob $object, $string, $encoding) |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
if ($encoding === false) { |
|
118
|
|
|
$this->assertEquals(strlen($string), Kint_Object_Blob::strlen($string)); |
|
119
|
|
|
$this->assertEquals(strlen($string), Kint_Object_Blob::strlen($string, false)); |
|
120
|
|
|
} else { |
|
121
|
|
|
$this->assertEquals(mb_strlen($string, $encoding), Kint_Object_Blob::strlen($string)); |
|
122
|
|
|
$this->assertEquals(mb_strlen($string, $encoding), Kint_Object_Blob::strlen($string, $encoding)); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @dataProvider blobProvider |
|
128
|
|
|
*/ |
|
129
|
|
|
public function testDetectEncoding(Kint_Object_Blob $object, $string, $encoding) |
|
|
|
|
|
|
130
|
|
|
{ |
|
131
|
|
|
$this->assertEquals($encoding, Kint_Object_Blob::detectEncoding($string)); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @dataProvider blobProvider |
|
136
|
|
|
* @expectedException \PHPUnit_Framework_Error_Deprecated |
|
137
|
|
|
*/ |
|
138
|
|
|
public function testEscapeText(Kint_Object_Blob $object, $string, $encoding) |
|
|
|
|
|
|
139
|
|
|
{ |
|
140
|
|
|
Kint::$enabled_mode = Kint::MODE_TEXT; |
|
141
|
|
|
|
|
142
|
|
|
$this->assertEquals($string, Kint_Object_Blob::escape($string, $encoding)); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @dataProvider blobProvider |
|
147
|
|
|
* @expectedException \PHPUnit_Framework_Error_Deprecated |
|
148
|
|
|
*/ |
|
149
|
|
|
public function testEscapeTextNoEncoding(Kint_Object_Blob $object, $string) |
|
|
|
|
|
|
150
|
|
|
{ |
|
151
|
|
|
Kint::$enabled_mode = Kint::MODE_TEXT; |
|
152
|
|
|
|
|
153
|
|
|
$this->assertEquals($string, Kint_Object_Blob::escape($string)); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @dataProvider blobProvider |
|
158
|
|
|
* @expectedException \PHPUnit_Framework_Error_Deprecated |
|
159
|
|
|
*/ |
|
160
|
|
|
public function testEscapeCli(Kint_Object_Blob $object, $string, $encoding) |
|
|
|
|
|
|
161
|
|
|
{ |
|
162
|
|
|
Kint::$enabled_mode = Kint::MODE_CLI; |
|
163
|
|
|
|
|
164
|
|
|
$this->assertNotContains("\x1b", Kint_Object_Blob::escape($string, $encoding)); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @dataProvider blobProvider |
|
169
|
|
|
* @expectedException \PHPUnit_Framework_Error_Deprecated |
|
170
|
|
|
*/ |
|
171
|
|
|
public function testEscapeCliNoEncoding(Kint_Object_Blob $object, $string) |
|
|
|
|
|
|
172
|
|
|
{ |
|
173
|
|
|
Kint::$enabled_mode = Kint::MODE_CLI; |
|
174
|
|
|
|
|
175
|
|
|
$this->assertNotContains("\x1b", Kint_Object_Blob::escape($string)); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @dataProvider blobProvider |
|
180
|
|
|
* @expectedException \PHPUnit_Framework_Error_Deprecated |
|
181
|
|
|
*/ |
|
182
|
|
|
public function testEscapeHtml(Kint_Object_Blob $object, $string, $encoding) |
|
|
|
|
|
|
183
|
|
|
{ |
|
184
|
|
|
Kint::$enabled_mode = Kint::MODE_RICH; |
|
185
|
|
|
|
|
186
|
|
|
if ($encoding === false || $encoding === 'ASCII') { |
|
187
|
|
|
$new_encoding = 'UTF-8'; |
|
|
|
|
|
|
188
|
|
|
} else { |
|
189
|
|
|
$new_encoding = $encoding; |
|
|
|
|
|
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
$expect = htmlspecialchars($string, ENT_NOQUOTES, $new_encoding); |
|
|
|
|
|
|
193
|
|
|
$expect = mb_encode_numericentity($expect, array(0x80, 0xffff, 0, 0xffff), $new_encoding); |
|
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
$this->assertEquals($expect, Kint_Object_Blob::escape($string, $encoding)); |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.