@@ -328,4 +328,39 @@ public function testDecodeOnce()
328328 $ matcher = new UrlMatcher ($ coll , new RequestContext ());
329329 $ this ->assertEquals (array ('foo ' => 'bar%23 ' , '_route ' => 'foo ' ), $ matcher ->match ('/foo/bar%2523 ' ));
330330 }
331+
332+ public function testWithHostname ()
333+ {
334+ $ coll = new RouteCollection ();
335+ $ coll ->add ('foo ' , new Route ('/foo/{foo} ' , array (), array (), array (), '{locale}.example.com ' ));
336+
337+ $ matcher = new UrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'en.example.com ' ));
338+ $ this ->assertEquals (array ('foo ' => 'bar ' , '_route ' => 'foo ' , 'locale ' => 'en ' ), $ matcher ->match ('/foo/bar ' ));
339+ }
340+
341+ public function testWithHostnameOnRouteCollection ()
342+ {
343+ $ coll = new RouteCollection ();
344+ $ coll ->add ('foo ' , new Route ('/foo/{foo} ' ));
345+ $ coll ->add ('bar ' , new Route ('/bar/{foo} ' , array (), array (), array (), '{locale}.example.net ' ));
346+ $ coll ->setHostnamePattern ('{locale}.example.com ' );
347+
348+ $ matcher = new UrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'en.example.com ' ));
349+ $ this ->assertEquals (array ('foo ' => 'bar ' , '_route ' => 'foo ' , 'locale ' => 'en ' ), $ matcher ->match ('/foo/bar ' ));
350+
351+ $ matcher = new UrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'en.example.net ' ));
352+ $ this ->assertEquals (array ('foo ' => 'bar ' , '_route ' => 'bar ' , 'locale ' => 'en ' ), $ matcher ->match ('/bar/bar ' ));
353+ }
354+
355+ /**
356+ * @expectedException Symfony\Component\Routing\Exception\ResourceNotFoundException
357+ */
358+ public function testWithOutHostnameHostnameDoesNotMatch ()
359+ {
360+ $ coll = new RouteCollection ();
361+ $ coll ->add ('foo ' , new Route ('/foo/{foo} ' , array (), array (), array (), '{locale}.example.com ' ));
362+
363+ $ matcher = new UrlMatcher ($ coll , new RequestContext ('' , 'GET ' , 'example.com ' ));
364+ $ matcher ->match ('/foo/bar ' );
365+ }
331366}
0 commit comments