commit | author | age
|
5f8ada
|
1 |
<?php |
AM |
2 |
|
|
3 |
/** |
|
4 |
* Test class to test rcube_charset class |
|
5 |
* |
|
6 |
* @package Tests |
0bfc86
|
7 |
* @group iconv |
TB |
8 |
* @group mbstring |
5f8ada
|
9 |
*/ |
AM |
10 |
class Framework_Charset extends PHPUnit_Framework_TestCase |
|
11 |
{ |
|
12 |
|
|
13 |
/** |
|
14 |
* Data for test_clean() |
|
15 |
*/ |
|
16 |
function data_clean() |
|
17 |
{ |
|
18 |
return array( |
b2e517
|
19 |
array('', ''), |
f7565d
|
20 |
array("\xC1", ""), |
AM |
21 |
array("Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν", "Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν"), |
5f8ada
|
22 |
); |
AM |
23 |
} |
|
24 |
|
|
25 |
/** |
|
26 |
* @dataProvider data_clean |
|
27 |
*/ |
b2e517
|
28 |
function test_clean($input, $output) |
5f8ada
|
29 |
{ |
b2e517
|
30 |
$this->assertEquals($output, rcube_charset::clean($input)); |
5f8ada
|
31 |
} |
b2e517
|
32 |
|
AM |
33 |
/** |
7eefdc
|
34 |
* Just check for faulty byte-sequence, regardless of the actual cleaning results |
TB |
35 |
*/ |
|
36 |
function test_clean_2() |
|
37 |
{ |
|
38 |
$bogus = "сим\xD0вол"; |
|
39 |
$this->assertRegExp('/\xD0\xD0/', $bogus); |
|
40 |
$this->assertNotRegExp('/\xD0\xD0/', rcube_charset::clean($bogus)); |
|
41 |
} |
|
42 |
|
|
43 |
/** |
b2e517
|
44 |
* Data for test_parse_charset() |
AM |
45 |
*/ |
|
46 |
function data_parse_charset() |
|
47 |
{ |
|
48 |
return array( |
|
49 |
array('UTF8', 'UTF-8'), |
|
50 |
array('WIN1250', 'WINDOWS-1250'), |
|
51 |
); |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* @dataProvider data_parse_charset |
|
56 |
*/ |
|
57 |
function test_parse_charset($input, $output) |
|
58 |
{ |
|
59 |
$this->assertEquals($output, rcube_charset::parse_charset($input)); |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Data for test_convert() |
|
64 |
*/ |
|
65 |
function data_convert() |
|
66 |
{ |
|
67 |
return array( |
|
68 |
array('ö', 'ö', 'UTF-8', 'UTF-8'), |
|
69 |
array('ö', '', 'UTF-8', 'US-ASCII'), |
|
70 |
array('aż', 'a', 'UTF-8', 'US-ASCII'), |
|
71 |
array('&BCAEMARBBEEESwQ7BDoEOA-', 'Рассылки', 'UTF7-IMAP', 'UTF-8'), |
|
72 |
array('Рассылки', '&BCAEMARBBEEESwQ7BDoEOA-', 'UTF-8', 'UTF7-IMAP'), |
|
73 |
); |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* @dataProvider data_convert |
|
78 |
*/ |
|
79 |
function test_convert($input, $output, $from, $to) |
|
80 |
{ |
|
81 |
$this->assertEquals($output, rcube_charset::convert($input, $from, $to)); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Data for test_utf7_to_utf8() |
|
86 |
*/ |
|
87 |
function data_utf7_to_utf8() |
|
88 |
{ |
|
89 |
return array( |
|
90 |
array('+BCAEMARBBEEESwQ7BDoEOA-', 'Рассылки'), |
|
91 |
); |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* @dataProvider data_utf7_to_utf8 |
|
96 |
*/ |
|
97 |
function test_utf7_to_utf8($input, $output) |
|
98 |
{ |
|
99 |
$this->assertEquals($output, rcube_charset::utf7_to_utf8($input)); |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Data for test_utf7imap_to_utf8() |
|
104 |
*/ |
|
105 |
function data_utf7imap_to_utf8() |
|
106 |
{ |
|
107 |
return array( |
|
108 |
array('&BCAEMARBBEEESwQ7BDoEOA-', 'Рассылки'), |
|
109 |
); |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* @dataProvider data_utf7imap_to_utf8 |
|
114 |
*/ |
|
115 |
function test_utf7imap_to_utf8($input, $output) |
|
116 |
{ |
|
117 |
$this->assertEquals($output, rcube_charset::utf7imap_to_utf8($input)); |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* Data for test_utf8_to_utf7imap() |
|
122 |
*/ |
|
123 |
function data_utf8_to_utf7imap() |
|
124 |
{ |
|
125 |
return array( |
|
126 |
array('Рассылки', '&BCAEMARBBEEESwQ7BDoEOA-'), |
|
127 |
); |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* @dataProvider data_utf8_to_utf7imap |
|
132 |
*/ |
|
133 |
function test_utf8_to_utf7imap($input, $output) |
|
134 |
{ |
|
135 |
$this->assertEquals($output, rcube_charset::utf8_to_utf7imap($input)); |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* Data for test_utf16_to_utf8() |
|
140 |
*/ |
|
141 |
function data_utf16_to_utf8() |
|
142 |
{ |
|
143 |
return array( |
|
144 |
array(base64_decode('BCAEMARBBEEESwQ7BDoEOA=='), 'Рассылки'), |
|
145 |
); |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* @dataProvider data_utf16_to_utf8 |
|
150 |
*/ |
|
151 |
function test_utf16_to_utf8($input, $output) |
|
152 |
{ |
|
153 |
$this->assertEquals($output, rcube_charset::utf16_to_utf8($input)); |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* Data for test_detect() |
|
158 |
*/ |
|
159 |
function data_detect() |
|
160 |
{ |
|
161 |
return array( |
|
162 |
array('', '', 'UTF-8'), |
|
163 |
array('a', 'UTF-8', 'UTF-8'), |
|
164 |
); |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* @dataProvider data_detect |
|
169 |
*/ |
|
170 |
function test_detect($input, $fallback, $output) |
|
171 |
{ |
|
172 |
$this->assertEquals($output, rcube_charset::detect($input, $fallback)); |
|
173 |
} |
|
174 |
|
a5b8ef
|
175 |
/** |
AM |
176 |
* Data for test_detect() |
|
177 |
*/ |
|
178 |
function data_detect_with_lang() |
|
179 |
{ |
|
180 |
return array( |
|
181 |
array('Åã¥Ü¦WºÙ,¥Dn', 'zh_TW', 'BIG-5'), |
|
182 |
); |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* @dataProvider data_detect_with_lang |
|
187 |
*/ |
|
188 |
function test_detect_with_lang($input, $lang, $output) |
|
189 |
{ |
|
190 |
$this->assertEquals($output, rcube_charset::detect($input, $output, $lang)); |
|
191 |
} |
|
192 |
|
5f8ada
|
193 |
} |