LanguagePlTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @author Amir E. Aharoni
  4. * @copyright Copyright © 2012, Amir E. Aharoni
  5. * @file
  6. */
  7. /** Tests for MediaWiki languages/classes/LanguagePl.php */
  8. class LanguagePlTest extends LanguageClassesTestCase {
  9. /**
  10. * @dataProvider providePlural
  11. * @covers Language::convertPlural
  12. */
  13. public function testPlural( $result, $value ) {
  14. $forms = [ 'one', 'few', 'many' ];
  15. $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
  16. }
  17. /**
  18. * @dataProvider providePlural
  19. * @covers Language::getPluralRuleType
  20. */
  21. public function testGetPluralRuleType( $result, $value ) {
  22. $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
  23. }
  24. public static function providePlural() {
  25. return [
  26. [ 'many', 0 ],
  27. [ 'one', 1 ],
  28. [ 'few', 2 ],
  29. [ 'few', 3 ],
  30. [ 'few', 4 ],
  31. [ 'many', 5 ],
  32. [ 'many', 9 ],
  33. [ 'many', 10 ],
  34. [ 'many', 11 ],
  35. [ 'many', 21 ],
  36. [ 'few', 22 ],
  37. [ 'few', 23 ],
  38. [ 'few', 24 ],
  39. [ 'many', 25 ],
  40. [ 'many', 200 ],
  41. [ 'many', 201 ],
  42. ];
  43. }
  44. /**
  45. * @dataProvider providePluralTwoForms
  46. * @covers Language::convertPlural
  47. */
  48. public function testPluralTwoForms( $result, $value ) {
  49. $forms = [ 'one', 'other' ];
  50. $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
  51. }
  52. public static function providePluralTwoForms() {
  53. return [
  54. [ 'other', 0 ],
  55. [ 'one', 1 ],
  56. [ 'other', 2 ],
  57. [ 'other', 3 ],
  58. [ 'other', 4 ],
  59. [ 'other', 5 ],
  60. [ 'other', 9 ],
  61. [ 'other', 10 ],
  62. [ 'other', 11 ],
  63. [ 'other', 21 ],
  64. [ 'other', 22 ],
  65. [ 'other', 23 ],
  66. [ 'other', 24 ],
  67. [ 'other', 25 ],
  68. [ 'other', 200 ],
  69. [ 'other', 201 ],
  70. ];
  71. }
  72. /**
  73. * @covers Language::commafy()
  74. * @dataProvider provideCommafyData
  75. */
  76. public function testCommafy( $number, $numbersWithCommas ) {
  77. $this->assertEquals(
  78. $numbersWithCommas,
  79. $this->getLang()->commafy( $number ),
  80. "commafy('$number')"
  81. );
  82. }
  83. public static function provideCommafyData() {
  84. // Note that commafy() always uses English separators (',' and '.') instead of
  85. // Polish (' ' and ','). There is another function that converts them later.
  86. return [
  87. [ 1000, '1000' ],
  88. [ 10000, '10,000' ],
  89. [ 1000.0001, '1000.0001' ],
  90. [ 10000.0001, '10,000.0001' ],
  91. [ -1000, '-1000' ],
  92. [ -10000, '-10,000' ],
  93. [ -1000.0001, '-1000.0001' ],
  94. [ -10000.0001, '-10,000.0001' ],
  95. ];
  96. }
  97. }