@@ -29,19 +29,43 @@ public function testTrans($expected, $id, $parameters)
2929 /**
3030 * @dataProvider getTransChoiceTests
3131 */
32- public function testTransChoice ($ expected , $ id , $ number , $ parameters )
32+ public function testTransChoiceWithExplicitLocale ($ expected , $ id , $ number , $ parameters )
3333 {
34+ $ translator = new IdentityTranslator (new MessageSelector ());
35+ $ translator ->setLocale ('en ' );
36+
37+ $ this ->assertEquals ($ expected , $ translator ->transChoice ($ id , $ number , $ parameters ));
38+ }
39+
40+ /**
41+ * @dataProvider getTransChoiceTests
42+ */
43+ public function testTransChoiceWithDefaultLocale ($ expected , $ id , $ number , $ parameters )
44+ {
45+ \Locale::setDefault ('en ' );
46+
3447 $ translator = new IdentityTranslator (new MessageSelector ());
3548
3649 $ this ->assertEquals ($ expected , $ translator ->transChoice ($ id , $ number , $ parameters ));
3750 }
3851
39- // noop
4052 public function testGetSetLocale ()
4153 {
4254 $ translator = new IdentityTranslator (new MessageSelector ());
4355 $ translator ->setLocale ('en ' );
44- $ translator ->getLocale ();
56+
57+ $ this ->assertEquals ('en ' , $ translator ->getLocale ());
58+ }
59+
60+ public function testGetLocaleReturnsDefaultLocaleIfNotSet ()
61+ {
62+ $ translator = new IdentityTranslator (new MessageSelector ());
63+
64+ \Locale::setDefault ('en ' );
65+ $ this ->assertEquals ('en ' , $ translator ->getLocale ());
66+
67+ \Locale::setDefault ('pt_BR ' );
68+ $ this ->assertEquals ('pt_BR ' , $ translator ->getLocale ());
4569 }
4670
4771 public function getTransTests ()
@@ -55,7 +79,12 @@ public function getTransTests()
5579 public function getTransChoiceTests ()
5680 {
5781 return array (
58- array ('There is 10 apples ' , '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples ' , 10 , array ('%count% ' => 10 )),
82+ array ('There is no apple ' , '{0} There is no apple|{1} There is one apple|]1,Inf] There are %count% apples ' , 0 , array ('%count% ' => 0 )),
83+ array ('There is one apple ' , '{0} There is no apple|{1} There is one apple|]1,Inf] There are %count% apples ' , 1 , array ('%count% ' => 1 )),
84+ array ('There are 10 apples ' , '{0} There is no apple|{1} There is one apple|]1,Inf] There are %count% apples ' , 10 , array ('%count% ' => 10 )),
85+ array ('There are 0 apples ' , 'There is 1 apple|There are %count% apples ' , 0 , array ('%count% ' => 0 )),
86+ array ('There is 1 apple ' , 'There is 1 apple|There are %count% apples ' , 1 , array ('%count% ' => 1 )),
87+ array ('There are 10 apples ' , 'There is 1 apple|There are %count% apples ' , 10 , array ('%count% ' => 10 )),
5988 );
6089 }
6190}
0 commit comments