public function HttpCacheTest::testHitsCachedResponseWithSMaxAgeDirective

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php, line 553

Class

HttpCacheTest

Namespace

Symfony\Component\HttpKernel\Tests\HttpCache

Code

public function testHitsCachedResponseWithSMaxAgeDirective() {
  $time = \DateTime::createFromFormat('U', time() - 5);
  $this
    ->setNextResponse(200, array(
    'Date' => $time
      ->format(DATE_RFC2822),
    'Cache-Control' => 's-maxage=10, max-age=0',
  ));
  $this
    ->request('GET', '/');
  $this
    ->assertHttpKernelIsCalled();
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());
  $this
    ->assertNotNull($this->response->headers
    ->get('Date'));
  $this
    ->assertTraceContains('miss');
  $this
    ->assertTraceContains('store');
  $this
    ->assertEquals('Hello World', $this->response
    ->getContent());
  $this
    ->request('GET', '/');
  $this
    ->assertHttpKernelIsNotCalled();
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());
  $this
    ->assertTrue(strtotime($this->responses[0]->headers
    ->get('Date')) - strtotime($this->response->headers
    ->get('Date')) < 2);
  $this
    ->assertTrue($this->response->headers
    ->get('Age') > 0);
  $this
    ->assertNotNull($this->response->headers
    ->get('X-Content-Digest'));
  $this
    ->assertTraceContains('fresh');
  $this
    ->assertTraceNotContains('store');
  $this
    ->assertEquals('Hello World', $this->response
    ->getContent());
}