Fixed absolute_url for absolute paths

This commit is contained in:
florianv 2015-02-20 00:13:09 +01:00
parent a630d87d57
commit 08aa7bc223
2 changed files with 17 additions and 2 deletions

View File

@ -67,10 +67,10 @@ class HttpFoundationExtension extends \Twig_Extension
$prefix = substr($prefix, 0, $pos).'/';
}
$path = $prefix.$path;
return $request->getUriForPath($prefix.$path);
}
return $request->getUriForPath($path);
return $request->getSchemeAndHttpHost().$path;
}
/**

View File

@ -43,6 +43,21 @@ class HttpFoundationExtensionTest extends \PHPUnit_Framework_TestCase
);
}
public function testGenerateAbsoluteUrlWithScriptFileName()
{
$request = Request::create('http://localhost/app/web/app_dev.php');
$request->server->set('SCRIPT_FILENAME', '/var/www/app/web/app_dev.php');
$stack = new RequestStack();
$stack->push($request);
$extension = new HttpFoundationExtension($stack);
$this->assertEquals(
'http://localhost/app/web/bundles/framework/css/structure.css',
$extension->generateAbsoluteUrl('/app/web/bundles/framework/css/structure.css')
);
}
/**
* @dataProvider getGenerateRelativePathData()
*/