~ubuntu-branches/ubuntu/wily/symfony/wily

« back to all changes in this revision

Viewing changes to src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php

  • Committer: Package Import Robot
  • Author(s): David Prévot, Fabien Potencier
  • Date: 2015-06-14 17:15:34 UTC
  • mfrom: (1.3.3)
  • Revision ID: package-import@ubuntu.com-20150614171534-h74z7c7x7hdhz3ra
Tags: 2.7.1+dfsg-1
[ Fabien Potencier ]
updated VERSION for 2.7.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
        $this->assertEquals('OK', $translator->trans($msgid), '-> caching does not work in '.($debug ? 'debug' : 'production'));
75
75
    }
76
76
 
77
 
    public function testRefreshCacheWhenResourcesChange()
78
 
    {
79
 
        // prime the cache
80
 
        $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
81
 
        $loader
82
 
            ->method('load')
83
 
            ->will($this->returnValue($this->getCatalogue('fr', array(
84
 
                'foo' => 'foo A',
85
 
            ))))
86
 
        ;
87
 
 
88
 
        $translator = new Translator('fr', null, $this->tmpDir, true);
89
 
        $translator->setLocale('fr');
90
 
        $translator->addLoader('loader', $loader);
91
 
        $translator->addResource('loader', 'foo', 'fr');
92
 
 
93
 
        $this->assertEquals('foo A', $translator->trans('foo'));
94
 
 
95
 
        // add a new resource to refresh the cache
96
 
        $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
97
 
        $loader
98
 
            ->method('load')
99
 
            ->will($this->returnValue($this->getCatalogue('fr', array(
100
 
                'foo' => 'foo B',
101
 
            ))))
102
 
        ;
103
 
 
104
 
        $translator = new Translator('fr', null, $this->tmpDir, true);
105
 
        $translator->setLocale('fr');
106
 
        $translator->addLoader('loader', $loader);
107
 
        $translator->addResource('loader', 'bar', 'fr');
108
 
 
109
 
        $this->assertEquals('foo B', $translator->trans('foo'));
110
 
    }
111
 
 
112
77
    public function testCatalogueIsReloadedWhenResourcesAreNoLongerFresh()
113
78
    {
114
79
        /*
153
118
    /**
154
119
     * @dataProvider runForDebugAndProduction
155
120
     */
156
 
    public function testDifferentTranslatorsForSameLocaleDoNotInterfere($debug)
157
 
    {
158
 
        $locale = 'any_locale';
159
 
        $format = 'some_format';
160
 
        $msgid = 'test';
161
 
 
162
 
        // Create a Translator and prime its cache
163
 
        $translator = new Translator($locale, null, $this->tmpDir, $debug);
164
 
        $translator->addLoader($format, new ArrayLoader());
165
 
        $translator->addResource($format, array($msgid => 'FAIL'), $locale);
166
 
        $translator->trans($msgid);
167
 
 
168
 
        /*
169
 
         * Create another Translator with the same locale but a different resource.
170
 
         * It should not use the first translator's cache but return the value from its own resource.
171
 
         */
172
 
        $translator = new Translator($locale, null, $this->tmpDir, $debug);
173
 
        $translator->addLoader($format, new ArrayLoader());
174
 
        $translator->addResource($format, array($msgid => 'OK'), $locale);
175
 
 
176
 
        $this->assertEquals('OK', $translator->trans($msgid), '-> different translators for the same domain interfere in '.($debug ? 'debug' : 'production'));
177
 
    }
178
 
 
179
 
    /**
180
 
     * @dataProvider runForDebugAndProduction
181
 
     */
182
121
    public function testDifferentTranslatorsForSameLocaleDoNotOverwriteEachOthersCache($debug)
183
122
    {
184
123
        /*