You are here

public function ResponseTest::testSetCache in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Tests/ResponseTest.php \Symfony\Component\HttpFoundation\Tests\ResponseTest::testSetCache()

File

vendor/symfony/http-foundation/Tests/ResponseTest.php, line 559

Class

ResponseTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testSetCache() {
  $response = new Response();

  //array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public')
  try {
    $response
      ->setCache(array(
      'wrong option' => 'value',
    ));
    $this
      ->fail('->setCache() throws an InvalidArgumentException if an option is not supported');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf('InvalidArgumentException', $e, '->setCache() throws an InvalidArgumentException if an option is not supported');
    $this
      ->assertContains('"wrong option"', $e
      ->getMessage());
  }
  $options = array(
    'etag' => '"whatever"',
  );
  $response
    ->setCache($options);
  $this
    ->assertEquals($response
    ->getEtag(), '"whatever"');
  $now = new \DateTime();
  $options = array(
    'last_modified' => $now,
  );
  $response
    ->setCache($options);
  $this
    ->assertEquals($response
    ->getLastModified()
    ->getTimestamp(), $now
    ->getTimestamp());
  $options = array(
    'max_age' => 100,
  );
  $response
    ->setCache($options);
  $this
    ->assertEquals($response
    ->getMaxAge(), 100);
  $options = array(
    's_maxage' => 200,
  );
  $response
    ->setCache($options);
  $this
    ->assertEquals($response
    ->getMaxAge(), 200);
  $this
    ->assertTrue($response->headers
    ->hasCacheControlDirective('public'));
  $this
    ->assertFalse($response->headers
    ->hasCacheControlDirective('private'));
  $response
    ->setCache(array(
    'public' => true,
  ));
  $this
    ->assertTrue($response->headers
    ->hasCacheControlDirective('public'));
  $this
    ->assertFalse($response->headers
    ->hasCacheControlDirective('private'));
  $response
    ->setCache(array(
    'public' => false,
  ));
  $this
    ->assertFalse($response->headers
    ->hasCacheControlDirective('public'));
  $this
    ->assertTrue($response->headers
    ->hasCacheControlDirective('private'));
  $response
    ->setCache(array(
    'private' => true,
  ));
  $this
    ->assertFalse($response->headers
    ->hasCacheControlDirective('public'));
  $this
    ->assertTrue($response->headers
    ->hasCacheControlDirective('private'));
  $response
    ->setCache(array(
    'private' => false,
  ));
  $this
    ->assertTrue($response->headers
    ->hasCacheControlDirective('public'));
  $this
    ->assertFalse($response->headers
    ->hasCacheControlDirective('private'));
}