@@ -179,4 +179,78 @@ public function getNumericVariableNames()
179179 array ('1e2 ' )
180180 );
181181 }
182+
183+ /**
184+ * @dataProvider provideCompileWithHostnameData
185+ */
186+ public function testCompileWithHostname ($ name , $ arguments , $ prefix , $ regex , $ variables , $ pathVariables , $ tokens , $ hostnameRegex , $ hostnameVariables , $ hostnameTokens )
187+ {
188+ $ r = new \ReflectionClass ('Symfony \\Component \\Routing \\Route ' );
189+ $ route = $ r ->newInstanceArgs ($ arguments );
190+
191+ $ compiled = $ route ->compile ();
192+ $ this ->assertEquals ($ prefix , $ compiled ->getStaticPrefix (), $ name .' (static prefix) ' );
193+ $ this ->assertEquals ($ regex , str_replace (array ("\n" , ' ' ), '' , $ compiled ->getRegex ()), $ name .' (regex) ' );
194+ $ this ->assertEquals ($ variables , $ compiled ->getVariables (), $ name .' (variables) ' );
195+ $ this ->assertEquals ($ pathVariables , $ compiled ->getPathVariables (), $ name .' (path variables) ' );
196+ $ this ->assertEquals ($ tokens , $ compiled ->getTokens (), $ name .' (tokens) ' );
197+
198+
199+ $ this ->assertEquals ($ hostnameRegex , str_replace (array ("\n" , ' ' ), '' , $ compiled ->getHostnameRegex ()), $ name .' (hostname regex) ' );
200+ $ this ->assertEquals ($ hostnameVariables , $ compiled ->getHostnameVariables (), $ name .' (hostname variables) ' );
201+ $ this ->assertEquals ($ hostnameTokens , $ compiled ->getHostnameTokens (), $ name .' (hostname tokens) ' );
202+ }
203+
204+ public function provideCompileWithHostnameData ()
205+ {
206+ return array (
207+ array (
208+ 'Route with hostname pattern ' ,
209+ array ('/hello ' , array (), array (), array (), 'www.example.com ' ),
210+ '/hello ' , '#^/hello$#s ' , array (), array (), array (
211+ array ('text ' , '/hello ' ),
212+ ),
213+ '#^www\.example\.com$#s ' , array (), array (
214+ array ('text ' , 'www.example.com ' ),
215+ ),
216+ ),
217+ array (
218+ 'Route with hostname pattern and some variables ' ,
219+ array ('/hello/{name} ' , array (), array (), array (), 'www.example.{tld} ' ),
220+ '/hello ' , '#^/hello/(?<name>[^/]++)$#s ' , array ('tld ' , 'name ' ), array ('name ' ), array (
221+ array ('variable ' , '/ ' , '[^/]++ ' , 'name ' ),
222+ array ('text ' , '/hello ' ),
223+ ),
224+ '#^www\.example\.(?<tld>[^\.]++)$#s ' , array ('tld ' ), array (
225+ array ('variable ' , '. ' , '[^\.]++ ' , 'tld ' ),
226+ array ('text ' , 'www.example ' ),
227+ ),
228+ ),
229+ array (
230+ 'Route with variable at begining of hostname ' ,
231+ array ('/hello ' , array (), array (), array (), '{locale}.example.{tld} ' ),
232+ '/hello ' , '#^/hello$#s ' , array ('locale ' , 'tld ' ), array (), array (
233+ array ('text ' , '/hello ' ),
234+ ),
235+ '#^(?<locale>[^\.]++)\.example\.(?<tld>[^\.]++)$#s ' , array ('locale ' , 'tld ' ), array (
236+ array ('variable ' , '. ' , '[^\.]++ ' , 'tld ' ),
237+ array ('text ' , '.example ' ),
238+ array ('variable ' , '' , '[^\.]++ ' , 'locale ' ),
239+ ),
240+ ),
241+ array (
242+ 'Route with hostname variables that has a default value ' ,
243+ array ('/hello ' , array ('locale ' => 'a ' , 'tld ' => 'b ' ), array (), array (), '{locale}.example.{tld} ' ),
244+ '/hello ' , '#^/hello$#s ' , array ('locale ' , 'tld ' ), array (), array (
245+ array ('text ' , '/hello ' ),
246+ ),
247+ '#^(?<locale>[^\.]++)\.example\.(?<tld>[^\.]++)$#s ' , array ('locale ' , 'tld ' ), array (
248+ array ('variable ' , '. ' , '[^\.]++ ' , 'tld ' ),
249+ array ('text ' , '.example ' ),
250+ array ('variable ' , '' , '[^\.]++ ' , 'locale ' ),
251+ ),
252+ ),
253+ );
254+ }
182255}
256+
0 commit comments