public function HttpCacheTest::testStoresMultipleResponsesWhenHeadersDiffer

File

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

Class

HttpCacheTest

Namespace

Symfony\Component\HttpKernel\Tests\HttpCache

Code

public function testStoresMultipleResponsesWhenHeadersDiffer() {
  $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
    ->assertEquals(1, $this->response->headers
    ->get('X-Response-Count'));
  $this
    ->request('GET', '/', array(
    'HTTP_ACCEPT' => 'text/html',
    'HTTP_USER_AGENT' => 'Bob/2.0',
  ));
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());
  $this
    ->assertTraceContains('miss');
  $this
    ->assertTraceContains('store');
  $this
    ->assertEquals('Bob/2.0', $this->response
    ->getContent());
  $this
    ->assertEquals(2, $this->response->headers
    ->get('X-Response-Count'));
  $this
    ->request('GET', '/', array(
    'HTTP_ACCEPT' => 'text/html',
    'HTTP_USER_AGENT' => 'Bob/1.0',
  ));
  $this
    ->assertTraceContains('fresh');
  $this
    ->assertEquals('Bob/1.0', $this->response
    ->getContent());
  $this
    ->assertEquals(1, $this->response->headers
    ->get('X-Response-Count'));
  $this
    ->request('GET', '/', array(
    'HTTP_ACCEPT' => 'text/html',
    'HTTP_USER_AGENT' => 'Bob/2.0',
  ));
  $this
    ->assertTraceContains('fresh');
  $this
    ->assertEquals('Bob/2.0', $this->response
    ->getContent());
  $this
    ->assertEquals(2, $this->response->headers
    ->get('X-Response-Count'));
  $this
    ->request('GET', '/', array(
    'HTTP_USER_AGENT' => 'Bob/2.0',
  ));
  $this
    ->assertTraceContains('miss');
  $this
    ->assertEquals('Bob/2.0', $this->response
    ->getContent());
  $this
    ->assertEquals(3, $this->response->headers
    ->get('X-Response-Count'));
}