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
|
|
|
use function implode; |
10
|
|
|
use function chr; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Test for gettext parsing. |
14
|
|
|
*/ |
15
|
|
|
class PluralTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Test for npgettext. |
19
|
|
|
* |
20
|
|
|
* @param int $number Number |
21
|
|
|
* @param string $expected Expected output |
22
|
|
|
* |
23
|
|
|
* @dataProvider providerTestNpgettext |
24
|
|
|
*/ |
25
|
|
|
public function testNpgettext(int $number, string $expected): void |
26
|
|
|
{ |
27
|
|
|
$parser = new Translator(''); |
28
|
|
|
$result = $parser->npgettext( |
29
|
|
|
'context', |
30
|
|
|
"%d pig went to the market\n", |
31
|
|
|
"%d pigs went to the market\n", |
32
|
|
|
$number |
33
|
|
|
); |
34
|
|
|
$this->assertSame($expected, $result); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Data provider for test_npgettext. |
39
|
|
|
* |
40
|
|
|
* @return array[] |
41
|
|
|
*/ |
42
|
|
|
public static function providerTestNpgettext(): array |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
[ |
46
|
|
|
1, |
47
|
|
|
"%d pig went to the market\n", |
48
|
|
|
], |
49
|
|
|
[ |
50
|
|
|
2, |
51
|
|
|
"%d pigs went to the market\n", |
52
|
|
|
], |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Test for ngettext |
58
|
|
|
*/ |
59
|
|
|
public function testNgettext(): void |
60
|
|
|
{ |
61
|
|
|
$parser = new Translator(''); |
62
|
|
|
$translationKey = implode(chr(0), ["%d pig went to the market\n", "%d pigs went to the market\n"]); |
63
|
|
|
$parser->setTranslation($translationKey, ''); |
64
|
|
|
$result = $parser->ngettext( |
65
|
|
|
"%d pig went to the market\n", |
66
|
|
|
"%d pigs went to the market\n", |
67
|
|
|
1 |
68
|
|
|
); |
69
|
|
|
$this->assertSame('', $result); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|