Skip to content
Permalink
Browse files

Implement withMustRevalidate()

  • Loading branch information...
markstory committed Dec 5, 2016
1 parent 966d3b7 commit f2f195f3464ceefb1416cf00968d51ca97304345
Showing with 73 additions and 3 deletions.
  1. +25 −0 src/Network/Response.php
  2. +48 −3 tests/TestCase/Network/ResponseTest.php
@@ -1376,6 +1376,31 @@ public function mustRevalidate($enable = null)
return array_key_exists('must-revalidate', $this->_cacheDirectives);
}
/**
* Create an instance with Cache-Control must-revalidate directive set.
*
* Sets the Cache-Control must-revalidate directive.
* must-revalidate indicates that the response should not be served
* stale by a cache under any circumstance without first revalidating
* with the origin.
*
* @param bool $enable If boolean sets or unsets the directive.
* @return static
*/
public function withMustRevalidate($enable)
{
$new = clone $this;
if ($enable) {
$new->_cacheDirectives['must-revalidate'] = true;
} else {
unset($new->_cacheDirectives['must-revalidate']);
}
$new->_setCacheControl();
return $new;
}
/**
* Helper method to generate a valid Cache-Control header from the options set
* in other methods
@@ -555,6 +555,16 @@ public function testCache()
$this->assertEquals($expected, $response->header());
}
/**
* Tests the withCache method
*
* @return void
*/
public function testWithCache()
{
$this->markTestIncomplete();
}
/**
* Tests the compress method
*
@@ -776,6 +786,16 @@ public function testExpires()
$this->assertEquals($time->format($format) . ' GMT', $response->getHeaderLine('Expires'));
}
/**
* Tests the withExpires method
*
* @return void
*/
public function testWithExpires()
{
$this->markTestIncomplete();
}
/**
* Tests setting the modification date
*
@@ -804,6 +824,16 @@ public function testModified()
$this->assertEquals($time->format($format) . ' GMT', $response->getHeaderLine('Last-Modified'));
}
/**
* Tests the withModified method
*
* @return void
*/
public function testWithModified()
{
$this->markTestIncomplete();
}
/**
* Tests setting of public/private Cache-Control directives
*
@@ -916,9 +946,6 @@ public function testSharedMaxAge()
*/
public function testMustRevalidate()
{
$response = $this->getMockBuilder('Cake\Network\Response')
->setMethods(['_sendHeader', '_sendContent'])
->getMock();
$response = new Response();
$this->assertFalse($response->mustRevalidate());
@@ -935,6 +962,24 @@ public function testMustRevalidate()
$this->assertEquals('s-maxage=3600, must-revalidate', $response->getHeaderLine('Cache-Control'));
}
/**
* Tests setting of must-revalidate Cache-Control directive
*
* @return void
*/
public function testWithMustRevalidate()
{
$response = new Response();
$this->assertFalse($response->hasHeader('Cache-Control'));
$new = $response->withMustRevalidate(true);
$this->assertFalse($response->hasHeader('Cache-Control'));
$this->assertEquals('must-revalidate', $new->getHeaderLine('Cache-Control'));
$new = $new->withMustRevalidate(false);
$this->assertEmpty($new->getHeaderLine('Cache-Control'));
}
/**
* Tests getting/setting the Vary header
*

0 comments on commit f2f195f

Please sign in to comment.
You can’t perform that action at this time.