-
Notifications
You must be signed in to change notification settings - Fork 0
/
Translator_CasePluralInterval_Test.php
executable file
·89 lines (69 loc) · 2.43 KB
/
Translator_CasePluralInterval_Test.php
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
<?php
namespace I18Next\Tests;
use I18Next\Exception\TranslationSyntaxError;
use I18Next\Translator;
class Translator_CasePluralInterval_Test extends TranslatorBaseCase
{
/**
* Testing this :
* "key4_interval": "(1){one item};(2-7){a few items};(7-inf){a lot of items};".
*
* "key4_interval": "(1){one item};(2-7){a few items};(7-inf){a lot of items};"
*/
public function testNoCount()
{
$this->setupTranslatorLanguages('en');
$result = $this->translator->_('key4');
$this->assertEquals('one item', $result);
}
public function testCount0()
{
$this->setupTranslatorLanguages('en');
$result = $this->translator->_('key4', ['count' => 0]);
$this->assertEquals('key4', $result);
}
public function testCount1()
{
$this->setupTranslatorLanguages('en');
$result = $this->translator->_('key4', ['count' => 1]);
$this->assertEquals('one item', $result);
}
public function testCount3()
{
$this->setupTranslatorLanguages('en');
$result = $this->translator->_('key4', ['count' => 3]);
$this->assertEquals('a few items', $result);
}
public function testCount8()
{
$this->setupTranslatorLanguages('en');
$result = $this->translator->_('key4', ['count' => 8]);
$this->assertEquals('a lot of items', $result);
}
public function testException1()
{
$this->expectException(TranslationSyntaxError::class);
$path = '/tmp/locale_exception';
@mkdir($path.'/en', 0777, true);
file_put_contents(
$path.'/en/exception.json',
json_encode(['key4_interval' => '(1){one item};2-7){a few items};(7-inf){a lot of items};'])
);
$this->translator = new Translator();
$this->translator->setTranslationsPath($path);
$this->translator->setLanguagePrimary('en');
}
public function testException2()
{
$this->expectException(TranslationSyntaxError::class);
$path = '/tmp/locale_exception';
@mkdir($path.'/en', 0777, true);
file_put_contents(
$path.'/en/exception.json',
json_encode(['key4_interval' => '(1){one item};(2-7){a few items};(7-inf){a lot of items}'])
);
$this->translator = new Translator();
$this->translator->setTranslationsPath($path);
$this->translator->setLanguagePrimary('en');
}
}