]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
1 | <?php |
2 | ||
3 | /* | |
4 | * This file is part of the Symfony package. | |
5 | * | |
6 | * (c) Fabien Potencier <fabien@symfony.com> | |
7 | * | |
8 | * For the full copyright and license information, please view the LICENSE | |
9 | * file that was distributed with this source code. | |
10 | */ | |
11 | ||
12 | namespace Symfony\Component\Translation\Tests; | |
13 | ||
14 | use Symfony\Component\Translation\MessageSelector; | |
15 | ||
16 | class MessageSelectorTest extends \PHPUnit_Framework_TestCase | |
17 | { | |
18 | /** | |
19 | * @dataProvider getChooseTests | |
20 | */ | |
21 | public function testChoose($expected, $id, $number) | |
22 | { | |
23 | $selector = new MessageSelector(); | |
24 | ||
25 | $this->assertEquals($expected, $selector->choose($id, $number, 'en')); | |
26 | } | |
27 | ||
28 | /** | |
29 | * @expectedException InvalidArgumentException | |
30 | */ | |
31 | public function testChooseWhenNoEnoughChoices() | |
32 | { | |
33 | $selector = new MessageSelector(); | |
34 | ||
35 | $selector->choose('foo', 10, 'en'); | |
36 | } | |
37 | ||
38 | public function getChooseTests() | |
39 | { | |
40 | return array( | |
41 | array('There is no apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0), | |
42 | array('There is no apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0), | |
43 | array('There is no apples', '{0}There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0), | |
44 | ||
45 | array('There is one apple', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 1), | |
46 | ||
47 | array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 10), | |
48 | array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf]There is %count% apples', 10), | |
49 | array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 10), | |
50 | ||
51 | array('There is %count% apples', 'There is one apple|There is %count% apples', 0), | |
52 | array('There is one apple', 'There is one apple|There is %count% apples', 1), | |
53 | array('There is %count% apples', 'There is one apple|There is %count% apples', 10), | |
54 | ||
55 | array('There is %count% apples', 'one: There is one apple|more: There is %count% apples', 0), | |
56 | array('There is one apple', 'one: There is one apple|more: There is %count% apples', 1), | |
57 | array('There is %count% apples', 'one: There is one apple|more: There is %count% apples', 10), | |
58 | ||
59 | array('There is no apples', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 0), | |
60 | array('There is one apple', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 1), | |
61 | array('There is %count% apples', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 10), | |
62 | ||
63 | array('', '{0}|{1} There is one apple|]1,Inf] There is %count% apples', 0), | |
64 | array('', '{0} There is no apples|{1}|]1,Inf] There is %count% apples', 1), | |
65 | ||
66 | // Indexed only tests which are Gettext PoFile* compatible strings. | |
67 | array('There are %count% apples', 'There is one apple|There are %count% apples', 0), | |
68 | array('There is one apple', 'There is one apple|There are %count% apples', 1), | |
69 | array('There are %count% apples', 'There is one apple|There are %count% apples', 2), | |
70 | ||
71 | // Tests for float numbers | |
72 | array('There is almost one apple', '{0} There is no apples|]0,1[ There is almost one apple|{1} There is one apple|[1,Inf] There is more than one apple', 0.7), | |
73 | array('There is one apple', '{0} There is no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1), | |
74 | array('There is more than one apple', '{0} There is no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1.7), | |
75 | array('There is no apples', '{0} There is no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0), | |
76 | array('There is no apples', '{0} There is no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0.0), | |
77 | array('There is no apples', '{0.0} There is no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0), | |
78 | ); | |
79 | } | |
80 | } |