@@ -84,19 +84,20 @@ public function testDumpWithRoutes()
8484 $ this ->assertEquals ('/app.php/testing2 ' , $ relativeUrlWithoutParameter );
8585 }
8686
87- public function testDumpWithLocalizedRoutes ()
87+ public function testDumpWithSimpleLocalizedRoutes ()
8888 {
89+ $ this ->routeCollection ->add ('test ' , (new Route ('/foo ' )));
8990 $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' ));
9091 $ this ->routeCollection ->add ('test.nl ' , (new Route ('/testen/is/leuk ' ))->setDefault ('_locale ' , 'nl ' )->setDefault ('_canonical_route ' , 'test ' ));
9192
9293 $ code = $ this ->generatorDumper ->dump (array (
93- 'class ' => 'LocalizedProjectUrlGenerator ' ,
94+ 'class ' => 'SimpleLocalizedProjectUrlGenerator ' ,
9495 ));
9596 file_put_contents ($ this ->testTmpFilepath , $ code );
9697 include $ this ->testTmpFilepath ;
9798
9899 $ context = new RequestContext ('/app.php ' );
99- $ projectUrlGenerator = new \LocalizedProjectUrlGenerator ($ context , null , 'en ' );
100+ $ projectUrlGenerator = new \SimpleLocalizedProjectUrlGenerator ($ context , null , 'en ' );
100101
101102 $ urlWithDefaultLocale = $ projectUrlGenerator ->generate ('test ' );
102103 $ urlWithSpecifiedLocale = $ projectUrlGenerator ->generate ('test ' , array ('_locale ' => 'nl ' ));
@@ -109,6 +110,57 @@ public function testDumpWithLocalizedRoutes()
109110 $ this ->assertEquals ('/app.php/testen/is/leuk ' , $ urlWithSpecifiedLocale );
110111 $ this ->assertEquals ('/app.php/testing/is/fun ' , $ urlWithEnglishContext );
111112 $ this ->assertEquals ('/app.php/testen/is/leuk ' , $ urlWithDutchContext );
113+
114+ // test with full route name
115+ $ this ->assertEquals ('/app.php/testing/is/fun ' , $ projectUrlGenerator ->generate ('test.en ' ));
116+
117+ $ context ->setParameter ('_locale ' , 'de_DE ' );
118+ // test that it fall backs to another route when there is no matching localized route
119+ $ this ->assertEquals ('/app.php/foo ' , $ projectUrlGenerator ->generate ('test ' ));
120+ }
121+
122+ /**
123+ * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
124+ * @expectedExceptionMessage Unable to generate a URL for the named route "test" as such route does not exist.
125+ */
126+ public function testDumpWithRouteNotFoundLocalizedRoutes ()
127+ {
128+ $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' ));
129+
130+ $ code = $ this ->generatorDumper ->dump (array (
131+ 'class ' => 'RouteNotFoundLocalizedProjectUrlGenerator ' ,
132+ ));
133+ file_put_contents ($ this ->testTmpFilepath , $ code );
134+ include $ this ->testTmpFilepath ;
135+
136+ $ projectUrlGenerator = new \RouteNotFoundLocalizedProjectUrlGenerator (new RequestContext ('/app.php ' ), null , 'pl_PL ' );
137+ $ projectUrlGenerator ->generate ('test ' );
138+ }
139+
140+ public function testDumpWithFallbackLocaleLocalizedRoutes ()
141+ {
142+ $ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_canonical_route ' , 'test ' ));
143+ $ this ->routeCollection ->add ('test.nl ' , (new Route ('/testen/is/leuk ' ))->setDefault ('_canonical_route ' , 'test ' ));
144+ $ this ->routeCollection ->add ('test.fr ' , (new Route ('/tester/est/amusant ' ))->setDefault ('_canonical_route ' , 'test ' ));
145+
146+ $ code = $ this ->generatorDumper ->dump (array (
147+ 'class ' => 'FallbackLocaleLocalizedProjectUrlGenerator ' ,
148+ ));
149+ file_put_contents ($ this ->testTmpFilepath , $ code );
150+ include $ this ->testTmpFilepath ;
151+
152+ $ context = new RequestContext ('/app.php ' );
153+ $ context ->setParameter ('_locale ' , 'en_GB ' );
154+ $ projectUrlGenerator = new \FallbackLocaleLocalizedProjectUrlGenerator ($ context , null , null );
155+
156+ // test with context _locale
157+ $ this ->assertEquals ('/app.php/testing/is/fun ' , $ projectUrlGenerator ->generate ('test ' ));
158+ // test with parameters _locale
159+ $ this ->assertEquals ('/app.php/testen/is/leuk ' , $ projectUrlGenerator ->generate ('test ' , array ('_locale ' => 'nl_BE ' )));
160+
161+ $ projectUrlGenerator = new \FallbackLocaleLocalizedProjectUrlGenerator (new RequestContext ('/app.php ' ), null , 'fr_CA ' );
162+ // test with default locale
163+ $ this ->assertEquals ('/app.php/tester/est/amusant ' , $ projectUrlGenerator ->generate ('test ' ));
112164 }
113165
114166 public function testDumpWithTooManyRoutes ()
0 commit comments