1fa736e7e3df40d3eaba693f34aa5b03bb0a8ee3
[yaffs-website] / vendor / symfony / translation / Tests / Formatter / MessageFormatterTest.php
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\Formatter;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Translation\Formatter\MessageFormatter;
16
17 class MessageFormatterTest extends TestCase
18 {
19     /**
20      * @dataProvider getTransMessages
21      */
22     public function testFormat($expected, $message, $parameters = array())
23     {
24         $this->assertEquals($expected, $this->getMessageFormatter()->format($message, 'en', $parameters));
25     }
26
27     /**
28      * @dataProvider getTransChoiceMessages
29      */
30     public function testFormatPlural($expected, $message, $number, $parameters)
31     {
32         $this->assertEquals($expected, $this->getMessageFormatter()->choiceFormat($message, $number, 'fr', $parameters));
33     }
34
35     public function getTransMessages()
36     {
37         return array(
38             array(
39                 'There is one apple',
40                 'There is one apple',
41             ),
42             array(
43                 'There are 5 apples',
44                 'There are %count% apples',
45                 array('%count%' => 5),
46             ),
47             array(
48                 'There are 5 apples',
49                 'There are {{count}} apples',
50                 array('{{count}}' => 5),
51             ),
52         );
53     }
54
55     public function getTransChoiceMessages()
56     {
57         return array(
58             array('Il y a 0 pomme', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 0, array('%count%' => 0)),
59             array('Il y a 1 pomme', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 1, array('%count%' => 1)),
60             array('Il y a 10 pommes', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 10, array('%count%' => 10)),
61
62             array('Il y a 0 pomme', 'Il y a %count% pomme|Il y a %count% pommes', 0, array('%count%' => 0)),
63             array('Il y a 1 pomme', 'Il y a %count% pomme|Il y a %count% pommes', 1, array('%count%' => 1)),
64             array('Il y a 10 pommes', 'Il y a %count% pomme|Il y a %count% pommes', 10, array('%count%' => 10)),
65
66             array('Il y a 0 pomme', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 0, array('%count%' => 0)),
67             array('Il y a 1 pomme', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 1, array('%count%' => 1)),
68             array('Il y a 10 pommes', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 10, array('%count%' => 10)),
69
70             array('Il n\'y a aucune pomme', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 0, array('%count%' => 0)),
71             array('Il y a 1 pomme', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 1, array('%count%' => 1)),
72             array('Il y a 10 pommes', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 10, array('%count%' => 10)),
73
74             array('Il y a 0 pomme', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 0, array('%count%' => 0)),
75         );
76     }
77
78     private function getMessageFormatter()
79     {
80         return new MessageFormatter();
81     }
82 }