Nenhuma Descrição

IdentityTranslatorTest.php 3.2KB

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