LanguageArTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @covers LanguageAr
  4. */
  5. class LanguageArTest extends LanguageClassesTestCase {
  6. /**
  7. * @covers Language::formatNum
  8. * @dataProvider provideFormatNum
  9. */
  10. public function testFormatNum( $num, $formatted ) {
  11. $this->assertEquals( $formatted, $this->getLang()->formatNum( $num ) );
  12. }
  13. public static function provideFormatNum() {
  14. return [
  15. [ '1234567', '١٬٢٣٤٬٥٦٧' ],
  16. [ -12.89, '-١٢٫٨٩' ],
  17. ];
  18. }
  19. /**
  20. * @covers LanguageAr::normalize
  21. * @covers Language::normalize
  22. * @dataProvider provideNormalize
  23. */
  24. public function testNormalize( $input, $expected ) {
  25. if ( $input === $expected ) {
  26. throw new Exception( 'Expected output must differ.' );
  27. }
  28. $this->setMwGlobals( 'wgFixArabicUnicode', true );
  29. $this->assertSame( $expected, $this->getLang()->normalize( $input ), 'ar-normalised form' );
  30. $this->setMwGlobals( 'wgFixArabicUnicode', false );
  31. $this->assertSame( $input, $this->getLang()->normalize( $input ), 'regular normalised form' );
  32. }
  33. public static function provideNormalize() {
  34. return [
  35. [
  36. 'ﷅ',
  37. 'صمم',
  38. ],
  39. ];
  40. }
  41. /**
  42. * Mostly to test the raw ascii feature.
  43. * @dataProvider provideSprintfDate
  44. * @covers Language::sprintfDate
  45. */
  46. public function testSprintfDate( $format, $date, $expected ) {
  47. $this->assertEquals( $expected, $this->getLang()->sprintfDate( $format, $date ) );
  48. }
  49. public static function provideSprintfDate() {
  50. return [
  51. [
  52. 'xg "vs" g',
  53. '20120102030410',
  54. 'يناير vs ٣'
  55. ],
  56. [
  57. 'xmY',
  58. '20120102030410',
  59. '١٤٣٣'
  60. ],
  61. [
  62. 'xnxmY',
  63. '20120102030410',
  64. '1433'
  65. ],
  66. [
  67. 'xN xmj xmn xN xmY',
  68. '20120102030410',
  69. ' 7 2 ١٤٣٣'
  70. ],
  71. ];
  72. }
  73. /**
  74. * @dataProvider providePlural
  75. * @covers Language::convertPlural
  76. */
  77. public function testPlural( $result, $value ) {
  78. $forms = [ 'zero', 'one', 'two', 'few', 'many', 'other' ];
  79. $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
  80. }
  81. /**
  82. * @dataProvider providePlural
  83. * @covers Language::getPluralRuleType
  84. */
  85. public function testGetPluralRuleType( $result, $value ) {
  86. $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
  87. }
  88. public static function providePlural() {
  89. return [
  90. [ 'zero', 0 ],
  91. [ 'one', 1 ],
  92. [ 'two', 2 ],
  93. [ 'few', 3 ],
  94. [ 'few', 9 ],
  95. [ 'few', 110 ],
  96. [ 'many', 11 ],
  97. [ 'many', 15 ],
  98. [ 'many', 99 ],
  99. [ 'many', 9999 ],
  100. [ 'other', 100 ],
  101. [ 'other', 102 ],
  102. [ 'other', 1000 ],
  103. [ 'other', 1.7 ],
  104. ];
  105. }
  106. }