Kint_Object_BlobTest::testEscapeText()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class Kint_Object_BlobTest extends KintTestCase
0 ignored issues
show
Coding Style introduced by
Kint_Object_BlobTest does not seem to conform to the naming convention (^[A-Z][a-zA-Z0-9]*$).

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.

Loading history...
4
{
5
    public function blobProvider()
6
    {
7
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
8
        $b = Kint_Object::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $string is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $encoding is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $string. This often makes code more readable.
Loading history...
81
            $string = '"'.$string.'"';
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $string. This often makes code more readable.
Loading history...
82
            $string = mb_convert_encoding($string, $encoding, 'UTF-8');
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $string. This often makes code more readable.
Loading history...
83
        } else {
84
            $string = '"'.$string.'"';
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $string. This often makes code more readable.
Loading history...
85
        }
86
87
        $this->assertEquals($string, $object->getValueShort());
88
    }
89
90
    public function testTransplant()
91
    {
92
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
93
        $b = Kint_Object::blank('$v');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
94
95
        $string = 'How now brown cow';
96
97
        $o = $p->parse($string, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
98
99
        $this->assertNotFalse($o->encoding);
0 ignored issues
show
Bug introduced by
The property encoding does not seem to exist in Kint_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
100
        $this->assertNotNull($o->encoding);
101
        $this->assertNotEmpty($o->encoding);
102
103
        $o2 = $o->transplant(new Kint_Object_Blob());
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o2. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
183
    {
184
        Kint::$enabled_mode = Kint::MODE_RICH;
185
186
        if ($encoding === false || $encoding === 'ASCII') {
187
            $new_encoding = 'UTF-8';
0 ignored issues
show
Coding Style introduced by
$new_encoding does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
188
        } else {
189
            $new_encoding = $encoding;
0 ignored issues
show
Coding Style introduced by
$new_encoding does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
190
        }
191
192
        $expect = htmlspecialchars($string, ENT_NOQUOTES, $new_encoding);
0 ignored issues
show
Coding Style introduced by
$new_encoding does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
193
        $expect = mb_encode_numericentity($expect, array(0x80, 0xffff, 0, 0xffff), $new_encoding);
0 ignored issues
show
Coding Style introduced by
$new_encoding does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
194
195
        $this->assertEquals($expect, Kint_Object_Blob::escape($string, $encoding));
196
    }
197
}
198