From 47dfb9cb6a44526dd882614f05df8242eb2d9ce2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Dec 2012 10:29:04 +0100 Subject: [PATCH] [HttpFoundation] added some tests for the previous merge and removed dead code (closes #6037) --- .../Component/HttpFoundation/Response.php | 10 ++-------- .../HttpFoundation/Tests/ResponseTest.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 4d8992a7c3..7428b9a9c3 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -692,14 +692,8 @@ class Response return $age; } - $expiry = $this->getExpires(); - - if (!$expiry instanceof \DateTime && (-1 == $expiry || 0 === $expiry)) { - return $expiry; - } - - if (null !== $expiry) { - return $expiry->format('U') - $this->getDate()->format('U'); + if (null !== $this->getExpires()) { + return $this->getExpires()->format('U') - $this->getDate()->format('U'); } return null; diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php index c14dc4b83d..4fc93c33ef 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php @@ -351,6 +351,23 @@ class ResponseTest extends \PHPUnit_Framework_TestCase $this->assertEquals('', $response->getContent()); } + public function testPrepareSetsPragmaOnHttp10Only() + { + $request = Request::create('/', 'GET'); + $request->server->set('SERVER_PROTOCOL', 'HTTP/1.0'); + + $response = new Response('foo'); + $response->prepare($request); + $this->assertEquals('no-cache', $response->headers->get('pragma')); + $this->assertEquals('-1', $response->headers->get('expires')); + + $request->server->set('SERVER_PROTOCOL', 'HTTP/1.1'); + $response = new Response('foo'); + $response->prepare($request); + $this->assertFalse($response->headers->has('pragma')); + $this->assertFalse($response->headers->has('expires')); + } + public function testSetCache() { $response = new Response();