@@ -196,6 +196,45 @@ public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales(
196
196
$ this ->assertEquals ('bar ' , $ translator ->trans ('bar ' ));
197
197
}
198
198
199
+ public function testGetCatalogueBehavesConsistently ()
200
+ {
201
+ /*
202
+ * Create a translator that loads two catalogues for two different locales.
203
+ * The catalogues contain distinct sets of messages.
204
+ */
205
+ $ translator = new Translator ('a ' , null , $ this ->tmpDir );
206
+ $ translator ->setFallbackLocales (array ('b ' ));
207
+
208
+ $ translator ->addLoader ('array ' , new ArrayLoader ());
209
+ $ translator ->addResource ('array ' , array ('foo ' => 'foo (a) ' ), 'a ' );
210
+ $ translator ->addResource ('array ' , array ('foo ' => 'foo (b) ' ), 'b ' );
211
+ $ translator ->addResource ('array ' , array ('bar ' => 'bar (b) ' ), 'b ' );
212
+
213
+ $ catalogue = $ translator ->getCatalogue ('a ' );
214
+ $ this ->assertFalse ($ catalogue ->defines ('bar ' )); // Sure, the "a" catalogue does not contain that message.
215
+
216
+ $ fallback = $ catalogue ->getFallbackCatalogue ();
217
+ $ this ->assertTrue ($ fallback ->defines ('foo ' )); // "foo" is present in "a" and "b"
218
+
219
+ /*
220
+ * Now, repeat the same test.
221
+ * Behind the scenes, the cache is used. But that should not matter, right?
222
+ */
223
+ $ translator = new Translator ('a ' , null , $ this ->tmpDir );
224
+ $ translator ->setFallbackLocales (array ('b ' ));
225
+
226
+ $ translator ->addLoader ('array ' , new ArrayLoader ());
227
+ $ translator ->addResource ('array ' , array ('foo ' => 'foo (a) ' ), 'a ' );
228
+ $ translator ->addResource ('array ' , array ('foo ' => 'foo (b) ' ), 'b ' );
229
+ $ translator ->addResource ('array ' , array ('bar ' => 'bar (b) ' ), 'b ' );
230
+
231
+ $ catalogue = $ translator ->getCatalogue ('a ' );
232
+ $ this ->assertFalse ($ catalogue ->defines ('bar ' ));
233
+
234
+ $ fallback = $ catalogue ->getFallbackCatalogue ();
235
+ $ this ->assertTrue ($ fallback ->defines ('foo ' ));
236
+ }
237
+
199
238
protected function getCatalogue ($ locale , $ messages )
200
239
{
201
240
$ catalogue = new MessageCatalogue ($ locale );
0 commit comments