You are here

public function HttpCacheTest::testFetchesFullResponseWhenCacheStaleAndNoValidatorsPresent 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::testFetchesFullResponseWhenCacheStaleAndNoValidatorsPresent()

File

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

Class

HttpCacheTest

Namespace

Symfony\Component\HttpKernel\Tests\HttpCache

Code

public function testFetchesFullResponseWhenCacheStaleAndNoValidatorsPresent() {
  $time = \DateTime::createFromFormat('U', time() + 5);
  $this
    ->setNextResponse(200, array(
    'Cache-Control' => 'public',
    'Expires' => $time
      ->format(DATE_RFC2822),
  ));

  // build initial request
  $this
    ->request('GET', '/');
  $this
    ->assertHttpKernelIsCalled();
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());
  $this
    ->assertNotNull($this->response->headers
    ->get('Date'));
  $this
    ->assertNotNull($this->response->headers
    ->get('X-Content-Digest'));
  $this
    ->assertNotNull($this->response->headers
    ->get('Age'));
  $this
    ->assertTraceContains('miss');
  $this
    ->assertTraceContains('store');
  $this
    ->assertEquals('Hello World', $this->response
    ->getContent());

  # go in and play around with the cached metadata directly ...
  $values = $this
    ->getMetaStorageValues();
  $this
    ->assertCount(1, $values);
  $tmp = unserialize($values[0]);
  $time = \DateTime::createFromFormat('U', time());
  $tmp[0][1]['expires'] = $time
    ->format(DATE_RFC2822);
  $r = new \ReflectionObject($this->store);
  $m = $r
    ->getMethod('save');
  $m
    ->setAccessible(true);
  $m
    ->invoke($this->store, 'md' . hash('sha256', 'http://localhost/'), serialize($tmp));

  // build subsequent request; should be found but miss due to freshness
  $this
    ->request('GET', '/');
  $this
    ->assertHttpKernelIsCalled();
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());
  $this
    ->assertTrue($this->response->headers
    ->get('Age') <= 1);
  $this
    ->assertNotNull($this->response->headers
    ->get('X-Content-Digest'));
  $this
    ->assertTraceContains('stale');
  $this
    ->assertTraceNotContains('fresh');
  $this
    ->assertTraceNotContains('miss');
  $this
    ->assertTraceContains('store');
  $this
    ->assertEquals('Hello World', $this->response
    ->getContent());
}