12
12
namespace Symfony \Bundle \FrameworkBundle \Tests \Translation ;
13
13
14
14
use Symfony \Bundle \FrameworkBundle \Translation \Translator ;
15
+ use Symfony \Component \Translation \Loader \ArrayLoader ;
15
16
use Symfony \Component \Translation \MessageCatalogue ;
16
17
use Symfony \Component \Filesystem \Filesystem ;
17
18
use Symfony \Component \Translation \MessageSelector ;
@@ -77,6 +78,8 @@ public function testTransWithCaching()
77
78
78
79
// do it another time as the cache is primed now
79
80
$ loader = $ this ->getMock ('Symfony\Component\Translation\Loader\LoaderInterface ' );
81
+ $ loader ->expects ($ this ->never ())->method ('load ' );
82
+
80
83
$ translator = $ this ->getTranslator ($ loader , array ('cache_dir ' => $ this ->tmpDir ));
81
84
$ translator ->setLocale ('fr ' );
82
85
$ translator ->setFallbackLocales (array ('en ' , 'es ' , 'pt-PT ' , 'pt_BR ' , 'fr.UTF-8 ' , 'sr@latin ' ));
@@ -90,6 +93,27 @@ public function testTransWithCaching()
90
93
$ this ->assertEquals ('other choice 1 (PT-BR) ' , $ translator ->transChoice ('other choice ' , 1 ));
91
94
$ this ->assertEquals ('foobarbaz (fr.UTF-8) ' , $ translator ->trans ('foobarbaz ' ));
92
95
$ this ->assertEquals ('foobarbax (sr@latin) ' , $ translator ->trans ('foobarbax ' ));
96
+
97
+ // refresh cache again when resource file resources file change
98
+ $ resource = $ this ->getMock ('Symfony\Component\Config\Resource\ResourceInterface ' );
99
+ $ resource
100
+ ->expects ($ this ->at (0 ))
101
+ ->method ('isFresh ' )
102
+ ->will ($ this ->returnValue (false ))
103
+ ;
104
+ $ catalogue = $ this ->getCatalogue ('fr ' , array ('foo ' => 'foo fresh ' ));
105
+ $ catalogue ->addResource ($ resource );
106
+
107
+ $ loader = $ this ->getMock ('Symfony\Component\Translation\Loader\LoaderInterface ' );
108
+ $ loader
109
+ ->expects ($ this ->at (0 ))
110
+ ->method ('load ' )
111
+ ->will ($ this ->returnValue ($ catalogue ))
112
+ ;
113
+
114
+ $ translator = $ this ->getTranslator ($ loader , array ('cache_dir ' => $ this ->tmpDir ));
115
+ $ translator ->setLocale ('fr ' );
116
+ $ this ->assertEquals ('foo fresh ' , $ translator ->trans ('foo ' ));
93
117
}
94
118
95
119
public function testTransWithCachingWithInvalidLocale ()
@@ -184,12 +208,7 @@ protected function getContainer($loader)
184
208
185
209
public function getTranslator ($ loader , $ options = array (), $ translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator ' )
186
210
{
187
- $ translator = new $ translatorClass (
188
- $ this ->getContainer ($ loader ),
189
- new MessageSelector (),
190
- array ('loader ' => array ('loader ' )),
191
- $ options
192
- );
211
+ $ translator = $ this ->createTranslator ($ loader , $ options , $ translatorClass );
193
212
194
213
$ translator ->addResource ('loader ' , 'foo ' , 'fr ' );
195
214
$ translator ->addResource ('loader ' , 'foo ' , 'en ' );
@@ -201,6 +220,18 @@ public function getTranslator($loader, $options = array(), $translatorClass = '\
201
220
202
221
return $ translator ;
203
222
}
223
+
224
+ private function createTranslator ($ loader , $ options , $ translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator ' )
225
+ {
226
+ $ translator = new $ translatorClass (
227
+ $ this ->getContainer ($ loader ),
228
+ new MessageSelector (),
229
+ array ('loader ' => array ('loader ' )),
230
+ $ options
231
+ );
232
+
233
+ return $ translator ;
234
+ }
204
235
}
205
236
206
237
class TranslatorWithInvalidLocale extends Translator
0 commit comments