@@ -140,9 +140,9 @@ public function testDumpWithRouteNotFoundLocalizedRoutes()
140140
141141 public function testDumpWithFallbackLocaleLocalizedRoutes ()
142142 {
143- $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_canonical_route ' , 'test ' ));
144- $ this ->routeCollection ->add ('test.nl ' , (new Route ('/testen/is/leuk ' ))->setDefault ('_canonical_route ' , 'test ' ));
145- $ this ->routeCollection ->add ('test.fr ' , (new Route ('/tester/est/amusant ' ))->setDefault ('_canonical_route ' , 'test ' ));
143+ $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , ' en ' )-> setDefault ( ' _canonical_route ' , 'test ' ));
144+ $ this ->routeCollection ->add ('test.nl ' , (new Route ('/testen/is/leuk ' ))->setDefault ('_locale ' , ' nl ' )-> setDefault ( ' _canonical_route ' , 'test ' ));
145+ $ this ->routeCollection ->add ('test.fr ' , (new Route ('/tester/est/amusant ' ))->setDefault ('_locale ' , ' fr ' )-> setDefault ( ' _canonical_route ' , 'test ' ));
146146
147147 $ code = $ this ->generatorDumper ->dump ([
148148 'class ' => 'FallbackLocaleLocalizedProjectUrlGenerator ' ,
@@ -250,4 +250,32 @@ public function testDumpWithSchemeRequirement()
250250 $ this ->assertEquals ('https://localhost/app.php/testing ' , $ absoluteUrl );
251251 $ this ->assertEquals ('/app.php/testing ' , $ relativeUrl );
252252 }
253+
254+ public function testDumpWithLocalizedRoutesPreserveTheGoodLocaleInTheUrl ()
255+ {
256+ $ this ->routeCollection ->add ('foo.en ' , (new Route ('/{_locale}/foo ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'foo ' ));
257+ $ this ->routeCollection ->add ('foo.fr ' , (new Route ('/{_locale}/foo ' ))->setDefault ('_locale ' , 'fr ' )->setDefault ('_canonical_route ' , 'foo ' ));
258+ $ this ->routeCollection ->add ('fun.en ' , (new Route ('/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'fun ' ));
259+ $ this ->routeCollection ->add ('fun.fr ' , (new Route ('/amusant ' ))->setDefault ('_locale ' , 'fr ' )->setDefault ('_canonical_route ' , 'fun ' ));
260+
261+ file_put_contents ($ this ->testTmpFilepath , $ this ->generatorDumper ->dump ([
262+ 'class ' => 'PreserveTheGoodLocaleInTheUrlGenerator ' ,
263+ ]));
264+ include $ this ->testTmpFilepath ;
265+
266+ $ requestContext = new RequestContext ();
267+ $ requestContext ->setParameter ('_locale ' , 'fr ' );
268+
269+ $ phpGenerator = new \PreserveTheGoodLocaleInTheUrlGenerator ($ requestContext );
270+
271+ $ this ->assertSame ('/fr/foo ' , $ phpGenerator ->generate ('foo ' ));
272+ $ this ->assertSame ('/en/foo ' , $ phpGenerator ->generate ('foo.en ' ));
273+ $ this ->assertSame ('/en/foo ' , $ phpGenerator ->generate ('foo ' , ['_locale ' => 'en ' ]));
274+ $ this ->assertSame ('/en/foo ' , $ phpGenerator ->generate ('foo.fr ' , ['_locale ' => 'en ' ]));
275+
276+ $ this ->assertSame ('/amusant ' , $ phpGenerator ->generate ('fun ' ));
277+ $ this ->assertSame ('/fun ' , $ phpGenerator ->generate ('fun.en ' ));
278+ $ this ->assertSame ('/fun ' , $ phpGenerator ->generate ('fun ' , ['_locale ' => 'en ' ]));
279+ $ this ->assertSame ('/amusant ' , $ phpGenerator ->generate ('fun.fr ' , ['_locale ' => 'en ' ]));
280+ }
253281}
0 commit comments