You are here

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

File

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

Class

HttpCacheTest

Namespace

Symfony\Component\HttpKernel\Tests\HttpCache

Code

public function testServesFromCacheWhenHeadersMatch() {
  $count = 0;
  $this
    ->setNextResponse(200, array(
    'Cache-Control' => 'max-age=10000',
  ), '', function ($request, $response) use (&$count) {
    $response->headers
      ->set('Vary', 'Accept User-Agent Foo');
    $response->headers
      ->set('Cache-Control', 'public, max-age=10');
    $response->headers
      ->set('X-Response-Count', ++$count);
    $response
      ->setContent($request->headers
      ->get('USER_AGENT'));
  });
  $this
    ->request('GET', '/', array(
    'HTTP_ACCEPT' => 'text/html',
    'HTTP_USER_AGENT' => 'Bob/1.0',
  ));
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());
  $this
    ->assertEquals('Bob/1.0', $this->response
    ->getContent());
  $this
    ->assertTraceContains('miss');
  $this
    ->assertTraceContains('store');
  $this
    ->request('GET', '/', array(
    'HTTP_ACCEPT' => 'text/html',
    'HTTP_USER_AGENT' => 'Bob/1.0',
  ));
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());
  $this
    ->assertEquals('Bob/1.0', $this->response
    ->getContent());
  $this
    ->assertTraceContains('fresh');
  $this
    ->assertTraceNotContains('store');
  $this
    ->assertNotNull($this->response->headers
    ->get('X-Content-Digest'));
}