Procházet zdrojové kódy

[HttpKernel] Added test

Jordi Boggiano před 14 roky
rodič
revize
0891c578b2

+ 20 - 0
tests/Symfony/Tests/Component/HttpKernel/HttpCache/HttpCacheTest.php

@@ -763,6 +763,26 @@ class HttpCacheTest extends HttpCacheTestCase
         $this->assertEquals(strlen('Hello World'), $this->response->headers->get('Content-Length'));
     }
 
+    public function testSendsNoContentWhenFresh()
+    {
+        $time = \DateTime::createFromFormat('U', time());
+        $that = $this;
+        $this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($that, $time)
+        {
+            $response->headers->set('Cache-Control', 'public, max-age=10');
+            $response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
+        });
+
+        $this->request('GET', '/');
+        $this->assertHttpKernelIsCalled();
+        $this->assertEquals('Hello World', $this->response->getContent());
+
+        $this->request('GET', '/', array('HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)));
+        $this->assertHttpKernelIsNotCalled();
+        $this->assertEquals(304, $this->response->getStatusCode());
+        $this->assertEquals('', $this->response->getContent());
+    }
+
     public function testInvalidatesCachedResponsesOnPost()
     {
         $this->setNextResponse(200, array(), 'Hello World', function ($request, $response)