TranslationMessageSelectorTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Illuminate\Tests\Translation;
  3. use Illuminate\Translation\MessageSelector;
  4. use PHPUnit\Framework\TestCase;
  5. class TranslationMessageSelectorTest extends TestCase
  6. {
  7. /**
  8. * @dataProvider chooseTestData
  9. */
  10. public function testChoose($expected, $id, $number)
  11. {
  12. $selector = new MessageSelector;
  13. $this->assertEquals($expected, $selector->choose($id, $number, 'en'));
  14. }
  15. public function chooseTestData()
  16. {
  17. return [
  18. ['first', 'first', 1],
  19. ['first', 'first', 10],
  20. ['first', 'first|second', 1],
  21. ['second', 'first|second', 10],
  22. ['second', 'first|second', 0],
  23. ['first', '{0} first|{1}second', 0],
  24. ['first', '{1}first|{2}second', 1],
  25. ['second', '{1}first|{2}second', 2],
  26. ['first', '{2}first|{1}second', 2],
  27. ['second', '{9}first|{10}second', 0],
  28. ['first', '{9}first|{10}second', 1],
  29. ['', '{0}|{1}second', 0],
  30. ['', '{0}first|{1}', 1],
  31. ['first', '{1.3}first|{2.3}second', 1.3],
  32. ['second', '{1.3}first|{2.3}second', 2.3],
  33. ['first
  34. line', '{1}first
  35. line|{2}second', 1],
  36. ["first \n
  37. line", "{1}first \n
  38. line|{2}second", 1],
  39. ['first', '{0} first|[1,9]second', 0],
  40. ['second', '{0}first|[1,9]second', 1],
  41. ['second', '{0}first|[1,9]second', 10],
  42. ['first', '{0}first|[2,9]second', 1],
  43. ['second', '[4,*]first|[1,3]second', 1],
  44. ['first', '[4,*]first|[1,3]second', 100],
  45. ['second', '[1,5]first|[6,10]second', 7],
  46. ['first', '[*,4]first|[5,*]second', 1],
  47. ['second', '[5,*]first|[*,4]second', 1],
  48. ['second', '[5,*]first|[*,4]second', 0],
  49. ['first', '{0}first|[1,3]second|[4,*]third', 0],
  50. ['second', '{0}first|[1,3]second|[4,*]third', 1],
  51. ['third', '{0}first|[1,3]second|[4,*]third', 9],
  52. ['first', 'first|second|third', 1],
  53. ['second', 'first|second|third', 9],
  54. ['second', 'first|second|third', 0],
  55. ['first', '{0} first | { 1 } second', 0],
  56. ['first', '[4,*]first | [1,3]second', 100],
  57. ];
  58. }
  59. }