IdentityTranslatorTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Tests\Component\Translation;
  11. use Symfony\Component\Translation\IdentityTranslator;
  12. use Symfony\Component\Translation\MessageSelector;
  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(new MessageSelector());
  21. $this->assertEquals($expected, $translator->trans($id, $parameters));
  22. }
  23. /**
  24. * @dataProvider getTransChoiceTests
  25. */
  26. public function testTransChoice($expected, $id, $number, $parameters)
  27. {
  28. $translator = new IdentityTranslator(new MessageSelector());
  29. $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters));
  30. }
  31. // noop
  32. public function testGetSetLocale()
  33. {
  34. $translator = new IdentityTranslator(new MessageSelector());
  35. $translator->setLocale('en');
  36. $translator->getLocale();
  37. }
  38. public function getTransTests()
  39. {
  40. return array(
  41. array('Symfony2 is great!', 'Symfony2 is great!', array()),
  42. array('Symfony2 is awesome!', 'Symfony2 is %what%!', array('%what%' => 'awesome')),
  43. );
  44. }
  45. public function getTransChoiceTests()
  46. {
  47. return array(
  48. 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)),
  49. );
  50. }
  51. }