Blame view

vendor/aura/intl/tests/TranslatorLocatorTest.php 3.03 KB
c4650843   Etienne Pallier   Ajout du dossier ...
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Aura\Intl;

class TranslatorLocatorTest extends \PHPUnit_Framework_TestCase
{
    protected $factory;

    protected $translators;

    protected $packages;

    protected $formatters;

    protected function setUp()
    {
        $registry['Vendor.Package']['en_US'] = function () {
            return new \Aura\Intl\Package(
                'mock',
                null,
                [
                    'ERR_NO_SUCH_OPTION' => "The option {option} is not recognized.",
                ]
            );
        };

        $registry['Vendor.Package']['pt_BR'] = function () {
            return new \Aura\Intl\Package(
                'mock',
                null,
                [
                    'ERR_NO_SUCH_OPTION' => "O {option} opção não é reconhecido.",
                ]
            );
        };

        $this->packages = new PackageLocator($registry);

        $this->formatters = new FormatterLocator([
            'mock' => function () {
                return new MockFormatter;
            },
        ]);

        $this->factory = new TranslatorFactory;

        $this->translators = new TranslatorLocator(
            $this->packages,
            $this->formatters,
            $this->factory,
            'en_US'
        );
    }

    public function testSetAndGetLocale()
    {
        $expect = 'pt_BR';
        $this->translators->setLocale($expect);
        $actual = $this->translators->getLocale();
        $this->assertSame($expect, $actual);
    }

    public function testGetFactory()
    {
        $actual = $this->translators->getFactory();
        $this->assertSame($this->factory, $actual);
    }

    public function testGet()
    {
        $actual = $this->translators->get('Vendor.Package');
        $this->assertInstanceOf('Aura\Intl\Translator', $actual);
    }

    public function testGetPackages()
    {
        $actual = $this->translators->getPackages();
        $this->assertSame($this->packages, $actual);
    }

    public function testGetFormatterLocator()
    {
        $actual = $this->translators->getFormatters();
        $this->assertSame($this->formatters, $actual);
    }

    public function testIssue9()
    {
        $this->packages->set('Vendor.Package', 'en_UK', function () {
            $package = new Package('mock');
            $package->setMessages([
                'FOO' => 'The text for "foo."',
                'BAR' => 'The text for "bar."',
            ]);
            return $package;
        });

        $translator = $this->translators->get('Vendor.Package', 'en_UK');
        $expect = 'The text for "foo."';
        $this->assertSame($translator->translate('FOO'), $expect);
    }

    public function testIssue9Failure()
    {
        $package = new Package;
        $package->setMessages([
            'FOO' => 'The text for "foo."',
            'BAR' => 'The text for "bar."',
        ]);
        // $this->packages->set('Vendor.Package', 'en_UK', $package);
        // $this->setExpectedException('Exception');
        // $translator = $this->translators->get('Vendor.Package', 'en_UK');
    }
}