@@ -248,22 +248,40 @@ public function testRequiredParamAndEmptyPassed()
248
248
249
249
public function testSchemeRequirementDoesNothingIfSameCurrentScheme ()
250
250
{
251
- $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array ('_scheme ' => 'http ' )));
251
+ $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array ('_scheme ' => 'http ' ))); // BC
252
252
$ this ->assertEquals ('/app.php/ ' , $ this ->getGenerator ($ routes )->generate ('test ' ));
253
253
254
- $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array ('_scheme ' => 'https ' )));
254
+ $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array ('_scheme ' => 'https ' ))); // BC
255
+ $ this ->assertEquals ('/app.php/ ' , $ this ->getGenerator ($ routes , array ('scheme ' => 'https ' ))->generate ('test ' ));
256
+
257
+ $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array (), array (), '' , array ('http ' )));
258
+ $ this ->assertEquals ('/app.php/ ' , $ this ->getGenerator ($ routes )->generate ('test ' ));
259
+
260
+ $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array (), array (), '' , array ('https ' )));
255
261
$ this ->assertEquals ('/app.php/ ' , $ this ->getGenerator ($ routes , array ('scheme ' => 'https ' ))->generate ('test ' ));
256
262
}
257
263
258
264
public function testSchemeRequirementForcesAbsoluteUrl ()
259
265
{
260
- $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array ('_scheme ' => 'https ' )));
266
+ $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array ('_scheme ' => 'https ' ))); // BC
267
+ $ this ->assertEquals ('https://localhost/app.php/ ' , $ this ->getGenerator ($ routes )->generate ('test ' ));
268
+
269
+ $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array ('_scheme ' => 'http ' ))); // BC
270
+ $ this ->assertEquals ('http://localhost/app.php/ ' , $ this ->getGenerator ($ routes , array ('scheme ' => 'https ' ))->generate ('test ' ));
271
+
272
+ $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array (), array (), '' , array ('https ' )));
261
273
$ this ->assertEquals ('https://localhost/app.php/ ' , $ this ->getGenerator ($ routes )->generate ('test ' ));
262
274
263
- $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array (' _scheme ' => 'http ' )));
275
+ $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array (), array (), '' , array ( 'http ' )));
264
276
$ this ->assertEquals ('http://localhost/app.php/ ' , $ this ->getGenerator ($ routes , array ('scheme ' => 'https ' ))->generate ('test ' ));
265
277
}
266
278
279
+ public function testSchemeRequirementCreatesUrlForFirstRequiredScheme ()
280
+ {
281
+ $ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , array (), array (), array (), '' , array ('Ftp ' , 'https ' )));
282
+ $ this ->assertEquals ('ftp://localhost/app.php/ ' , $ this ->getGenerator ($ routes )->generate ('test ' ));
283
+ }
284
+
267
285
public function testPathWithTwoStartingSlashes ()
268
286
{
269
287
$ routes = $ this ->getRoutes ('test ' , new Route ('//path-and-not-domain ' ));
@@ -447,7 +465,7 @@ public function testUrlWithInvalidParameterInHostInNonStrictMode()
447
465
$ this ->assertNull ($ generator ->generate ('test ' , array ('foo ' => 'baz ' ), false ));
448
466
}
449
467
450
- public function testGenerateNetworkPath ()
468
+ public function testGenerateNetworkPathBC ()
451
469
{
452
470
$ routes = $ this ->getRoutes ('test ' , new Route ('/{name} ' , array (), array ('_scheme ' => 'http ' ), array (), '{locale}.example.com ' ));
453
471
@@ -465,13 +483,32 @@ public function testGenerateNetworkPath()
465
483
);
466
484
}
467
485
486
+ public function testGenerateNetworkPath ()
487
+ {
488
+ $ routes = $ this ->getRoutes ('test ' , new Route ('/{name} ' , array (), array (), array (), '{locale}.example.com ' , array ('http ' )));
489
+
490
+ $ this ->assertSame ('//fr.example.com/app.php/Fabien ' , $ this ->getGenerator ($ routes )->generate ('test ' ,
491
+ array ('name ' =>'Fabien ' , 'locale ' => 'fr ' ), UrlGeneratorInterface::NETWORK_PATH ), 'network path with different host '
492
+ );
493
+ $ this ->assertSame ('//fr.example.com/app.php/Fabien?query=string ' , $ this ->getGenerator ($ routes , array ('host ' => 'fr.example.com ' ))->generate ('test ' ,
494
+ array ('name ' =>'Fabien ' , 'locale ' => 'fr ' , 'query ' => 'string ' ), UrlGeneratorInterface::NETWORK_PATH ), 'network path although host same as context '
495
+ );
496
+ $ this ->assertSame ('http://fr.example.com/app.php/Fabien ' , $ this ->getGenerator ($ routes , array ('scheme ' => 'https ' ))->generate ('test ' ,
497
+ array ('name ' =>'Fabien ' , 'locale ' => 'fr ' ), UrlGeneratorInterface::NETWORK_PATH ), 'absolute URL because scheme requirement does not match context '
498
+ );
499
+ $ this ->assertSame ('http://fr.example.com/app.php/Fabien ' , $ this ->getGenerator ($ routes )->generate ('test ' ,
500
+ array ('name ' =>'Fabien ' , 'locale ' => 'fr ' ), UrlGeneratorInterface::ABSOLUTE_URL ), 'absolute URL with same scheme because it is requested '
501
+ );
502
+ }
503
+
468
504
public function testGenerateRelativePath ()
469
505
{
470
506
$ routes = new RouteCollection ();
471
507
$ routes ->add ('article ' , new Route ('/{author}/{article}/ ' ));
472
508
$ routes ->add ('comments ' , new Route ('/{author}/{article}/comments ' ));
473
509
$ routes ->add ('host ' , new Route ('/{article} ' , array (), array (), array (), '{author}.example.com ' ));
474
- $ routes ->add ('scheme ' , new Route ('/{author} ' , array (), array ('_scheme ' => 'https ' )));
510
+ $ routes ->add ('schemeBC ' , new Route ('/{author} ' , array (), array ('_scheme ' => 'https ' ))); // BC
511
+ $ routes ->add ('scheme ' , new Route ('/{author}/blog ' , array (), array (), array (), '' , array ('https ' )));
475
512
$ routes ->add ('unrelated ' , new Route ('/about ' ));
476
513
477
514
$ generator = $ this ->getGenerator ($ routes , array ('host ' => 'example.com ' , 'pathInfo ' => '/fabien/symfony-is-great/ ' ));
@@ -491,9 +528,12 @@ public function testGenerateRelativePath()
491
528
$ this ->assertSame ('//bernhard.example.com/app.php/forms-are-great ' , $ generator ->generate ('host ' ,
492
529
array ('author ' =>'bernhard ' , 'article ' => 'forms-are-great ' ), UrlGeneratorInterface::RELATIVE_PATH )
493
530
);
494
- $ this ->assertSame ('https://example.com/app.php/bernhard ' , $ generator ->generate ('scheme ' ,
531
+ $ this ->assertSame ('https://example.com/app.php/bernhard ' , $ generator ->generate ('schemeBC ' ,
495
532
array ('author ' =>'bernhard ' ), UrlGeneratorInterface::RELATIVE_PATH )
496
533
);
534
+ $ this ->assertSame ('https://example.com/app.php/bernhard/blog ' , $ generator ->generate ('scheme ' ,
535
+ array ('author ' =>'bernhard ' ), UrlGeneratorInterface::RELATIVE_PATH )
536
+ );
497
537
$ this ->assertSame ('../../about ' , $ generator ->generate ('unrelated ' ,
498
538
array (), UrlGeneratorInterface::RELATIVE_PATH )
499
539
);
0 commit comments