|
14 | 14 | use Symfony\Component\Routing\RouteCollection; |
15 | 15 | use Symfony\Component\Routing\Route; |
16 | 16 | use Symfony\Component\Routing\Generator\UrlGenerator; |
| 17 | +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
17 | 18 | use Symfony\Component\Routing\RequestContext; |
18 | 19 |
|
19 | 20 | class UrlGeneratorTest extends \PHPUnit_Framework_TestCase |
@@ -439,6 +440,58 @@ public function testUrlWithInvalidParameterInHostnameInNonStrictMode() |
439 | 440 | $this->assertNull($generator->generate('test', array('foo' => 'baz'), false)); |
440 | 441 | } |
441 | 442 |
|
| 443 | + public function testGenerateNetworkPath() |
| 444 | + { |
| 445 | + $routes = $this->getRoutes('test', new Route('/{name}', array(), array('_scheme' => 'http'), array(), '{locale}.example.com')); |
| 446 | + |
| 447 | + $this->assertSame('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', |
| 448 | + array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'network path with different host' |
| 449 | + ); |
| 450 | + $this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', |
| 451 | + array('name' =>'Fabien', 'locale' => 'fr', 'query' => 'string'), UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context' |
| 452 | + ); |
| 453 | + $this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', |
| 454 | + array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context' |
| 455 | + ); |
| 456 | + $this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', |
| 457 | + array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested' |
| 458 | + ); |
| 459 | + } |
| 460 | + |
| 461 | + public function testGenerateRelativePath() |
| 462 | + { |
| 463 | + $routes = new RouteCollection(); |
| 464 | + $routes->add('article', new Route('/{author}/{article}/')); |
| 465 | + $routes->add('comments', new Route('/{author}/{article}/comments')); |
| 466 | + $routes->add('hostname', new Route('/{article}', array(), array(), array(), '{author}.example.com')); |
| 467 | + $routes->add('scheme', new Route('/{author}', array(), array('_scheme' => 'https'))); |
| 468 | + $routes->add('unrelated', new Route('/about')); |
| 469 | + |
| 470 | + $generator = $this->getGenerator($routes, array('host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/')); |
| 471 | + |
| 472 | + $this->assertSame('comments', $generator->generate('comments', |
| 473 | + array('author' =>'fabien', 'article' => 'symfony-is-great'), UrlGeneratorInterface::RELATIVE_PATH) |
| 474 | + ); |
| 475 | + $this->assertSame('comments?page=2', $generator->generate('comments', |
| 476 | + array('author' =>'fabien', 'article' => 'symfony-is-great', 'page' => 2), UrlGeneratorInterface::RELATIVE_PATH) |
| 477 | + ); |
| 478 | + $this->assertSame('../twig-is-great/', $generator->generate('article', |
| 479 | + array('author' =>'fabien', 'article' => 'twig-is-great'), UrlGeneratorInterface::RELATIVE_PATH) |
| 480 | + ); |
| 481 | + $this->assertSame('../../bernhard/forms-are-great/', $generator->generate('article', |
| 482 | + array('author' =>'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH) |
| 483 | + ); |
| 484 | + $this->assertSame('//bernhard.example.com/app.php/forms-are-great', $generator->generate('hostname', |
| 485 | + array('author' =>'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH) |
| 486 | + ); |
| 487 | + $this->assertSame('https://example.com/app.php/bernhard', $generator->generate('scheme', |
| 488 | + array('author' =>'bernhard'), UrlGeneratorInterface::RELATIVE_PATH) |
| 489 | + ); |
| 490 | + $this->assertSame('../../about', $generator->generate('unrelated', |
| 491 | + array(), UrlGeneratorInterface::RELATIVE_PATH) |
| 492 | + ); |
| 493 | + } |
| 494 | + |
442 | 495 | /** |
443 | 496 | * @dataProvider provideRelativePaths |
444 | 497 | */ |
|
0 commit comments