You are here

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

File

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

Class

HttpCacheTest

Namespace

Symfony\Component\HttpKernel\Tests\HttpCache

Code

public function testRespondsWith304OnlyIfIfNoneMatchAndIfModifiedSinceBothMatch() {
  $time = new \DateTime();
  $this
    ->setNextResponse(200, array(), '', function ($request, $response) use ($time) {
    $response
      ->setStatusCode(200);
    $response->headers
      ->set('ETag', '12345');
    $response->headers
      ->set('Last-Modified', $time
      ->format(DATE_RFC2822));
    $response->headers
      ->set('Content-Type', 'text/plain');
    $response
      ->setContent('Hello World');
  });

  // only ETag matches
  $t = \DateTime::createFromFormat('U', time() - 3600);
  $this
    ->request('GET', '/', array(
    'HTTP_IF_NONE_MATCH' => '12345',
    'HTTP_IF_MODIFIED_SINCE' => $t
      ->format(DATE_RFC2822),
  ));
  $this
    ->assertHttpKernelIsCalled();
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());

  // only Last-Modified matches
  $this
    ->request('GET', '/', array(
    'HTTP_IF_NONE_MATCH' => '1234',
    'HTTP_IF_MODIFIED_SINCE' => $time
      ->format(DATE_RFC2822),
  ));
  $this
    ->assertHttpKernelIsCalled();
  $this
    ->assertEquals(200, $this->response
    ->getStatusCode());

  // Both matches
  $this
    ->request('GET', '/', array(
    'HTTP_IF_NONE_MATCH' => '12345',
    'HTTP_IF_MODIFIED_SINCE' => $time
      ->format(DATE_RFC2822),
  ));
  $this
    ->assertHttpKernelIsCalled();
  $this
    ->assertEquals(304, $this->response
    ->getStatusCode());
}