You are here

public function HttpCacheTest::testHitsCachedResponsesWithExpiresHeader in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/Tests/HttpCache/HttpCacheTest.php \Symfony\Component\HttpKernel\Tests\HttpCache\HttpCacheTest::testHitsCachedResponsesWithExpiresHeader()

File

vendor/symfony/http-kernel/Tests/HttpCache/HttpCacheTest.php, line 491

Class

HttpCacheTest

Namespace

Symfony\Component\HttpKernel\Tests\HttpCache

Code

public function testHitsCachedResponsesWithExpiresHeader() {
  $time1 = \DateTime::createFromFormat('U', time() - 5);
  $time2 = \DateTime::createFromFormat('U', time() + 5);
  $this
    ->setNextResponse(200, array(
    'Cache-Control' => 'public',
    'Date' => $time1
      ->format(DATE_RFC2822),
    'Expires' => $time2
      ->format(DATE_RFC2822),
  ));
  $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());
}