You are here

public function HttpCacheTest::testValidatesPrivateResponsesCachedOnTheClient in Zircon Profile 8.0

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

File

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

Class

HttpCacheTest

Namespace

Symfony\Component\HttpKernel\Tests\HttpCache

Code

public function testValidatesPrivateResponsesCachedOnTheClient() {
  $this
    ->setNextResponse(200, array(), '', function ($request, $response) {
    $etags = preg_split('/\\s*,\\s*/', $request->headers
      ->get('IF_NONE_MATCH'));
    if ($request->cookies
      ->has('authenticated')) {
      $response->headers
        ->set('Cache-Control', 'private, no-store');
      $response
        ->setETag('"private tag"');
      if (in_array('"private tag"', $etags)) {
        $response
          ->setStatusCode(304);
      }
      else {
        $response
          ->setStatusCode(200);
        $response->headers
          ->set('Content-Type', 'text/plain');
        $response
          ->setContent('private data');
      }
    }
    else {
      $response->headers
        ->set('Cache-Control', 'public');
      $response
        ->setETag('"public tag"');
      if (in_array('"public tag"', $etags)) {
        $response
          ->setStatusCode(304);
      }
      else {
        $response
          ->setStatusCode(200);
        $response->headers
          ->set('Content-Type', 'text/plain');
        $response
          ->setContent('public data');
      }
    }
  });
  $this
    ->request('GET', '/');
  $this
    ->assertHttpKernelIsCalled();
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());
  $this
    ->assertEquals('"public tag"', $this->response->headers
    ->get('ETag'));
  $this
    ->assertEquals('public data', $this->response
    ->getContent());
  $this
    ->assertTraceContains('miss');
  $this
    ->assertTraceContains('store');
  $this
    ->request('GET', '/', array(), array(
    'authenticated' => '',
  ));
  $this
    ->assertHttpKernelIsCalled();
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());
  $this
    ->assertEquals('"private tag"', $this->response->headers
    ->get('ETag'));
  $this
    ->assertEquals('private data', $this->response
    ->getContent());
  $this
    ->assertTraceContains('stale');
  $this
    ->assertTraceContains('invalid');
  $this
    ->assertTraceNotContains('store');
}