public function HttpCacheTest::testValidatesCachedResponsesWithLastModifiedAndNoFreshnessInformation in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/http-kernel/Tests/HttpCache/HttpCacheTest.php \Symfony\Component\HttpKernel\Tests\HttpCache\HttpCacheTest::testValidatesCachedResponsesWithLastModifiedAndNoFreshnessInformation()
File
- vendor/
symfony/ http-kernel/ Tests/ HttpCache/ HttpCacheTest.php, line 738
Class
Namespace
Symfony\Component\HttpKernel\Tests\HttpCacheCode
public function testValidatesCachedResponsesWithLastModifiedAndNoFreshnessInformation() {
$time = \DateTime::createFromFormat('U', time());
$this
->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($time) {
$response->headers
->set('Cache-Control', 'public');
$response->headers
->set('Last-Modified', $time
->format(DATE_RFC2822));
if ($time
->format(DATE_RFC2822) == $request->headers
->get('IF_MODIFIED_SINCE')) {
$response
->setStatusCode(304);
$response
->setContent('');
}
});
// build initial request
$this
->request('GET', '/');
$this
->assertHttpKernelIsCalled();
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertNotNull($this->response->headers
->get('Last-Modified'));
$this
->assertNotNull($this->response->headers
->get('X-Content-Digest'));
$this
->assertEquals('Hello World', $this->response
->getContent());
$this
->assertTraceContains('miss');
$this
->assertTraceContains('store');
$this
->assertTraceNotContains('stale');
// build subsequent request; should be found but miss due to freshness
$this
->request('GET', '/');
$this
->assertHttpKernelIsCalled();
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertNotNull($this->response->headers
->get('Last-Modified'));
$this
->assertNotNull($this->response->headers
->get('X-Content-Digest'));
$this
->assertTrue($this->response->headers
->get('Age') <= 1);
$this
->assertEquals('Hello World', $this->response
->getContent());
$this
->assertTraceContains('stale');
$this
->assertTraceContains('valid');
$this
->assertTraceContains('store');
$this
->assertTraceNotContains('miss');
}