@@ -87,8 +87,8 @@ public function testDumpWithRoutes()
87
87
public function testDumpWithSimpleLocalizedRoutes ()
88
88
{
89
89
$ this ->routeCollection ->add ('test ' , (new Route ('/foo ' )));
90
- $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' ));
91
- $ this ->routeCollection ->add ('test.nl ' , (new Route ('/testen/is/leuk ' ))->setDefault ('_locale ' , 'nl ' )->setDefault ('_canonical_route ' , 'test ' ));
90
+ $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' )-> setRequirement ( ' _locale ' , ' en ' ) );
91
+ $ this ->routeCollection ->add ('test.nl ' , (new Route ('/testen/is/leuk ' ))->setDefault ('_locale ' , 'nl ' )->setDefault ('_canonical_route ' , 'test ' )-> setRequirement ( ' _locale ' , ' nl ' ) );
92
92
93
93
$ code = $ this ->generatorDumper ->dump ();
94
94
file_put_contents ($ this ->testTmpFilepath , $ code );
@@ -120,7 +120,7 @@ public function testDumpWithRouteNotFoundLocalizedRoutes()
120
120
{
121
121
$ this ->expectException ('Symfony\Component\Routing\Exception\RouteNotFoundException ' );
122
122
$ this ->expectExceptionMessage ('Unable to generate a URL for the named route "test" as such route does not exist. ' );
123
- $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' ));
123
+ $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' )-> setRequirement ( ' _locale ' , ' en ' ) );
124
124
125
125
$ code = $ this ->generatorDumper ->dump ();
126
126
file_put_contents ($ this ->testTmpFilepath , $ code );
@@ -131,9 +131,9 @@ public function testDumpWithRouteNotFoundLocalizedRoutes()
131
131
132
132
public function testDumpWithFallbackLocaleLocalizedRoutes ()
133
133
{
134
- $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' ));
135
- $ this ->routeCollection ->add ('test.nl ' , (new Route ('/testen/is/leuk ' ))->setDefault ('_locale ' , 'nl ' )->setDefault ('_canonical_route ' , 'test ' ));
136
- $ this ->routeCollection ->add ('test.fr ' , (new Route ('/tester/est/amusant ' ))->setDefault ('_locale ' , 'fr ' )->setDefault ('_canonical_route ' , 'test ' ));
134
+ $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' )-> setRequirement ( ' _locale ' , ' en ' ) );
135
+ $ this ->routeCollection ->add ('test.nl ' , (new Route ('/testen/is/leuk ' ))->setDefault ('_locale ' , 'nl ' )->setDefault ('_canonical_route ' , 'test ' )-> setRequirement ( ' _locale ' , ' nl ' ) );
136
+ $ this ->routeCollection ->add ('test.fr ' , (new Route ('/tester/est/amusant ' ))->setDefault ('_locale ' , 'fr ' )->setDefault ('_canonical_route ' , 'test ' )-> setRequirement ( ' _locale ' , ' fr ' ) );
137
137
138
138
$ code = $ this ->generatorDumper ->dump ();
139
139
file_put_contents ($ this ->testTmpFilepath , $ code );
@@ -234,10 +234,10 @@ public function testDumpWithSchemeRequirement()
234
234
235
235
public function testDumpWithLocalizedRoutesPreserveTheGoodLocaleInTheUrl ()
236
236
{
237
- $ this ->routeCollection ->add ('foo.en ' , (new Route ('/{_locale}/foo ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'foo ' ));
238
- $ this ->routeCollection ->add ('foo.fr ' , (new Route ('/{_locale}/foo ' ))->setDefault ('_locale ' , 'fr ' )->setDefault ('_canonical_route ' , 'foo ' ));
239
- $ this ->routeCollection ->add ('fun.en ' , (new Route ('/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'fun ' ));
240
- $ this ->routeCollection ->add ('fun.fr ' , (new Route ('/amusant ' ))->setDefault ('_locale ' , 'fr ' )->setDefault ('_canonical_route ' , 'fun ' ));
237
+ $ this ->routeCollection ->add ('foo.en ' , (new Route ('/{_locale}/fork ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'foo ' )-> setRequirement ( ' _locale ' , ' en ' ));
238
+ $ this ->routeCollection ->add ('foo.fr ' , (new Route ('/{_locale}/fourchette ' ))->setDefault ('_locale ' , 'fr ' )->setDefault ('_canonical_route ' , 'foo ' )-> setRequirement ( ' _locale ' , ' fr ' ));
239
+ $ this ->routeCollection ->add ('fun.en ' , (new Route ('/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'fun ' )-> setRequirement ( ' _locale ' , ' en ' ) );
240
+ $ this ->routeCollection ->add ('fun.fr ' , (new Route ('/amusant ' ))->setDefault ('_locale ' , 'fr ' )->setDefault ('_canonical_route ' , 'fun ' )-> setRequirement ( ' _locale ' , ' fr ' ) );
241
241
242
242
file_put_contents ($ this ->testTmpFilepath , $ this ->generatorDumper ->dump ());
243
243
@@ -246,10 +246,10 @@ public function testDumpWithLocalizedRoutesPreserveTheGoodLocaleInTheUrl()
246
246
247
247
$ compiledUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , $ requestContext , null , null );
248
248
249
- $ this ->assertSame ('/fr/foo ' , $ compiledUrlGenerator ->generate ('foo ' ));
250
- $ this ->assertSame ('/en/foo ' , $ compiledUrlGenerator ->generate ('foo.en ' ));
251
- $ this ->assertSame ('/en/foo ' , $ compiledUrlGenerator ->generate ('foo ' , ['_locale ' => 'en ' ]));
252
- $ this ->assertSame ('/en/foo ' , $ compiledUrlGenerator ->generate ('foo.fr ' , ['_locale ' => 'en ' ]));
249
+ $ this ->assertSame ('/fr/fourchette ' , $ compiledUrlGenerator ->generate ('foo ' ));
250
+ $ this ->assertSame ('/en/fork ' , $ compiledUrlGenerator ->generate ('foo.en ' ));
251
+ $ this ->assertSame ('/en/fork ' , $ compiledUrlGenerator ->generate ('foo ' , ['_locale ' => 'en ' ]));
252
+ $ this ->assertSame ('/fr/fourchette ' , $ compiledUrlGenerator ->generate ('foo.fr ' , ['_locale ' => 'en ' ]));
253
253
254
254
$ this ->assertSame ('/amusant ' , $ compiledUrlGenerator ->generate ('fun ' ));
255
255
$ this ->assertSame ('/fun ' , $ compiledUrlGenerator ->generate ('fun.en ' ));
0 commit comments