1b417379c87ae0b53513f86255a4e29f7707778e
[yaffs-website] / vendor / symfony / translation / Tests / DataCollectorTranslatorTest.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;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Translation\Translator;
16 use Symfony\Component\Translation\DataCollectorTranslator;
17 use Symfony\Component\Translation\Loader\ArrayLoader;
18
19 class DataCollectorTranslatorTest extends TestCase
20 {
21     public function testCollectMessages()
22     {
23         $collector = $this->createCollector();
24         $collector->setFallbackLocales(array('fr', 'ru'));
25
26         $collector->trans('foo');
27         $collector->trans('bar');
28         $collector->transChoice('choice', 0);
29         $collector->trans('bar_ru');
30         $collector->trans('bar_ru', array('foo' => 'bar'));
31
32         $expectedMessages = array();
33         $expectedMessages[] = array(
34               'id' => 'foo',
35               'translation' => 'foo (en)',
36               'locale' => 'en',
37               'domain' => 'messages',
38               'state' => DataCollectorTranslator::MESSAGE_DEFINED,
39               'parameters' => array(),
40               'transChoiceNumber' => null,
41         );
42         $expectedMessages[] = array(
43               'id' => 'bar',
44               'translation' => 'bar (fr)',
45               'locale' => 'fr',
46               'domain' => 'messages',
47               'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
48               'parameters' => array(),
49               'transChoiceNumber' => null,
50         );
51         $expectedMessages[] = array(
52               'id' => 'choice',
53               'translation' => 'choice',
54               'locale' => 'en',
55               'domain' => 'messages',
56               'state' => DataCollectorTranslator::MESSAGE_MISSING,
57               'parameters' => array(),
58               'transChoiceNumber' => 0,
59         );
60         $expectedMessages[] = array(
61               'id' => 'bar_ru',
62               'translation' => 'bar (ru)',
63               'locale' => 'ru',
64               'domain' => 'messages',
65               'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
66               'parameters' => array(),
67               'transChoiceNumber' => null,
68         );
69         $expectedMessages[] = array(
70               'id' => 'bar_ru',
71               'translation' => 'bar (ru)',
72               'locale' => 'ru',
73               'domain' => 'messages',
74               'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
75               'parameters' => array('foo' => 'bar'),
76               'transChoiceNumber' => null,
77         );
78
79         $this->assertEquals($expectedMessages, $collector->getCollectedMessages());
80     }
81
82     private function createCollector()
83     {
84         $translator = new Translator('en');
85         $translator->addLoader('array', new ArrayLoader());
86         $translator->addResource('array', array('foo' => 'foo (en)'), 'en');
87         $translator->addResource('array', array('bar' => 'bar (fr)'), 'fr');
88         $translator->addResource('array', array('bar_ru' => 'bar (ru)'), 'ru');
89
90         return new DataCollectorTranslator($translator);
91     }
92 }