summaryrefslogtreecommitdiff
path: root/tests/phpunit/languages/LanguageHeTest.php
blob: c382244f92b84f6a920159dd75665c282b85915d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
 * @author Amir E. Aharoni
 * @copyright Copyright © 2012, Amir E. Aharoni
 * @file
 */

/** Tests for MediaWiki languages/classes/LanguageHe.php */
class LanguageHeTest extends LanguageClassesTestCase {
	/**
	 * The most common usage for the plural forms is two forms,
	 * for singular and plural. In this case, the second form
	 * is technically dual, but in practice it's used as plural.
	 * In some cases, usually with expressions of time, three forms
	 * are needed - singular, dual and plural.
	 * CLDR also specifies a fourth form for multiples of 10,
	 * which is very rare. It also has a mistake, because
	 * the number 10 itself is supposed to be just plural,
	 * so currently it's overridden in MediaWiki.
	 */

	// @todo the below test*PluralForms test methods can be refactored
	//  to use a single test method and data provider..

	/**
	 * @dataProvider provideTwoPluralForms
	 * @covers Language::convertPlural
	 */
	public function testTwoPluralForms( $result, $value ) {
		$forms = array( 'one', 'other' );
		$this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
	}

	/**
	 * @dataProvider provideThreePluralForms
	 * @covers Language::convertPlural
	 */
	public function testThreePluralForms( $result, $value ) {
		$forms = array( 'one', 'two', 'other' );
		$this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
	}

	/**
	 * @dataProvider provideFourPluralForms
	 * @covers Language::convertPlural
	 */
	public function testFourPluralForms( $result, $value ) {
		$forms = array( 'one', 'two', 'many', 'other' );
		$this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
	}

	/**
	 * @dataProvider provideFourPluralForms
	 * @covers Language::convertPlural
	 */
	public function testGetPluralRuleType( $result, $value ) {
		$this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
	}

	public static function provideTwoPluralForms() {
		return array(
			array( 'other', 0 ), // Zero - plural
			array( 'one', 1 ), // Singular
			array( 'other', 2 ), // No third form provided, use it as plural
			array( 'other', 3 ), // Plural - other
			array( 'other', 10 ), // No fourth form provided, use it as plural
			array( 'other', 20 ), // No fourth form provided, use it as plural
		);
	}

	public static function provideThreePluralForms() {
		return array(
			array( 'other', 0 ), // Zero - plural
			array( 'one', 1 ), // Singular
			array( 'two', 2 ), // Dual
			array( 'other', 3 ), // Plural - other
			array( 'other', 10 ), // No fourth form provided, use it as plural
			array( 'other', 20 ), // No fourth form provided, use it as plural
		);
	}

	public static function provideFourPluralForms() {
		return array(
			array( 'other', 0 ), // Zero - plural
			array( 'one', 1 ), // Singular
			array( 'two', 2 ), // Dual
			array( 'other', 3 ), // Plural - other
			array( 'other', 10 ), // 10 is supposed to be plural (other), not "many"
			array( 'many', 20 ), // Fourth form provided - rare, but supported by CLDR
		);
	}

	/**
	 * @dataProvider provideGrammar
	 * @covers Language::convertGrammar
	 */
	public function testGrammar( $result, $word, $case ) {
		$this->assertEquals( $result, $this->getLang()->convertGrammar( $word, $case ) );
	}

	// The comments in the beginning of the line help avoid RTL problems
	// with text editors.
	public static function provideGrammar() {
		return array(
			array(
				/* result */'וויקיפדיה',
				/* word   */'ויקיפדיה',
				/* case   */'תחילית',
			),
			array(
				/* result */'וולפגנג',
				/* word   */'וולפגנג',
				/* case   */'prefixed',
			),
			array(
				/* result */'קובץ',
				/* word   */'הקובץ',
				/* case   */'תחילית',
			),
			array(
				/* result */'־Wikipedia',
				/* word   */'Wikipedia',
				/* case   */'תחילית',
			),
			array(
				/* result */'־1995',
				/* word   */'1995',
				/* case   */'תחילית',
			),
		);
	}
}