|
13 | 13 |
|
14 | 14 | use FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor; |
15 | 15 | use FOS\JsRoutingBundle\Extractor\ExtractedRoute; |
| 16 | +use Symfony\Component\Routing\RequestContext; |
16 | 17 | use Symfony\Component\Routing\Route; |
17 | 18 | use Symfony\Component\HttpKernel\Kernel; |
18 | 19 |
|
@@ -105,6 +106,54 @@ public function testGetCachePath() |
105 | 106 | $this->assertEquals($this->cacheDir . DIRECTORY_SEPARATOR . 'fosJsRouting' . DIRECTORY_SEPARATOR . 'data.json', $extractor->getCachePath('')); |
106 | 107 | } |
107 | 108 |
|
| 109 | + /** |
| 110 | + * @dataProvider provideTestGetHostOverHttp |
| 111 | + */ |
| 112 | + public function testGetHostOverHttp($host, $httpPort, $expected) |
| 113 | + { |
| 114 | + $requestContext = new RequestContext('/app_dev.php', 'GET', $host, 'http', $httpPort); |
| 115 | + |
| 116 | + $router = $this->getMock('Symfony\\Component\\Routing\\Router', array(), array(), '', false); |
| 117 | + $router->expects($this->atLeastOnce()) |
| 118 | + ->method('getContext') |
| 119 | + ->will($this->returnValue($requestContext)); |
| 120 | + |
| 121 | + $extractor = new ExposedRoutesExtractor($router, array(), $this->cacheDir, array()); |
| 122 | + |
| 123 | + $this->assertEquals($expected, $extractor->getHost()); |
| 124 | + } |
| 125 | + public function provideTestGetHostOverHttp() |
| 126 | + { |
| 127 | + return array( |
| 128 | + 'HTTP Standard' => array('127.0.0.1', 80, '127.0.0.1'), |
| 129 | + 'HTTP Non-Standard' => array('127.0.0.1', 8888, '127.0.0.1:8888'), |
| 130 | + ); |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * @dataProvider provideTestGetHostOverHttps |
| 135 | + */ |
| 136 | + public function testGetHostOverHttps($host, $httpsPort, $expected) |
| 137 | + { |
| 138 | + $requestContext = new RequestContext('/app_dev.php', 'GET', $host, 'https', 80, $httpsPort); |
| 139 | + |
| 140 | + $router = $this->getMock('Symfony\\Component\\Routing\\Router', array(), array(), '', false); |
| 141 | + $router->expects($this->atLeastOnce()) |
| 142 | + ->method('getContext') |
| 143 | + ->will($this->returnValue($requestContext)); |
| 144 | + |
| 145 | + $extractor = new ExposedRoutesExtractor($router, array(), $this->cacheDir, array()); |
| 146 | + |
| 147 | + $this->assertEquals($expected, $extractor->getHost()); |
| 148 | + } |
| 149 | + public function provideTestGetHostOverHttps() |
| 150 | + { |
| 151 | + return array( |
| 152 | + 'HTTPS Standard' => array('127.0.0.1', 443, '127.0.0.1'), |
| 153 | + 'HTTPS Non-Standard' => array('127.0.0.1', 9876, '127.0.0.1:9876'), |
| 154 | + ); |
| 155 | + } |
| 156 | + |
108 | 157 | /** |
109 | 158 | * Get a mock object which represents a Router. |
110 | 159 | * @return \Symfony\Component\Routing\Router |
|
0 commit comments