SymfonyComponentTranslationTestsIdentityTranslatorTest

The Simple Calendar Symfony Component Translation Tests IdentityTranslatorTest class.

Defined (1)

The class is defined in the following location(s).

/vendor/symfony/translation/Tests/IdentityTranslatorTest.php  
  1. class IdentityTranslatorTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @dataProvider getTransTests 
  4. */ 
  5. public function testTrans($expected, $id, $parameters) 
  6. $translator = new IdentityTranslator(); 
  7.  
  8. $this->assertEquals($expected, $translator->trans($id, $parameters)); 
  9.  
  10. /** 
  11. * @dataProvider getTransChoiceTests 
  12. */ 
  13. public function testTransChoiceWithExplicitLocale($expected, $id, $number, $parameters) 
  14. $translator = new IdentityTranslator(); 
  15. $translator->setLocale('en'); 
  16.  
  17. $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters)); 
  18.  
  19. /** 
  20. * @dataProvider getTransChoiceTests 
  21. */ 
  22. public function testTransChoiceWithDefaultLocale($expected, $id, $number, $parameters) 
  23. \Locale::setDefault('en'); 
  24.  
  25. $translator = new IdentityTranslator(); 
  26.  
  27. $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters)); 
  28.  
  29. public function testGetSetLocale() 
  30. $translator = new IdentityTranslator(); 
  31. $translator->setLocale('en'); 
  32.  
  33. $this->assertEquals('en', $translator->getLocale()); 
  34.  
  35. public function testGetLocaleReturnsDefaultLocaleIfNotSet() 
  36. // in order to test with "pt_BR" 
  37. IntlTestHelper::requireFullIntl($this); 
  38.  
  39. $translator = new IdentityTranslator(); 
  40.  
  41. \Locale::setDefault('en'); 
  42. $this->assertEquals('en', $translator->getLocale()); 
  43.  
  44. \Locale::setDefault('pt_BR'); 
  45. $this->assertEquals('pt_BR', $translator->getLocale()); 
  46.  
  47. public function getTransTests() 
  48. return array( 
  49. array('Symfony is great!', 'Symfony is great!', array()),  
  50. array('Symfony is awesome!', 'Symfony is %what%!', array('%what%' => 'awesome')),  
  51. ); 
  52.  
  53. public function getTransChoiceTests() 
  54. return array( 
  55. 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)),  
  56. 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)),  
  57. 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)),  
  58. array('There are 0 apples', 'There is 1 apple|There are %count% apples', 0, array('%count%' => 0)),  
  59. array('There is 1 apple', 'There is 1 apple|There are %count% apples', 1, array('%count%' => 1)),  
  60. array('There are 10 apples', 'There is 1 apple|There are %count% apples', 10, array('%count%' => 10)),  
  61. // custom validation messages may be coded with a fixed value 
  62. array('There are 2 apples', 'There are 2 apples', 2, array('%count%' => 2)),  
  63. );