78288da40e150b964d5c7a3ce6a370af824fa073
[yaffs-website] / vendor / symfony / translation / Tests / IdentityTranslatorTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Translation\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Intl\Util\IntlTestHelper;
16 use Symfony\Component\Translation\IdentityTranslator;
17
18 class IdentityTranslatorTest extends TestCase
19 {
20     /**
21      * @dataProvider getTransTests
22      */
23     public function testTrans($expected, $id, $parameters)
24     {
25         $translator = new IdentityTranslator();
26
27         $this->assertEquals($expected, $translator->trans($id, $parameters));
28     }
29
30     /**
31      * @dataProvider getTransChoiceTests
32      */
33     public function testTransChoiceWithExplicitLocale($expected, $id, $number, $parameters)
34     {
35         $translator = new IdentityTranslator();
36         $translator->setLocale('en');
37
38         $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters));
39     }
40
41     /**
42      * @dataProvider getTransChoiceTests
43      */
44     public function testTransChoiceWithDefaultLocale($expected, $id, $number, $parameters)
45     {
46         \Locale::setDefault('en');
47
48         $translator = new IdentityTranslator();
49
50         $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters));
51     }
52
53     public function testGetSetLocale()
54     {
55         $translator = new IdentityTranslator();
56         $translator->setLocale('en');
57
58         $this->assertEquals('en', $translator->getLocale());
59     }
60
61     public function testGetLocaleReturnsDefaultLocaleIfNotSet()
62     {
63         // in order to test with "pt_BR"
64         IntlTestHelper::requireFullIntl($this, false);
65
66         $translator = new IdentityTranslator();
67
68         \Locale::setDefault('en');
69         $this->assertEquals('en', $translator->getLocale());
70
71         \Locale::setDefault('pt_BR');
72         $this->assertEquals('pt_BR', $translator->getLocale());
73     }
74
75     public function getTransTests()
76     {
77         return array(
78             array('Symfony is great!', 'Symfony is great!', array()),
79             array('Symfony is awesome!', 'Symfony is %what%!', array('%what%' => 'awesome')),
80         );
81     }
82
83     public function getTransChoiceTests()
84     {
85         return array(
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)),
94         );
95     }
96 }