You are here

public function ResponseTest::testGetTtl 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::testGetTtl()

File

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

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
    ->assertLessThanOrEqual(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');
}