PluralRulesTest.php 3.4 KB

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