public function ResponseTest::testGetTtl

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/ResponseTest.php, line 229

Class

ResponseTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testGetTtl() {
  $response = new Response();
  $this
    ->assertNull($response
    ->getTtl(), '->getTtl() returns null when no Expires or Cache-Control headers are present');
  $response = new Response();
  $response->headers
    ->set('Expires', $this
    ->createDateTimeOneHourLater()
    ->format(DATE_RFC2822));
  $this
    ->assertLessThan(1, 3600 - $response
    ->getTtl(), '->getTtl() uses the Expires header when no max-age is present');
  $response = new Response();
  $response->headers
    ->set('Expires', $this
    ->createDateTimeOneHourAgo()
    ->format(DATE_RFC2822));
  $this
    ->assertLessThan(0, $response
    ->getTtl(), '->getTtl() returns negative values when Expires is in past');
  $response = new Response();
  $response->headers
    ->set('Expires', $response
    ->getDate()
    ->format(DATE_RFC2822));
  $response->headers
    ->set('Age', 0);
  $this
    ->assertSame(0, $response
    ->getTtl(), '->getTtl() correctly handles zero');
  $response = new Response();
  $response->headers
    ->set('Cache-Control', 'max-age=60');
  $this
    ->assertLessThan(1, 60 - $response
    ->getTtl(), '->getTtl() uses Cache-Control max-age when present');
}