8000 [Translation] Add failing tests to verify that UTF-8 lang files can't… · sammanjac/symfony@deb6dea · GitHub
[go: up one dir, main page]

Skip to content

Commit deb6dea

Browse files
committed
[Translation] Add failing tests to verify that UTF-8 lang files can't be used with another charset
1 parent 0e852fe commit deb6dea

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/Symfony/Tests/Component/Translation/TranslatorTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,27 @@ public function testFlattenedTrans($expected, $messages, $id)
132132
$this->assertEquals($expected, $translator->trans($id, array(), '', 'fr'));
133133
}
134134

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+
135156
/**
136157
* @dataProvider getTransChoiceTests
137158
*/
@@ -199,6 +220,21 @@ public function getTransChoiceTests()
199220
);
200221
}
201222

223+
public function getLoadCatalogueTests()
224+
{
225+
return array(
226+
array('oia', null),
227+
array('oia', 'UTF-8'),
228+
array('öïä', 'UTF-8'),
229+
array 77FB ('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+
202238
public function testTransChoiceFallback()
203239
{
204240
$translator = new Translator('ru', new MessageSelector());

0 commit comments

Comments
 (0)
0