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.
|
||||
* 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.
|
||||
*
|
||||
* @param string $route The route pattern to redirect to
|
||||
@ -58,9 +58,9 @@ class RedirectController extends ContainerAware
|
||||
*
|
||||
* @param string $path The path to redirect to
|
||||
* @param Boolean $permanent Whether the redirect is permanent or not
|
||||
* @param Boolean $scheme The URL scheme (null to keep the current one)
|
||||
* @param integer $httpPort The HTTP port
|
||||
* @param integer $httpsPort The HTTPS port
|
||||
* @param string|null $scheme The URL scheme (null to keep the current one)
|
||||
* @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|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
|
||||
*/
|
||||
@ -89,27 +89,25 @@ class RedirectController extends ContainerAware
|
||||
|
||||
$port = '';
|
||||
if ('http' === $scheme) {
|
||||
if ($httpPort == null) {
|
||||
if (null === $httpPort) {
|
||||
if ('http' === $request->getScheme()) {
|
||||
$httpPort = $request->getPort();
|
||||
} else {
|
||||
} elseif ($this->container->hasParameter('request_listener.http_port')) {
|
||||
$httpPort = $this->container->getParameter('request_listener.http_port');
|
||||
}
|
||||
}
|
||||
|
||||
if ($httpPort != null && $httpPort != 80) {
|
||||
if (null !== $httpPort && 80 != $httpPort) {
|
||||
$port = ":$httpPort";
|
||||
}
|
||||
} elseif ('https' === $scheme) {
|
||||
if ($httpsPort == null) {
|
||||
if (null === $httpsPort) {
|
||||
if ('https' === $request->getScheme()) {
|
||||
$httpsPort = $request->getPort();
|
||||
} else {
|
||||
} elseif ($this->container->hasParameter('request_listener.https_port')) {
|
||||
$httpsPort = $this->container->getParameter('request_listener.https_port');
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if ($httpsPort != null && $httpsPort != 443) {
|
||||
if (null !== $httpsPort && 443 != $httpsPort) {
|
||||
$port = ":$httpsPort";
|
||||
}
|
||||
}
|
||||
|
@ -75,9 +75,7 @@ class RedirectControllerTest extends TestCase
|
||||
|
||||
$returnResponse = $controller->redirectAction($route, $permanent);
|
||||
|
||||
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
|
||||
|
||||
$this->assertTrue($returnResponse->isRedirect($url));
|
||||
$this->assertRedirectUrl($returnResponse, $url);
|
||||
$this->assertEquals($expectedCode, $returnResponse->getStatusCode());
|
||||
}
|
||||
|
||||
@ -104,9 +102,7 @@ class RedirectControllerTest extends TestCase
|
||||
$controller = new RedirectController();
|
||||
$returnResponse = $controller->urlRedirectAction('http://foo.bar/');
|
||||
|
||||
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
|
||||
|
||||
$this->assertEquals('http://foo.bar/', $returnResponse->headers->get('Location'));
|
||||
$this->assertRedirectUrl($returnResponse, 'http://foo.bar/');
|
||||
$this->assertEquals(302, $returnResponse->getStatusCode());
|
||||
}
|
||||
|
||||
@ -179,7 +175,7 @@ class RedirectControllerTest extends TestCase
|
||||
$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
|
||||
@ -202,7 +198,7 @@ class RedirectControllerTest extends TestCase
|
||||
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
|
||||
@ -210,16 +206,26 @@ class RedirectControllerTest extends TestCase
|
||||
->method('get')
|
||||
->with($this->equalTo('request'))
|
||||
->will($this->returnValue($request));
|
||||
if ($httpPort != null) {
|
||||
if (null !== $httpPort) {
|
||||
$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')
|
||||
->with($this->equalTo('request_listener.http_port'))
|
||||
->will($this->returnValue($httpPort));
|
||||
}
|
||||
if ($httpsPort != null) {
|
||||
if (null !== $httpsPort) {
|
||||
$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')
|
||||
->with($this->equalTo('request_listener.https_port'))
|
||||
->will($this->returnValue($httpsPort));
|
||||
@ -231,8 +237,8 @@ class RedirectControllerTest extends TestCase
|
||||
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