merged branch Tobion/patch-8 (PR #6071)
This PR was merged into the 2.0 branch.
Commits
-------
29bfa13
small fix of #5984 when the container param is not set
Discussion
----------
small fix of #5984 when the container param is not set
this can happen when the config for the router is unset, but this method does not need to depend on routing. reading an unset config would raise an exception.
---------------------------------------------------------------------------
by Tobion at 2012-11-19T20:44:31Z
Ops, I guess it's wrong. Travis will probably confirm this in a moment.
I will correct that.
---------------------------------------------------------------------------
by flojon at 2012-11-20T22:40:07Z
Yeah you changed the logic...
---------------------------------------------------------------------------
by Tobion at 2012-11-21T14:42:48Z
ok it's fixed.
This commit is contained in:
commit
5acbddbdd7
@ -28,7 +28,7 @@ class RedirectController extends ContainerAware
|
|||||||
* It expects a route path parameter.
|
* It expects a route path parameter.
|
||||||
* By default, the response status code is 301.
|
* By default, the response status code is 301.
|
||||||
*
|
*
|
||||||
* If the route empty, the status code will be 410.
|
* If the route is empty, the status code will be 410.
|
||||||
* If the permanent path parameter is set, the status code will be 302.
|
* If the permanent path parameter is set, the status code will be 302.
|
||||||
*
|
*
|
||||||
* @param string $route The route pattern to redirect to
|
* @param string $route The route pattern to redirect to
|
||||||
@ -56,11 +56,11 @@ class RedirectController extends ContainerAware
|
|||||||
* If the path is empty, the status code will be 410.
|
* If the path is empty, the status code will be 410.
|
||||||
* If the permanent flag is set, the status code will be 302.
|
* If the permanent flag is set, the status code will be 302.
|
||||||
*
|
*
|
||||||
* @param string $path The path to redirect to
|
* @param string $path The path to redirect to
|
||||||
* @param Boolean $permanent Whether the redirect is permanent or not
|
* @param Boolean $permanent Whether the redirect is permanent or not
|
||||||
* @param Boolean $scheme The URL scheme (null to keep the current one)
|
* @param string|null $scheme The URL scheme (null to keep the current one)
|
||||||
* @param integer $httpPort The HTTP port
|
* @param integer|null $httpPort The HTTP port (null to keep the current one for the same scheme or the configured port in the container)
|
||||||
* @param integer $httpsPort The HTTPS port
|
* @param integer|null $httpsPort The HTTPS port (null to keep the current one for the same scheme or the configured port in the container)
|
||||||
*
|
*
|
||||||
* @return Response A Response instance
|
* @return Response A Response instance
|
||||||
*/
|
*/
|
||||||
@ -89,27 +89,25 @@ class RedirectController extends ContainerAware
|
|||||||
|
|
||||||
$port = '';
|
$port = '';
|
||||||
if ('http' === $scheme) {
|
if ('http' === $scheme) {
|
||||||
if ($httpPort == null) {
|
if (null === $httpPort) {
|
||||||
if ('http' === $request->getScheme()) {
|
if ('http' === $request->getScheme()) {
|
||||||
$httpPort = $request->getPort();
|
$httpPort = $request->getPort();
|
||||||
} else {
|
} elseif ($this->container->hasParameter('request_listener.http_port')) {
|
||||||
$httpPort = $this->container->getParameter('request_listener.http_port');
|
$httpPort = $this->container->getParameter('request_listener.http_port');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (null !== $httpPort && 80 != $httpPort) {
|
||||||
if ($httpPort != null && $httpPort != 80) {
|
|
||||||
$port = ":$httpPort";
|
$port = ":$httpPort";
|
||||||
}
|
}
|
||||||
} elseif ('https' === $scheme) {
|
} elseif ('https' === $scheme) {
|
||||||
if ($httpsPort == null) {
|
if (null === $httpsPort) {
|
||||||
if ('https' === $request->getScheme()) {
|
if ('https' === $request->getScheme()) {
|
||||||
$httpsPort = $request->getPort();
|
$httpsPort = $request->getPort();
|
||||||
} else {
|
} elseif ($this->container->hasParameter('request_listener.https_port')) {
|
||||||
$httpsPort = $this->container->getParameter('request_listener.https_port');
|
$httpsPort = $this->container->getParameter('request_listener.https_port');
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
if (null !== $httpsPort && 443 != $httpsPort) {
|
||||||
if ($httpsPort != null && $httpsPort != 443) {
|
|
||||||
$port = ":$httpsPort";
|
$port = ":$httpsPort";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,9 +75,7 @@ class RedirectControllerTest extends TestCase
|
|||||||
|
|
||||||
$returnResponse = $controller->redirectAction($route, $permanent);
|
$returnResponse = $controller->redirectAction($route, $permanent);
|
||||||
|
|
||||||
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
|
$this->assertRedirectUrl($returnResponse, $url);
|
||||||
|
|
||||||
$this->assertTrue($returnResponse->isRedirect($url));
|
|
||||||
$this->assertEquals($expectedCode, $returnResponse->getStatusCode());
|
$this->assertEquals($expectedCode, $returnResponse->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,9 +102,7 @@ class RedirectControllerTest extends TestCase
|
|||||||
$controller = new RedirectController();
|
$controller = new RedirectController();
|
||||||
$returnResponse = $controller->urlRedirectAction('http://foo.bar/');
|
$returnResponse = $controller->urlRedirectAction('http://foo.bar/');
|
||||||
|
|
||||||
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
|
$this->assertRedirectUrl($returnResponse, 'http://foo.bar/');
|
||||||
|
|
||||||
$this->assertEquals('http://foo.bar/', $returnResponse->headers->get('Location'));
|
|
||||||
$this->assertEquals(302, $returnResponse->getStatusCode());
|
$this->assertEquals(302, $returnResponse->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +175,7 @@ class RedirectControllerTest extends TestCase
|
|||||||
$this->assertRedirectUrl($returnValue, $expectedUrl);
|
$this->assertRedirectUrl($returnValue, $expectedUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createRequestObject($scheme, $host, $port, $baseUrl)
|
private function createRequestObject($scheme, $host, $port, $baseUrl)
|
||||||
{
|
{
|
||||||
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
|
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
|
||||||
$request
|
$request
|
||||||
@ -202,7 +198,7 @@ class RedirectControllerTest extends TestCase
|
|||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createRedirectController($request, $httpPort = null, $httpsPort = null)
|
private function createRedirectController(Request $request, $httpPort = null, $httpsPort = null)
|
||||||
{
|
{
|
||||||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||||
$container
|
$container
|
||||||
@ -210,16 +206,26 @@ class RedirectControllerTest extends TestCase
|
|||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('request'))
|
->with($this->equalTo('request'))
|
||||||
->will($this->returnValue($request));
|
->will($this->returnValue($request));
|
||||||
if ($httpPort != null) {
|
if (null !== $httpPort) {
|
||||||
$container
|
$container
|
||||||
->expects($this->at(1))
|
->expects($this->once())
|
||||||
|
->method('hasParameter')
|
||||||
|
->with($this->equalTo('request_listener.http_port'))
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$container
|
||||||
|
->expects($this->once())
|
||||||
->method('getParameter')
|
->method('getParameter')
|
||||||
->with($this->equalTo('request_listener.http_port'))
|
->with($this->equalTo('request_listener.http_port'))
|
||||||
->will($this->returnValue($httpPort));
|
->will($this->returnValue($httpPort));
|
||||||
}
|
}
|
||||||
if ($httpsPort != null) {
|
if (null !== $httpsPort) {
|
||||||
$container
|
$container
|
||||||
->expects($this->at(1))
|
->expects($this->once())
|
||||||
|
->method('hasParameter')
|
||||||
|
->with($this->equalTo('request_listener.https_port'))
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$container
|
||||||
|
->expects($this->once())
|
||||||
->method('getParameter')
|
->method('getParameter')
|
||||||
->with($this->equalTo('request_listener.https_port'))
|
->with($this->equalTo('request_listener.https_port'))
|
||||||
->will($this->returnValue($httpsPort));
|
->will($this->returnValue($httpsPort));
|
||||||
@ -231,8 +237,8 @@ class RedirectControllerTest extends TestCase
|
|||||||
return $controller;
|
return $controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function assertRedirectUrl($returnValue, $expectedUrl)
|
public function assertRedirectUrl(Response $returnResponse, $expectedUrl)
|
||||||
{
|
{
|
||||||
$this->assertTrue($returnValue->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnValue->headers->get('Location'));
|
$this->assertTrue($returnResponse->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnResponse->headers->get('Location'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user