@@ -84,19 +84,20 @@ public function testDumpWithRoutes()
84
84
$ this ->assertEquals ('/app.php/testing2 ' , $ relativeUrlWithoutParameter );
85
85
}
86
86
87
- public function testDumpWithLocalizedRoutes ()
87
+ public function testDumpWithSimpleLocalizedRoutes ()
88
88
{
89
+ $ this ->routeCollection ->add ('test ' , (new Route ('/foo ' )));
89
90
$ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' ));
90
91
$ this ->routeCollection ->add ('test.nl ' , (new Route ('/testen/is/leuk ' ))->setDefault ('_locale ' , 'nl ' )->setDefault ('_canonical_route ' , 'test ' ));
91
92
92
93
$ code = $ this ->generatorDumper ->dump (array (
93
- 'class ' => 'LocalizedProjectUrlGenerator ' ,
94
+ 'class ' => 'SimpleLocalizedProjectUrlGenerator ' ,
94
95
));
95
96
file_put_contents ($ this ->testTmpFilepath , $ code );
96
97
include $ this ->testTmpFilepath ;
97
98
98
99
$ context = new RequestContext ('/app.php ' );
99
- $ projectUrlGenerator = new \LocalizedProjectUrlGenerator ($ context , null , 'en ' );
100
+ $ projectUrlGenerator = new \SimpleLocalizedProjectUrlGenerator ($ context , null , 'en ' );
100
101
101
102
$ urlWithDefaultLocale = $ projectUrlGenerator ->generate ('test ' );
102
103
$ urlWithSpecifiedLocale = $ projectUrlGenerator ->generate ('test ' , array ('_locale ' => 'nl ' ));
@@ -109,6 +110,57 @@ public function testDumpWithLocalizedRoutes()
109
110
$ this ->assertEquals ('/app.php/testen/is/leuk ' , $ urlWithSpecifiedLocale );
110
111
$ this ->assertEquals ('/app.php/testing/is/fun ' , $ urlWithEnglishContext );
111
112
$ 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 ' ));
112
164
}
113
165
114
166
public function testDumpWithTooManyRoutes ()
0 commit comments