Skip to content

Commit 0891c57

Browse files
committed
[HttpKernel] Added test
1 parent 1350645 commit 0891c57

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/Symfony/Tests/Component/HttpKernel/HttpCache/HttpCacheTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,26 @@ public function testUsesCacheToRespondToHeadRequestsWhenFresh()
763763
$this->assertEquals(strlen('Hello World'), $this->response->headers->get('Content-Length'));
764764
}
765765

766+
public function testSendsNoContentWhenFresh()
767+
{
768+
$time = \DateTime::createFromFormat('U', time());
769+
$that = $this;
770+
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($that, $time)
771+
{
772+
$response->headers->set('Cache-Control', 'public, max-age=10');
773+
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
774+
});
775+
776+
$this->request('GET', '/');
777+
$this->assertHttpKernelIsCalled();
778+
$this->assertEquals('Hello World', $this->response->getContent());
779+
780+
$this->request('GET', '/', array('HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)));
781+
$this->assertHttpKernelIsNotCalled();
782+
$this->assertEquals(304, $this->response->getStatusCode());
783+
$this->assertEquals('', $this->response->getContent());
784+
}
785+
766786
public function testInvalidatesCachedResponsesOnPost()
767787
{
768788
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response)

0 commit comments

Comments
 (0)