summaryrefslogtreecommitdiff
path: root/tests/phpunit/languages/LanguageArTest.php
blob: b23e0534109828d84886147142a1c4fff8e6c4e6 (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
<?php
/**
 * Based on LanguagMlTest
 * @file
 */

/** Tests for MediaWiki languages/LanguageAr.php */
class LanguageArTest extends MediaWikiTestCase {
	private $lang;

	function setUp() {
		$this->lang = Language::factory( 'Ar' );
	}
	function tearDown() {
		unset( $this->lang );
	}

	function testFormatNum() {
		$this->assertEquals( '١٬٢٣٤٬٥٦٧', $this->lang->formatNum( '1234567' ) );
		$this->assertEquals( '-١٢٫٨٩', $this->lang->formatNum( -12.89 ) );
	}

	/**
	 * Mostly to test the raw ascii feature.
	 * @dataProvider providerSprintfDate
	 */
	function testSprintfDate( $format, $date, $expected ) {
		$this->assertEquals( $expected, $this->lang->sprintfDate( $format, $date ) );
	}

	function providerSprintfDate() {
		return array(
			array(
				'xg "vs" g',
				'20120102030410',
				'يناير vs ٣'
			),
			array(
				'xmY',
				'20120102030410',
				'١٤٣٣'
			),
			array(
				'xnxmY',
				'20120102030410',
				'1433'
			),
			array(
				'xN xmj xmn xN xmY',
				'20120102030410',
				' 7 2  ١٤٣٣'
			),
		);
	}
	/** @dataProvider providePlural */
	function testPlural( $result, $value ) {
		$forms =  array( 'zero', 'one', 'two', 'few', 'many', 'other' );
		$this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
	}
	function providePlural() {
		return array (
			array( 'zero', 0 ),
			array( 'one', 1 ),
			array( 'two', 2 ),
			array( 'few', 3 ),
			array( 'few', 9 ),
			array( 'few', 110 ),
			array( 'many', 11 ),
			array( 'many', 15 ),
			array( 'many', 99 ),
			array( 'many', 9999 ),
			array( 'other', 100 ),
			array( 'other', 102 ),
			array( 'other', 1000 ),
			array( 'other', 1.7 ),
		);
	}
}