c382244f92b84f6a920159dd75665c282b85915d
[lhc/web/wiklou.git] / tests / phpunit / languages / LanguageHeTest.php
1 <?php
2 /**
3 * @author Amir E. Aharoni
4 * @copyright Copyright © 2012, Amir E. Aharoni
5 * @file
6 */
7
8 /** Tests for MediaWiki languages/classes/LanguageHe.php */
9 class LanguageHeTest extends LanguageClassesTestCase {
10 /**
11 * The most common usage for the plural forms is two forms,
12 * for singular and plural. In this case, the second form
13 * is technically dual, but in practice it's used as plural.
14 * In some cases, usually with expressions of time, three forms
15 * are needed - singular, dual and plural.
16 * CLDR also specifies a fourth form for multiples of 10,
17 * which is very rare. It also has a mistake, because
18 * the number 10 itself is supposed to be just plural,
19 * so currently it's overridden in MediaWiki.
20 */
21
22 // @todo the below test*PluralForms test methods can be refactored
23 // to use a single test method and data provider..
24
25 /**
26 * @dataProvider provideTwoPluralForms
27 * @covers Language::convertPlural
28 */
29 public function testTwoPluralForms( $result, $value ) {
30 $forms = array( 'one', 'other' );
31 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
32 }
33
34 /**
35 * @dataProvider provideThreePluralForms
36 * @covers Language::convertPlural
37 */
38 public function testThreePluralForms( $result, $value ) {
39 $forms = array( 'one', 'two', 'other' );
40 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
41 }
42
43 /**
44 * @dataProvider provideFourPluralForms
45 * @covers Language::convertPlural
46 */
47 public function testFourPluralForms( $result, $value ) {
48 $forms = array( 'one', 'two', 'many', 'other' );
49 $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
50 }
51
52 /**
53 * @dataProvider provideFourPluralForms
54 * @covers Language::convertPlural
55 */
56 public function testGetPluralRuleType( $result, $value ) {
57 $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
58 }
59
60 public static function provideTwoPluralForms() {
61 return array(
62 array( 'other', 0 ), // Zero - plural
63 array( 'one', 1 ), // Singular
64 array( 'other', 2 ), // No third form provided, use it as plural
65 array( 'other', 3 ), // Plural - other
66 array( 'other', 10 ), // No fourth form provided, use it as plural
67 array( 'other', 20 ), // No fourth form provided, use it as plural
68 );
69 }
70
71 public static function provideThreePluralForms() {
72 return array(
73 array( 'other', 0 ), // Zero - plural
74 array( 'one', 1 ), // Singular
75 array( 'two', 2 ), // Dual
76 array( 'other', 3 ), // Plural - other
77 array( 'other', 10 ), // No fourth form provided, use it as plural
78 array( 'other', 20 ), // No fourth form provided, use it as plural
79 );
80 }
81
82 public static function provideFourPluralForms() {
83 return array(
84 array( 'other', 0 ), // Zero - plural
85 array( 'one', 1 ), // Singular
86 array( 'two', 2 ), // Dual
87 array( 'other', 3 ), // Plural - other
88 array( 'other', 10 ), // 10 is supposed to be plural (other), not "many"
89 array( 'many', 20 ), // Fourth form provided - rare, but supported by CLDR
90 );
91 }
92
93 /**
94 * @dataProvider provideGrammar
95 * @covers Language::convertGrammar
96 */
97 public function testGrammar( $result, $word, $case ) {
98 $this->assertEquals( $result, $this->getLang()->convertGrammar( $word, $case ) );
99 }
100
101 // The comments in the beginning of the line help avoid RTL problems
102 // with text editors.
103 public static function provideGrammar() {
104 return array(
105 array(
106 /* result */'וויקיפדיה',
107 /* word */'ויקיפדיה',
108 /* case */'תחילית',
109 ),
110 array(
111 /* result */'וולפגנג',
112 /* word */'וולפגנג',
113 /* case */'prefixed',
114 ),
115 array(
116 /* result */'קובץ',
117 /* word */'הקובץ',
118 /* case */'תחילית',
119 ),
120 array(
121 /* result */'־Wikipedia',
122 /* word */'Wikipedia',
123 /* case */'תחילית',
124 ),
125 array(
126 /* result */'־1995',
127 /* word */'1995',
128 /* case */'תחילית',
129 ),
130 );
131 }
132 }