PluralRulesTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\I18n;
  16. use Cake\I18n\PluralRules;
  17. use Cake\TestSuite\TestCase;
  18. /**
  19. * PluralRules tests
  20. */
  21. class PluralRulesTest extends TestCase
  22. {
  23. /**
  24. * Returns the notable combinations for locales and numbers
  25. * with the respective plural form that should be selected
  26. *
  27. * @return array
  28. */
  29. public function localesProvider()
  30. {
  31. return [
  32. ['jp', 0, 0],
  33. ['jp', 1, 0],
  34. ['jp_JP', 2, 0],
  35. ['en_US', 0, 1],
  36. ['en', 1, 0],
  37. ['en_UK', 2, 1],
  38. ['pt_BR', 0, 1],
  39. ['pt_BR', 1, 0],
  40. ['pt_BR', 2, 1],
  41. ['pt', 0, 1],
  42. ['pt', 1, 0],
  43. ['pt', 2, 1],
  44. ['pt_PT', 0, 0],
  45. ['pt_PT', 1, 0],
  46. ['pt_PT', 2, 1],
  47. ['fr_FR', 0, 0],
  48. ['fr', 1, 0],
  49. ['fr', 2, 1],
  50. ['ru', 0, 2],
  51. ['ru', 1, 0],
  52. ['ru', 2, 1],
  53. ['ru', 21, 0],
  54. ['ru', 22, 1],
  55. ['ru', 5, 2],
  56. ['ru', 7, 2],
  57. ['sk', 0, 2],
  58. ['sk', 1, 0],
  59. ['sk', 2, 1],
  60. ['sk', 5, 2],
  61. ['ga', 0, 2],
  62. ['ga', 1, 0],
  63. ['ga', 2, 1],
  64. ['ga', 7, 3],
  65. ['ga', 11, 4],
  66. ['is', 1, 0],
  67. ['is', 2, 1],
  68. ['is', 3, 1],
  69. ['is', 11, 1],
  70. ['is', 21, 0],
  71. ['lt', 0, 2],
  72. ['lt', 1, 0],
  73. ['lt', 2, 1],
  74. ['lt', 11, 2],
  75. ['lt', 31, 0],
  76. ['sl', 0, 0],
  77. ['sl', 1, 1],
  78. ['sl', 2, 2],
  79. ['sl', 3, 3],
  80. ['sl', 10, 0],
  81. ['sl', 101, 1],
  82. ['sl', 103, 3],
  83. ['mk', 0, 2],
  84. ['mk', 1, 0],
  85. ['mk', 13, 2],
  86. ['mt', 0, 1],
  87. ['mt', 1, 0],
  88. ['mt', 11, 2],
  89. ['mt', 13, 2],
  90. ['mt', 21, 3],
  91. ['mt', 102, 1],
  92. ['lv', 0, 2],
  93. ['lv', 1, 0],
  94. ['lv', 2, 1],
  95. ['lv', 101, 0],
  96. ['pl', 0, 2],
  97. ['pl', 1, 0],
  98. ['pl', 2, 1],
  99. ['pl', 101, 2],
  100. ['ro', 0, 1],
  101. ['ro', 1, 0],
  102. ['ro', 2, 1],
  103. ['ro', 20, 2],
  104. ['ro', 101, 1],
  105. ['ar', 0, 0],
  106. ['ar', 1, 1],
  107. ['ar', 2, 2],
  108. ['ar', 20, 4],
  109. ['ar', 111, 4],
  110. ['ar', 1000, 5],
  111. ['cy', 0, 2],
  112. ['cy', 1, 0],
  113. ['cy', 10, 2],
  114. ['cy', 11, 3],
  115. ['cy', 8, 3],
  116. ['tr', 0, 1],
  117. ['tr', 1, 0],
  118. ['tr', 2, 1],
  119. ];
  120. }
  121. /**
  122. * Tests that the correct plural form is selected for the locale, number combination
  123. *
  124. * @dataProvider localesProvider
  125. * @return void
  126. */
  127. public function testCalculate($locale, $number, $expected)
  128. {
  129. $this->assertEquals($expected, PluralRules::calculate($locale, $number));
  130. }
  131. }