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
|
<?php
class RubyYamlFFSTest extends MediaWikiTestCase {
/** @var MessageGroup */
protected $group;
/** @var FFS */
protected $ffs;
protected $groupConfiguration = array(
'BASIC' => array(
'class' => 'FileBasedMessageGroup',
'id' => 'test-id',
'label' => 'Test Label',
'namespace' => 'NS_MEDIAWIKI',
'description' => 'Test description',
),
'FILES' => array(
'class' => 'RubyYamlFFS',
),
);
protected function setUp() {
parent::setUp();
$group = MessageGroupBase::factory( $this->groupConfiguration );
/** @var YamlFFS $ffs */
$this->ffs = $group->getFFS();
}
public function testFlattenPluralWithNoPlurals() {
$input = array(
'much' => 'a lot',
'less' => 'not so much',
);
$output = false;
$this->assertEquals( $output, $this->ffs->flattenPlural( $input ) );
}
public function testFlattenPluralWithPlurals() {
$input = array(
'one' => 'just a tiny bit',
'two' => 'not so much',
'other' => 'maybe a lot',
);
$output = '{{PLURAL|one=just a tiny bit|two=not so much|maybe a lot}}';
$this->assertEquals( $output, $this->ffs->flattenPlural( $input ) );
}
public function testFlattenPluralWithArrays() {
$input = array(
'one' => array(
'multi' => 'he lives in a multistorey house',
'row' => 'he lives in a row house',
),
'other' => array(
'multi' => 'he lives in mountain cave',
'row' => 'he lives in a cave near the river',
),
);
$output = false;
$this->assertEquals( $output, $this->ffs->flattenPlural( $input ) );
}
/**
* @expectedException MWException
* @expectedExceptionMessage Reserved plural keywords mixed with other keys
* @dataProvider flattenPluralsWithMixedKeywordsProvider
*/
public function testFlattenPluralsWithMixedKeywords( $input, $comment ) {
$this->ffs->flattenPlural( $input );
}
public function flattenPluralsWithMixedKeywordsProvider() {
return array(
array(
array(
'carrot' => 'I like carrots',
'other' => 'I like milk',
),
'reserved keyword at the end',
),
array(
array(
'one' => 'I am the one leader',
'club' => 'I am the club leader',
),
'reserved keyword at the beginning',
)
);
}
/**
* @dataProvider unflattenDataProvider
*/
public function testUnflattenPural( $key, $value, $result ) {
$this->assertEquals(
$result,
$this->ffs->unflattenPlural( $key, $value )
);
}
public function unflattenDataProvider() {
return array(
array( 'key', '{{PLURAL}}', false ),
array( 'key', 'value', array( 'key' => 'value' ) ),
array( 'key', '{{PLURAL|one=cat|other=cats}}',
array( 'key.one' => 'cat', 'key.other' => 'cats' )
),
array( 'key', '{{PLURAL|one=шляху %{related_ways}|шляхоў %{related_ways}}}',
array(
'key.one' => 'шляху %{related_ways}',
'key.other' => 'шляхоў %{related_ways}'
)
),
array( 'key', '{{PLURAL|foo=cat}}',
array( 'key.other' => 'foo=cat' )
),
array( 'key', '{{PLURAL|zero=0|one=1|two=2|few=3|many=160|other=898}}',
array( 'key.zero' => '0', 'key.one' => '1', 'key.two' => '2',
'key.few' => '3', 'key.many' => '160', 'key.other' => '898' )
),
);
}
}
|