Skip to content

Commit

Permalink
[FrameworkBundle] non-permanent redirect should be status code 404 ac…
Browse files Browse the repository at this point in the history
…cording to spec
  • Loading branch information
Tobion committed Aug 28, 2012
1 parent a1e6cfb commit 4c5bfab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Expand Up @@ -39,7 +39,7 @@ class RedirectController extends ContainerAware
public function redirectAction($route, $permanent = false)
{
if (!$route) {
return new Response(null, 410);
return new Response(null, $permanent ? 410 : 404);
}

$attributes = $this->container->get('request')->attributes->get('_route_params');
Expand Down Expand Up @@ -67,7 +67,7 @@ public function redirectAction($route, $permanent = false)
public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443)
{
if (!$path) {
return new Response(null, 410);
return new Response(null, $permanent ? 410 : 404);
}

$statusCode = $permanent ? 301 : 302;
Expand Down
Expand Up @@ -29,11 +29,13 @@ public function testEmptyRoute()
$controller = new RedirectController();
$controller->setContainer($container);

$returnResponse = $controller->redirectAction('');

$returnResponse = $controller->redirectAction('', true);
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);

$this->assertEquals(410, $returnResponse->getStatusCode());

$returnResponse = $controller->redirectAction('', false);
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
$this->assertEquals(404, $returnResponse->getStatusCode());
}

/**
Expand Down Expand Up @@ -102,11 +104,14 @@ public function provider()
public function testEmptyPath()
{
$controller = new RedirectController();
$returnResponse = $controller->urlRedirectAction('');

$returnResponse = $controller->urlRedirectAction('', true);
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);

$this->assertEquals(410, $returnResponse->getStatusCode());

$returnResponse = $controller->urlRedirectAction('', false);
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
$this->assertEquals(404, $returnResponse->getStatusCode());
}

public function testFullURL()
Expand Down

0 comments on commit 4c5bfab

Please sign in to comment.