UrlGeneratorTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Routing\Generator;
  11. use Symfony\Component\Routing\RouteCollection;
  12. use Symfony\Component\Routing\Route;
  13. use Symfony\Component\Routing\Generator\UrlGenerator;
  14. class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
  15. {
  16. /** @var RouteCollection */
  17. private $routeCollection;
  18. /** @var UrlGenerator */
  19. private $generator;
  20. protected function setUp()
  21. {
  22. parent::setUp();
  23. $this->routeCollection = new RouteCollection();
  24. $this->generator = new UrlGenerator($this->routeCollection);
  25. }
  26. public function testAbsoluteUrlWithPort80()
  27. {
  28. $this->routeCollection->add('test', new Route('/testing'));
  29. $this->generator->setContext(array(
  30. 'base_url'=>'/app.php',
  31. 'method'=>'GET',
  32. 'host'=>'localhost',
  33. 'port'=>80,
  34. 'is_secure'=>false));
  35. $url = $this->generator->generate('test', array(), true);
  36. $this->assertEquals('http://localhost/app.php/testing', $url);
  37. }
  38. public function testAbsoluteSecureUrlWithPort443()
  39. {
  40. $this->routeCollection->add('test', new Route('/testing'));
  41. $this->generator->setContext(array(
  42. 'base_url'=>'/app.php',
  43. 'method'=>'GET',
  44. 'host'=>'localhost',
  45. 'port'=>443,
  46. 'is_secure'=>true));
  47. $url = $this->generator->generate('test', array(), true);
  48. $this->assertEquals('https://localhost/app.php/testing', $url);
  49. }
  50. public function testAbsoluteUrlWithNonStandardPort()
  51. {
  52. $this->routeCollection->add('test', new Route('/testing'));
  53. $this->generator->setContext(array(
  54. 'base_url'=>'/app.php',
  55. 'method'=>'GET',
  56. 'host'=>'localhost',
  57. 'port'=>8080,
  58. 'is_secure'=>false));
  59. $url = $this->generator->generate('test', array(), true);
  60. $this->assertEquals('http://localhost:8080/app.php/testing', $url);
  61. }
  62. public function testAbsoluteSecureUrlWithNonStandardPort()
  63. {
  64. $this->routeCollection->add('test', new Route('/testing'));
  65. $this->generator->setContext(array(
  66. 'base_url'=>'/app.php',
  67. 'method'=>'GET',
  68. 'host'=>'localhost',
  69. 'port'=>8080,
  70. 'is_secure'=>true));
  71. $url = $this->generator->generate('test', array(), true);
  72. $this->assertEquals('https://localhost:8080/app.php/testing', $url);
  73. }
  74. }