MessageSelectorTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\MessageSelector;
  12. class MessageSelectorTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @dataProvider getChooseTests
  16. */
  17. public function testChoose($expected, $id, $number)
  18. {
  19. $selector = new MessageSelector();
  20. $this->assertEquals($expected, $selector->choose($id, $number, 'en'));
  21. }
  22. /**
  23. * @expectedException InvalidArgumentException
  24. */
  25. public function testChooseWhenNoEnoughChoices()
  26. {
  27. $selector = new MessageSelector();
  28. $selector->choose('foo', 10, 'en');
  29. }
  30. public function getChooseTests()
  31. {
  32. return array(
  33. array('There is no apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0),
  34. array('There is no apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0),
  35. array('There is no apples', '{0}There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0),
  36. array('There is one apple', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 1),
  37. array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 10),
  38. array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf]There is %count% apples', 10),
  39. array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 10),
  40. array('There is %count% apples', 'There is one apple|There is %count% apples', 0),
  41. array('There is one apple', 'There is one apple|There is %count% apples', 1),
  42. array('There is %count% apples', 'There is one apple|There is %count% apples', 10),
  43. array('There is %count% apples', 'one: There is one apple|more: There is %count% apples', 0),
  44. array('There is one apple', 'one: There is one apple|more: There is %count% apples', 1),
  45. array('There is %count% apples', 'one: There is one apple|more: There is %count% apples', 10),
  46. array('There is no apples', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 0),
  47. array('There is one apple', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 1),
  48. array('There is %count% apples', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 10),
  49. array('', '{0}|{1} There is one apple|]1,Inf] There is %count% apples', 0),
  50. array('', '{0} There is no apples|{1}|]1,Inf] There is %count% apples', 1),
  51. );
  52. }
  53. }