|
14 | 14 | use Symfony\Bridge\Twig\Extension\HttpFoundationExtension;
|
15 | 15 | use Symfony\Component\HttpFoundation\RequestStack;
|
16 | 16 | use Symfony\Component\HttpFoundation\Request;
|
| 17 | +use Symfony\Component\Routing\RequestContext; |
17 | 18 |
|
18 | 19 | class HttpFoundationExtensionTest extends \PHPUnit_Framework_TestCase
|
19 | 20 | {
|
@@ -43,6 +44,49 @@ public function getGenerateAbsoluteUrlData()
|
43 | 44 | );
|
44 | 45 | }
|
45 | 46 |
|
| 47 | + /** |
| 48 | + * @dataProvider getGenerateAbsoluteUrlRequestContextData |
| 49 | + */ |
| 50 | + public function testGenerateAbsoluteUrlWithRequestContext($path, $baseUrl, $host, $scheme, $httpPort, $httpsPort, $expected) |
| 51 | + { |
| 52 | + if (!class_exists('Symfony\Component\Routing\RequestContext')) { |
| 53 | + $this->markTestSkipped('The Routing component is needed to run tests that depend on its request context.'); |
| 54 | + } |
| 55 | + |
| 56 | + $requestContext = new RequestContext($baseUrl, 'GET', $host, $scheme, $httpPort, $httpsPort, $path); |
| 57 | + $extension = new HttpFoundationExtension(new RequestStack(), $requestContext); |
| 58 | + |
| 59 | + $this->assertEquals($expected, $extension->generateAbsoluteUrl($path)); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @dataProvider getGenerateAbsoluteUrlRequestContextData |
| 64 | + */ |
| 65 | + public function testGenerateAbsoluteUrlWithoutRequestAndRequestContext($path) |
| 66 | + { |
| 67 | + if (!class_exists('Symfony\Component\Routing\RequestContext')) { |
| 68 | + $this->markTestSkipped('The Routing component is needed to run tests that depend on its request context.'); |
| 69 | + } |
| 70 | + |
| 71 | + $extension = new HttpFoundationExtension(new RequestStack()); |
| 72 | + |
| 73 | + $this->assertEquals($path, $extension->generateAbsoluteUrl($path)); |
| 74 | + } |
| 75 | + |
| 76 | + public function getGenerateAbsoluteUrlRequestContextData() |
| 77 | + { |
| 78 | + return array( |
| 79 | + array('/foo.png', '/foo', 'localhost', 'http', 80, 443, 'http://localhost/foo.png'), |
| 80 | + array('foo.png', '/foo', 'localhost', 'http', 80, 443, 'http://localhost/foo/foo.png'), |
| 81 | + array('foo.png', '/foo/bar/', 'localhost', 'http', 80, 443, 'http://localhost/foo/bar/foo.png'), |
| 82 | + array('/foo.png', '/foo', 'localhost', 'https', 80, 443, 'https://localhost/foo.png'), |
| 83 | + array('foo.png', '/foo', 'localhost', 'https', 80, 443, 'https://localhost/foo/foo.png'), |
| 84 | + array('foo.png', '/foo/bar/', 'localhost', 'https', 80, 443, 'https://localhost/foo/bar/foo.png'), |
| 85 | + array('/foo.png', '/foo', 'localhost', 'http', 443, 80, 'http://localhost:443/foo.png'), |
| 86 | + array('/foo.png', '/foo', 'localhost', 'https', 443, 80, 'https://localhost:80/foo.png'), |
| 87 | + ); |
| 88 | + } |
| 89 | + |
46 | 90 | public function testGenerateAbsoluteUrlWithScriptFileName()
|
47 | 91 | {
|
48 | 92 | $request = Request::create('http://localhost/app/web/app_dev.php');
|
|
0 commit comments