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