Browse Source

Merge remote branch 'gordonslondon/http-foundation/response'

* gordonslondon/http-foundation/response:
  [HttpFoundation] merge Response::isRedirected() with Response::isRedirect() - Response::isRedirected() has been removed
Fabien Potencier 14 years ago
parent
commit
cb3390e9ae

+ 1 - 2
src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php

@@ -79,8 +79,7 @@ class RedirectControllerTest extends TestCase
 
 
         $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
         $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
 
 
-        $this->assertTrue($returnResponse->isRedirect());
-        $this->assertTrue($returnResponse->isRedirected($url));
+        $this->assertTrue($returnResponse->isRedirect($url));
         $this->assertEquals($expectedCode, $returnResponse->getStatusCode());
         $this->assertEquals($expectedCode, $returnResponse->getStatusCode());
     }
     }
 
 

+ 2 - 7
src/Symfony/Component/HttpFoundation/Response.php

@@ -729,9 +729,9 @@ class Response
         return 404 === $this->statusCode;
         return 404 === $this->statusCode;
     }
     }
 
 
-    public function isRedirect()
+    public function isRedirect($location = null)
     {
     {
-        return in_array($this->statusCode, array(201, 301, 302, 303, 307));
+        return in_array($this->statusCode, array(201, 301, 302, 303, 307)) && (null === $location ?: $location == $this->headers->get('Location'));
     }
     }
 
 
     public function isEmpty()
     public function isEmpty()
@@ -739,11 +739,6 @@ class Response
         return in_array($this->statusCode, array(201, 204, 304));
         return in_array($this->statusCode, array(201, 204, 304));
     }
     }
 
 
-    public function isRedirected($location)
-    {
-        return $this->isRedirect() && $location == $this->headers->get('Location');
-    }
-
     protected function fixContentType()
     protected function fixContentType()
     {
     {
         if (!$this->headers->has('Content-Type')) {
         if (!$this->headers->has('Content-Type')) {

+ 4 - 0
tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php

@@ -340,6 +340,10 @@ class ResponseTest extends \PHPUnit_Framework_TestCase
         $response = new Response('', 404);
         $response = new Response('', 404);
         $this->assertFalse($response->isRedirection());
         $this->assertFalse($response->isRedirection());
         $this->assertFalse($response->isRedirect());
         $this->assertFalse($response->isRedirect());
+
+        $response = new Response('', 301, array('Location' => '/good-uri'));
+        $this->assertFalse($response->isRedirect('/bad-uri'));
+        $this->assertTrue($response->isRedirect('/good-uri'));
     }
     }
 
 
     public function testIsNotFound()
     public function testIsNotFound()