4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Intl\Util\IntlTestHelper;
16 use Symfony\Component\Translation\IdentityTranslator;
18 class IdentityTranslatorTest extends TestCase
21 * @dataProvider getTransTests
23 public function testTrans($expected, $id, $parameters)
25 $translator = new IdentityTranslator();
27 $this->assertEquals($expected, $translator->trans($id, $parameters));
31 * @dataProvider getTransChoiceTests
33 public function testTransChoiceWithExplicitLocale($expected, $id, $number, $parameters)
35 $translator = new IdentityTranslator();
36 $translator->setLocale('en');
38 $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters));
42 * @dataProvider getTransChoiceTests
44 public function testTransChoiceWithDefaultLocale($expected, $id, $number, $parameters)
46 \Locale::setDefault('en');
48 $translator = new IdentityTranslator();
50 $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters));
53 public function testGetSetLocale()
55 $translator = new IdentityTranslator();
56 $translator->setLocale('en');
58 $this->assertEquals('en', $translator->getLocale());
61 public function testGetLocaleReturnsDefaultLocaleIfNotSet()
63 // in order to test with "pt_BR"
64 IntlTestHelper::requireFullIntl($this, false);
66 $translator = new IdentityTranslator();
68 \Locale::setDefault('en');
69 $this->assertEquals('en', $translator->getLocale());
71 \Locale::setDefault('pt_BR');
72 $this->assertEquals('pt_BR', $translator->getLocale());
75 public function getTransTests()
78 array('Symfony is great!', 'Symfony is great!', array()),
79 array('Symfony is awesome!', 'Symfony is %what%!', array('%what%' => 'awesome')),
83 public function getTransChoiceTests()
86 array('There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0, array('%count%' => 0)),
87 array('There is one apple', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 1, array('%count%' => 1)),
88 array('There are 10 apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10, array('%count%' => 10)),
89 array('There are 0 apples', 'There is 1 apple|There are %count% apples', 0, array('%count%' => 0)),
90 array('There is 1 apple', 'There is 1 apple|There are %count% apples', 1, array('%count%' => 1)),
91 array('There are 10 apples', 'There is 1 apple|There are %count% apples', 10, array('%count%' => 10)),
92 // custom validation messages may be coded with a fixed value
93 array('There are 2 apples', 'There are 2 apples', 2, array('%count%' => 2)),