4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Tests
;
14 use Symfony\Component\Translation\MessageSelector
;
16 class MessageSelectorTest
extends \PHPUnit_Framework_TestCase
19 * @dataProvider getChooseTests
21 public function testChoose($expected, $id, $number)
23 $selector = new MessageSelector();
25 $this->assertEquals($expected, $selector->choose($id, $number, 'en'));
29 * @expectedException InvalidArgumentException
31 public function testChooseWhenNoEnoughChoices()
33 $selector = new MessageSelector();
35 $selector->choose('foo', 10, 'en');
38 public function getChooseTests()
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),
45 array('There is one apple', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 1),
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),
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),
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),
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),
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),
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),
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),