PluralRulesTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. * 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. return [
  31. ['jp', 0, 0],
  32. ['jp', 1, 0],
  33. ['jp_JP', 2, 0],
  34. ['en_US', 0, 1],
  35. ['en', 1, 0],
  36. ['en_UK', 2, 1],
  37. ['pt_BR', 0, 1],
  38. ['pt_BR', 1, 0],
  39. ['pt_BR', 2, 1],
  40. ['pt', 0, 1],
  41. ['pt', 1, 0],
  42. ['pt', 2, 1],
  43. ['pt_PT', 0, 0],
  44. ['pt_PT', 1, 0],
  45. ['pt_PT', 2, 1],
  46. ['fr_FR', 0, 0],
  47. ['fr', 1, 0],
  48. ['fr', 2, 1],
  49. ['ru', 0, 2],
  50. ['ru', 1, 0],
  51. ['ru', 2, 1],
  52. ['sk', 0, 2],
  53. ['sk', 1, 0],
  54. ['sk', 2, 1],
  55. ['sk', 5, 2],
  56. ['ga', 0, 2],
  57. ['ga', 1, 0],
  58. ['ga', 2, 1],
  59. ['ga', 7, 3],
  60. ['ga', 11, 4],
  61. ['lt', 0, 2],
  62. ['lt', 1, 0],
  63. ['lt', 2, 1],
  64. ['lt', 11, 2],
  65. ['lt', 31, 0],
  66. ['sl', 0, 0],
  67. ['sl', 1, 1],
  68. ['sl', 2, 2],
  69. ['sl', 3, 3],
  70. ['sl', 10, 0],
  71. ['sl', 101, 1],
  72. ['sl', 103, 3],
  73. ['mk', 0, 2],
  74. ['mk', 1, 0],
  75. ['mk', 13, 2],
  76. ['mt', 0, 1],
  77. ['mt', 1, 0],
  78. ['mt', 11, 2],
  79. ['mt', 13, 2],
  80. ['mt', 21, 3],
  81. ['mt', 102, 1],
  82. ['lv', 0, 2],
  83. ['lv', 1, 0],
  84. ['lv', 2, 1],
  85. ['lv', 101, 0],
  86. ['pl', 0, 2],
  87. ['pl', 1, 0],
  88. ['pl', 2, 1],
  89. ['pl', 101, 2],
  90. ['ro', 0, 1],
  91. ['ro', 1, 0],
  92. ['ro', 2, 1],
  93. ['ro', 20, 2],
  94. ['ro', 101, 1],
  95. ['ar', 0, 0],
  96. ['ar', 1, 1],
  97. ['ar', 2, 2],
  98. ['ar', 20, 4],
  99. ['ar', 111, 4],
  100. ['ar', 1000, 5],
  101. ['cy', 0, 2],
  102. ['cy', 1, 0],
  103. ['cy', 10, 2],
  104. ['cy', 11, 3],
  105. ['cy', 8, 3],
  106. ];
  107. }
  108. /**
  109. * Tests that the correct plural form is selected for the locale, number combination
  110. *
  111. * @dataProvider localesProvider
  112. * @return void
  113. */
  114. public function testCalculate($locale, $number, $expected) {
  115. $this->assertEquals($expected, PluralRules::calculate($locale, $number));
  116. }
  117. }