@@ -132,6 +132,27 @@ public function testFlattenedTrans($expected, $messages, $id)
132
132
$ this ->assertEquals ($ expected , $ translator ->trans ($ id , array (), '' , 'fr ' ));
133
133
}
134
134
135
+ /**
136
+ * @dataProvider getLoadCatalogueTests
137
+ */
138
+ public function testLoadCatalogueConvertsEncoding ($ translation , $ charset )
139
+ {
140
+ if (!extension_loaded ('mbstring ' )) {
141
+ $ this ->markTestSkipped ('This test relies on the mbstring extension ' );
142
+ }
143
+ $ translator = new Translator ('en ' , new MessageSelector (), $ charset );
144
+ $ translator ->addLoader ('array ' , new ArrayLoader ());
145
+ $ translator ->addResource ('array ' , array ('id ' => $ translation ), 'en ' , 'messages ' );
146
+
147
+ if (null !== $ charset && mb_detect_encoding ($ translation ) !== $ charset ) {
148
+ $ expected = mb_convert_encoding ($ translation , $ charset , mb_detect_encoding ($ translation ));
149
+ } else {
150
+ $ expected = $ translation ;
151
+ }
152
+
153
+ $ this ->assertEquals ($ expected , $ translator ->trans ('id ' , array (), 'messages ' , 'en ' ));
154
+ }
155
+
135
156
/**
136
157
* @dataProvider getTransChoiceTests
137
158
*/
@@ -199,6 +220,21 @@ public function getTransChoiceTests()
199
220
);
200
221
}
201
222
223
+ public function getLoadCatalogueTests ()
224
+ {
225
+ return array (
226
+ array ('oia ' , null ),
227
+ array ('oia ' , 'UTF-8 ' ),
228
+ array ('öïä ' , 'UTF-8 ' ),
229
+ array('oia ' , 'ISO-8859-1 ' ),
230
+ array ('öïä ' , 'ISO-8859-1 ' ),
231
+ array ('цфЭ ' , 'UTF-8 ' ),
232
+ array ('цфЭ ' , 'KOI8-R ' ),
233
+ array ('ヨラリ ' , 'UTF-8 ' ),
234
+ array ('ヨラリ ' , 'SJIS ' ),
235
+ );
236
+ }
237
+
202
238
public function testTransChoiceFallback ()
203
239
{
204
240
$ translator = new Translator ('ru ' , new MessageSelector ());
0 commit comments