Added test when TTL has expired

This commit is contained in:
alquerci 2013-12-31 17:23:37 +01:00 committed by Fabien Potencier
parent 792b956540
commit bc42dae162
1 changed files with 83 additions and 0 deletions

View File

@ -595,6 +595,89 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertEquals('Hello World', $this->response->getContent());
}
public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpired()
{
$this->setNextResponse();
$this->cacheConfig['default_ttl'] = 2;
$this->request('GET', '/');
$this->assertHttpKernelIsCalled();
$this->assertTraceContains('miss');
$this->assertTraceContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control'));
$this->cacheConfig['default_ttl'] = 2;
$this->request('GET', '/');
$this->assertHttpKernelIsNotCalled();
$this->assertEquals(200, $this->response->getStatusCode());
$this->assertTraceContains('fresh');
$this->assertTraceNotContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
sleep(4);
$this->cacheConfig['default_ttl'] = 2;
$this->request('GET', '/');
$this->assertHttpKernelIsCalled();
$this->assertEquals(200, $this->response->getStatusCode());
$this->assertTraceContains('stale');
$this->assertTraceContains('invalid');
$this->assertTraceContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->cacheConfig['default_ttl'] = 2;
$this->request('GET', '/');
$this->assertHttpKernelIsNotCalled();
$this->assertEquals(200, $this->response->getStatusCode());
$this->assertTraceContains('fresh');
$this->assertTraceNotContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
}
public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpiredWithStatus304()
{
$this->setNextResponse();
$this->cacheConfig['default_ttl'] = 2;
$this->request('GET', '/');
$this->assertHttpKernelIsCalled();
$this->assertTraceContains('miss');
$this->assertTraceContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control'));
$this->cacheConfig['default_ttl'] = 2;
$this->request('GET', '/');
$this->assertHttpKernelIsNotCalled();
$this->assertEquals(200, $this->response->getStatusCode());
$this->assertTraceContains('fresh');
$this->assertTraceNotContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
sleep(4);
$this->setNextResponse(304);
$this->cacheConfig['default_ttl'] = 2;
$this->request('GET', '/');
$this->assertHttpKernelIsCalled();
$this->assertEquals(200, $this->response->getStatusCode());
$this->assertTraceContains('stale');
$this->assertTraceContains('valid');
$this->assertTraceContains('store');
$this->assertTraceNotContains('miss');
$this->assertEquals('Hello World', $this->response->getContent());
$this->cacheConfig['default_ttl'] = 2;
$this->request('GET', '/');
$this->assertHttpKernelIsNotCalled();
$this->assertEquals(200, $this->response->getStatusCode());
$this->assertTraceContains('fresh');
$this->assertTraceNotContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
}
public function testDoesNotAssignDefaultTtlWhenResponseHasMustRevalidateDirective()
{
$this->setNextResponse(200, array('Cache-Control' => 'must-revalidate'));