@@ -225,4 +225,39 @@ public function testDecodeOnce()
225
225
$ matcher = new UrlMatcher ($ coll , new RequestContext ());
226
226
$ this ->assertEquals (array ('foo ' => 'bar%23 ' , '_route ' => 'foo ' ), $ matcher ->match ('/foo/bar%2523 ' ));
227
227
}
228
+
229
+ public function testWithHostname ()
230
+ {
231
+ $ coll = new RouteCollection ();
232
+ $ coll ->add ('foo ' , new Route ('/foo/{foo} ' , array (), array (), array (), '{locale}.example.com ' ));
233
+
234
+ $ matcher = new UrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'en.example.com ' ));
235
+ $ this ->assertEquals (array ('foo ' => 'bar ' , '_route ' => 'foo ' , 'locale ' => 'en ' ), $ matcher ->match ('/foo/bar ' ));
236
+ }
237
+
238
+ public function testWithHostnameOnRouteCollection ()
239
+ {
240
+ $ coll = new RouteCollection ();
241
+ $ coll ->add ('foo ' , new Route ('/foo/{foo} ' ));
242
+ $ coll ->add ('bar ' , new Route ('/bar/{foo} ' , array (), array (), array (), '{locale}.example.net ' ));
243
+ $ coll ->setHostnamePattern ('{locale}.example.com ' );
244
+
245
+ $ matcher = new UrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'en.example.com ' ));
246
+ $ this ->assertEquals (array ('foo ' => 'bar ' , '_route ' => 'foo ' , 'locale ' => 'en ' ), $ matcher ->match ('/foo/bar ' ));
247
+
248
+ $ matcher = new UrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'en.example.net ' ));
249
+ $ this ->assertEquals (array ('foo ' => 'bar ' , '_route ' => 'bar ' , 'locale ' => 'en ' ), $ matcher ->match ('/bar/bar ' ));
250
+ }
251
+
252
+ /**
253
+ * @expectedException Symfony\Component\Routing\Exception\ResourceNotFoundException
254
+ */
255
+ public function testWithOutHostnameHostnameDoesNotMatch ()
256
+ {
257
+ $ coll = new RouteCollection ();
258
+ $ coll ->add ('foo ' , new Route ('/foo/{foo} ' , array (), array (), array (), '{locale}.example.com ' ));
259
+
260
+ $ matcher = new UrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'example.com ' ));
261
+ $ matcher ->match ('/foo/bar ' );
262
+ }
228
263
}
0 commit comments