1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\MoTranslator\Tests; |
6
|
|
|
|
7
|
|
|
use PhpMyAdmin\MoTranslator\Translator; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Test for gettext parsing. |
12
|
|
|
*/ |
13
|
|
|
class PluralFormulaTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Test for extractPluralsForms. |
17
|
|
|
* |
18
|
|
|
* @dataProvider pluralExtractionData |
19
|
|
|
*/ |
20
|
|
|
public function testExtractPluralsForms(string $header, string $expected): void |
21
|
|
|
{ |
22
|
|
|
self::assertSame( |
23
|
|
|
$expected, |
24
|
|
|
Translator::extractPluralsForms($header), |
25
|
|
|
); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** @return list<array{string, string}> */ |
|
|
|
|
29
|
|
|
public static function pluralExtractionData(): array |
30
|
|
|
{ |
31
|
|
|
return [ |
|
|
|
|
32
|
|
|
// It defaults to a "Western-style" plural header. |
33
|
|
|
[ |
34
|
|
|
'', |
35
|
|
|
'nplurals=2; plural=n == 1 ? 0 : 1;', |
36
|
|
|
], |
37
|
|
|
// Extracting it from the middle of the header works. |
38
|
|
|
[ |
39
|
|
|
"Content-type: text/html; charset=UTF-8\n" |
40
|
|
|
. "Plural-Forms: nplurals=1; plural=0;\n" |
41
|
|
|
. "Last-Translator: nobody\n", |
42
|
|
|
' nplurals=1; plural=0;', |
43
|
|
|
], |
44
|
|
|
// It's also case-insensitive. |
45
|
|
|
[ |
46
|
|
|
"PLURAL-forms: nplurals=1; plural=0;\n", |
47
|
|
|
' nplurals=1; plural=0;', |
48
|
|
|
], |
49
|
|
|
// It falls back to default if it's not on a separate line. |
50
|
|
|
[ |
51
|
|
|
'Content-type: text/html; charset=UTF-8' // note the missing \n here |
52
|
|
|
. "Plural-Forms: nplurals=1; plural=0;\n" |
53
|
|
|
. "Last-Translator: nobody\n", |
54
|
|
|
'nplurals=2; plural=n == 1 ? 0 : 1;', |
55
|
|
|
], |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** @dataProvider pluralCounts */ |
60
|
|
|
public function testPluralCounts(string $expr, int $expected): void |
61
|
|
|
{ |
62
|
|
|
self::assertSame( |
63
|
|
|
$expected, |
64
|
|
|
Translator::extractPluralCount($expr), |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** @return list<array{string, int}> */ |
69
|
|
|
public static function pluralCounts(): array |
70
|
|
|
{ |
71
|
|
|
return [ |
|
|
|
|
72
|
|
|
[ |
73
|
|
|
'', |
74
|
|
|
1, |
75
|
|
|
], |
76
|
|
|
[ |
77
|
|
|
'foo=2; expr', |
78
|
|
|
1, |
79
|
|
|
], |
80
|
|
|
[ |
81
|
|
|
'nplurals=2; epxr', |
82
|
|
|
2, |
83
|
|
|
], |
84
|
|
|
[ |
85
|
|
|
' nplurals = 3 ; epxr', |
86
|
|
|
3, |
87
|
|
|
], |
88
|
|
|
[ |
89
|
|
|
' nplurals = 4 ; epxr ; ', |
90
|
|
|
4, |
91
|
|
|
], |
92
|
|
|
[ |
93
|
|
|
'nplurals', |
94
|
|
|
1, |
95
|
|
|
], |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** @dataProvider pluralExpressions */ |
100
|
|
|
public function testPluralExpression(string $expr, string $expected): void |
101
|
|
|
{ |
102
|
|
|
self::assertSame( |
103
|
|
|
$expected, |
104
|
|
|
Translator::sanitizePluralExpression($expr), |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** @return list<array{string, string}> */ |
109
|
|
|
public static function pluralExpressions(): array |
110
|
|
|
{ |
111
|
|
|
return [ |
|
|
|
|
112
|
|
|
[ |
113
|
|
|
'', |
114
|
|
|
'', |
115
|
|
|
], |
116
|
|
|
[ |
117
|
|
|
'nplurals=2; plural=n == 1 ? 0 : 1;', |
118
|
|
|
'n == 1 ? 0 : 1', |
119
|
|
|
], |
120
|
|
|
[ |
121
|
|
|
' nplurals=1; plural=0;', |
122
|
|
|
'0', |
123
|
|
|
], |
124
|
|
|
[ |
125
|
|
|
"nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5;\n", |
126
|
|
|
'n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5', |
127
|
|
|
], |
128
|
|
|
[ |
129
|
|
|
' nplurals=1; plural=baz(n);', |
130
|
|
|
'(n)', |
131
|
|
|
], |
132
|
|
|
[ |
133
|
|
|
' plural=n', |
134
|
|
|
'n', |
135
|
|
|
], |
136
|
|
|
[ |
137
|
|
|
'nplurals', |
138
|
|
|
'n', |
139
|
|
|
], |
140
|
|
|
]; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths