|
|
@@ -17,6 +17,7 @@
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
*/
|
|
|
App::uses('CakeResponse', 'Network');
|
|
|
+App::uses('CakeRequest', 'Network');
|
|
|
|
|
|
class CakeResponseTest extends CakeTestCase {
|
|
|
|
|
|
@@ -182,11 +183,13 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$response->expects($this->at(0))
|
|
|
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
|
|
$response->expects($this->at(1))
|
|
|
- ->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
|
|
- $response->expects($this->at(2))
|
|
|
->method('_sendHeader')->with('Content-Language', 'es');
|
|
|
- $response->expects($this->at(3))
|
|
|
+ $response->expects($this->at(2))
|
|
|
->method('_sendHeader')->with('WWW-Authenticate', 'Negotiate');
|
|
|
+ $response->expects($this->at(3))
|
|
|
+ ->method('_sendHeader')->with('Content-Length', 17);
|
|
|
+ $response->expects($this->at(4))
|
|
|
+ ->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
|
|
$response->send();
|
|
|
}
|
|
|
|
|
|
@@ -202,7 +205,9 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$response->expects($this->at(0))
|
|
|
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
|
|
$response->expects($this->at(1))
|
|
|
- ->method('_sendHeader')->with('Content-Type', 'audio/mpeg; charset=UTF-8');
|
|
|
+ ->method('_sendHeader')->with('Content-Length', 17);
|
|
|
+ $response->expects($this->at(2))
|
|
|
+ ->method('_sendHeader')->with('Content-Type', 'audio/mpeg');
|
|
|
$response->send();
|
|
|
}
|
|
|
|
|
|
@@ -218,7 +223,9 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$response->expects($this->at(0))
|
|
|
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
|
|
$response->expects($this->at(1))
|
|
|
- ->method('_sendHeader')->with('Content-Type', 'audio/mpeg; charset=UTF-8');
|
|
|
+ ->method('_sendHeader')->with('Content-Length', 17);
|
|
|
+ $response->expects($this->at(2))
|
|
|
+ ->method('_sendHeader')->with('Content-Type', 'audio/mpeg');
|
|
|
$response->send();
|
|
|
}
|
|
|
|
|
|
@@ -232,9 +239,9 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$response->expects($this->at(0))
|
|
|
->method('_sendHeader')->with('HTTP/1.1 302 Found');
|
|
|
$response->expects($this->at(1))
|
|
|
- ->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
|
|
- $response->expects($this->at(2))
|
|
|
->method('_sendHeader')->with('Location', 'http://www.example.com');
|
|
|
+ $response->expects($this->at(2))
|
|
|
+ ->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
|
|
$response->send();
|
|
|
}
|
|
|
|
|
|
@@ -247,8 +254,7 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$expected = array(
|
|
|
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
|
|
|
'Last-Modified' => gmdate("D, d M Y H:i:s") . " GMT",
|
|
|
- 'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
|
|
|
- 'Pragma' => 'no-cache'
|
|
|
+ 'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
|
|
|
);
|
|
|
$response->disableCache();
|
|
|
$this->assertEquals($response->header(), $expected);
|
|
|
@@ -261,13 +267,13 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
public function testCache() {
|
|
|
$response = new CakeResponse();
|
|
|
$since = time();
|
|
|
- $time = '+1 day';
|
|
|
+ $time = new DateTime('+1 day', new DateTimeZone('UTC'));
|
|
|
+ $response->expires('+1 day');
|
|
|
$expected = array(
|
|
|
'Date' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
|
|
|
- 'Last-Modified' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
|
|
|
- 'Expires' => gmdate("D, j M Y H:i:s", strtotime($time)) . " GMT",
|
|
|
- 'Cache-Control' => 'public, max-age=' . (strtotime($time) - time()),
|
|
|
- 'Pragma' => 'cache'
|
|
|
+ 'Last-Modified' => gmdate("D, j M Y H:i:s ", $since) . 'GMT',
|
|
|
+ 'Expires' => $time->format('D, j M Y H:i:s') . ' GMT',
|
|
|
+ 'Cache-Control' => 'public, max-age=' . ($time->format('U') - time())
|
|
|
);
|
|
|
$response->cache($since);
|
|
|
$this->assertEquals($response->header(), $expected);
|
|
|
@@ -277,10 +283,9 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$time = '+5 day';
|
|
|
$expected = array(
|
|
|
'Date' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
|
|
|
- 'Last-Modified' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
|
|
|
+ 'Last-Modified' => gmdate("D, j M Y H:i:s ", $since) . 'GMT',
|
|
|
'Expires' => gmdate("D, j M Y H:i:s", strtotime($time)) . " GMT",
|
|
|
- 'Cache-Control' => 'public, max-age=' . (strtotime($time) - time()),
|
|
|
- 'Pragma' => 'cache'
|
|
|
+ 'Cache-Control' => 'public, max-age=' . (strtotime($time) - time())
|
|
|
);
|
|
|
$response->cache($since, $time);
|
|
|
$this->assertEquals($response->header(), $expected);
|
|
|
@@ -290,10 +295,9 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$time = time();
|
|
|
$expected = array(
|
|
|
'Date' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
|
|
|
- 'Last-Modified' => gmdate("D, j M Y G:i:s ", $since) . 'GMT',
|
|
|
+ 'Last-Modified' => gmdate("D, j M Y H:i:s ", $since) . 'GMT',
|
|
|
'Expires' => gmdate("D, j M Y H:i:s", $time) . " GMT",
|
|
|
- 'Cache-Control' => 'public, max-age=0',
|
|
|
- 'Pragma' => 'cache'
|
|
|
+ 'Cache-Control' => 'public, max-age=0'
|
|
|
);
|
|
|
$response->cache($since, $time);
|
|
|
$this->assertEquals($response->header(), $expected);
|
|
|
@@ -439,9 +443,9 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$response->expects($this->once())->method('_sendContent')->with('the response body');
|
|
|
$response->expects($this->at(0))
|
|
|
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
|
|
- $response->expects($this->at(1))
|
|
|
- ->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
|
|
$response->expects($this->at(2))
|
|
|
+ ->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
|
|
+ $response->expects($this->at(1))
|
|
|
->method('_sendHeader')->with('Content-Length', strlen('the response body'));
|
|
|
$response->send();
|
|
|
|
|
|
@@ -451,9 +455,9 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$response->expects($this->once())->method('_sendContent')->with($body);
|
|
|
$response->expects($this->at(0))
|
|
|
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
|
|
- $response->expects($this->at(1))
|
|
|
- ->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
|
|
$response->expects($this->at(2))
|
|
|
+ ->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
|
|
+ $response->expects($this->at(1))
|
|
|
->method('_sendHeader')->with('Content-Length', 116);
|
|
|
$response->send();
|
|
|
|
|
|
@@ -471,7 +475,7 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$response->header('Content-Length', 1);
|
|
|
$response->expects($this->never())->method('outputCompressed');
|
|
|
$response->expects($this->once())->method('_sendContent')->with($body);
|
|
|
- $response->expects($this->at(2))
|
|
|
+ $response->expects($this->at(1))
|
|
|
->method('_sendHeader')->with('Content-Length', 1);
|
|
|
$response->send();
|
|
|
|
|
|
@@ -494,10 +498,427 @@ class CakeResponseTest extends CakeTestCase {
|
|
|
$response->expects($this->at(0))
|
|
|
->method('_sendHeader')->with('HTTP/1.1 200 OK');
|
|
|
$response->expects($this->at(1))
|
|
|
- ->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
|
|
- $response->expects($this->at(2))
|
|
|
->method('_sendHeader')->with('Content-Length', strlen($goofyOutput) + 116);
|
|
|
+ $response->expects($this->at(2))
|
|
|
+ ->method('_sendHeader')->with('Content-Type', 'text/html; charset=UTF-8');
|
|
|
$response->send();
|
|
|
ob_end_clean();
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests getting/setting the protocol
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testProtocol() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->protocol('HTTP/1.0');
|
|
|
+ $this->assertEquals('HTTP/1.0', $response->protocol());
|
|
|
+ $response->expects($this->at(0))
|
|
|
+ ->method('_sendHeader')->with('HTTP/1.0 200 OK');
|
|
|
+ $response->send();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests getting/setting the Content-Length
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testLength() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->length(100);
|
|
|
+ $this->assertEquals(100, $response->length());
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Content-Length', 100);
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->length(false);
|
|
|
+ $this->assertFalse($response->length());
|
|
|
+ $response->expects($this->exactly(2))
|
|
|
+ ->method('_sendHeader');
|
|
|
+ $response->send();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests that the response body is unset if the status code is 304 or 204
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testUnmodifiedContent() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->body('This is a body');
|
|
|
+ $response->statusCode(204);
|
|
|
+ $response->expects($this->once())
|
|
|
+ ->method('_sendContent')->with('');
|
|
|
+ $response->send();
|
|
|
+ $this->assertFalse(array_key_exists('Content-Type', $response->header()));
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->body('This is a body');
|
|
|
+ $response->statusCode(304);
|
|
|
+ $response->expects($this->once())
|
|
|
+ ->method('_sendContent')->with('');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->body('This is a body');
|
|
|
+ $response->statusCode(200);
|
|
|
+ $response->expects($this->once())
|
|
|
+ ->method('_sendContent')->with('This is a body');
|
|
|
+ $response->send();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests setting the expiration date
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testExpires() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $now = new DateTime('now', new DateTimeZone('America/Los_Angeles'));
|
|
|
+ $response->expires($now);
|
|
|
+ $now->setTimeZone(new DateTimeZone('UTC'));
|
|
|
+ $this->assertEquals($now->format('D, j M Y H:i:s') . ' GMT', $response->expires());
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Expires', $now->format('D, j M Y H:i:s') . ' GMT');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $now = time();
|
|
|
+ $response->expires($now);
|
|
|
+ $this->assertEquals(gmdate('D, j M Y H:i:s', $now) . ' GMT', $response->expires());
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Expires', gmdate('D, j M Y H:i:s', $now) . ' GMT');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $time = new DateTime('+1 day', new DateTimeZone('UTC'));
|
|
|
+ $response->expires('+1 day');
|
|
|
+ $this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->expires());
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Expires', $time->format('D, j M Y H:i:s') . ' GMT');
|
|
|
+ $response->send();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests setting the modification date
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testModified() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $now = new DateTime('now', new DateTimeZone('America/Los_Angeles'));
|
|
|
+ $response->modified($now);
|
|
|
+ $now->setTimeZone(new DateTimeZone('UTC'));
|
|
|
+ $this->assertEquals($now->format('D, j M Y H:i:s') . ' GMT', $response->modified());
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Last-Modified', $now->format('D, j M Y H:i:s') . ' GMT');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $now = time();
|
|
|
+ $response->modified($now);
|
|
|
+ $this->assertEquals(gmdate('D, j M Y H:i:s', $now) . ' GMT', $response->modified());
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Last-Modified', gmdate('D, j M Y H:i:s', $now) . ' GMT');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $time = new DateTime('+1 day', new DateTimeZone('UTC'));
|
|
|
+ $response->modified('+1 day');
|
|
|
+ $this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Last-Modified', $time->format('D, j M Y H:i:s') . ' GMT');
|
|
|
+ $response->send();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests setting of public/private Cache-Control directives
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testSharable() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $this->assertNull($response->sharable());
|
|
|
+ $response->sharable(true);
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('public', $headers['Cache-Control']);
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Cache-Control', 'public');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->sharable(false);
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('private', $headers['Cache-Control']);
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Cache-Control', 'private');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->sharable(true);
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('public', $headers['Cache-Control']);
|
|
|
+ $response->sharable(false);
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('private', $headers['Cache-Control']);
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Cache-Control', 'private');
|
|
|
+ $response->send();
|
|
|
+ $this->assertFalse($response->sharable());
|
|
|
+ $response->sharable(true);
|
|
|
+ $this->assertTrue($response->sharable());
|
|
|
+
|
|
|
+ $response = new CakeResponse;
|
|
|
+ $response->sharable(true, 3600);
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('public, s-maxage=3600', $headers['Cache-Control']);
|
|
|
+
|
|
|
+ $response = new CakeResponse;
|
|
|
+ $response->sharable(false, 3600);
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('private, max-age=3600', $headers['Cache-Control']);
|
|
|
+ $response->send();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests setting of max-age Cache-Control directive
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testMaxAge() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $this->assertNull($response->maxAge());
|
|
|
+ $response->maxAge(3600);
|
|
|
+ $this->assertEquals(3600, $response->maxAge());
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('max-age=3600', $headers['Cache-Control']);
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Cache-Control', 'max-age=3600');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->maxAge(3600);
|
|
|
+ $response->sharable(false);
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('max-age=3600, private', $headers['Cache-Control']);
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Cache-Control', 'max-age=3600, private');
|
|
|
+ $response->send();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests setting of s-maxage Cache-Control directive
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testSharedMaxAge() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $this->assertNull($response->maxAge());
|
|
|
+ $response->sharedMaxAge(3600);
|
|
|
+ $this->assertEquals(3600, $response->sharedMaxAge());
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('s-maxage=3600', $headers['Cache-Control']);
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Cache-Control', 's-maxage=3600');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->sharedMaxAge(3600);
|
|
|
+ $response->sharable(true);
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('s-maxage=3600, public', $headers['Cache-Control']);
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Cache-Control', 's-maxage=3600, public');
|
|
|
+ $response->send();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests setting of must-revalidate Cache-Control directive
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testMustRevalidate() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $this->assertFalse($response->mustRevalidate());
|
|
|
+ $response->mustRevalidate(true);
|
|
|
+ $this->assertTrue($response->mustRevalidate());
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('must-revalidate', $headers['Cache-Control']);
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Cache-Control', 'must-revalidate');
|
|
|
+ $response->send();
|
|
|
+ $response->mustRevalidate(false);
|
|
|
+ $this->assertFalse($response->mustRevalidate());
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->sharedMaxAge(3600);
|
|
|
+ $response->mustRevalidate(true);
|
|
|
+ $headers = $response->header();
|
|
|
+ $this->assertEquals('s-maxage=3600, must-revalidate', $headers['Cache-Control']);
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Cache-Control', 's-maxage=3600, must-revalidate');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests getting/setting the Vary header
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testVary() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->vary('Accept-encoding');
|
|
|
+ $this->assertEquals(array('Accept-encoding'), $response->vary());
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Vary', 'Accept-encoding');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->vary(array('Accept-language', 'Accept-encoding'));
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Vary', 'Accept-language, Accept-encoding');
|
|
|
+ $response->send();
|
|
|
+ $this->assertEquals(array('Accept-language', 'Accept-encoding'), $response->vary());
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests getting/setting the Etag header
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testEtag() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->etag('something');
|
|
|
+ $this->assertEquals('"something"', $response->etag());
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Etag', '"something"');
|
|
|
+ $response->send();
|
|
|
+
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->etag('something', true);
|
|
|
+ $this->assertEquals('W/"something"', $response->etag());
|
|
|
+ $response->expects($this->at(1))
|
|
|
+ ->method('_sendHeader')->with('Etag', 'W/"something"');
|
|
|
+ $response->send();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Tests that the response is able to be marked as not modified
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testNotModified() {
|
|
|
+ $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
|
|
+ $response->body('something');
|
|
|
+ $response->statusCode(200);
|
|
|
+ $response->length(100);
|
|
|
+ $response->modified('now');
|
|
|
+ $response->notModified();
|
|
|
+
|
|
|
+ $this->assertEmpty($response->header());
|
|
|
+ $this->assertEmpty($response->body());
|
|
|
+ $this->assertEquals(304, $response->statusCode());
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test checkNotModified method
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ **/
|
|
|
+ public function testCheckNotModifiedByEtagStar() {
|
|
|
+ $_SERVER['HTTP_IF_NONE_MATCH'] = '*';
|
|
|
+ $response = $this->getMock('CakeResponse', array('notModified'));
|
|
|
+ $response->etag('something');
|
|
|
+ $response->expects($this->once())->method('notModified');
|
|
|
+ $response->checkNotModified(new CakeRequest);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test checkNotModified method
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ **/
|
|
|
+ public function testCheckNotModifiedByEtagExact() {
|
|
|
+ $_SERVER['HTTP_IF_NONE_MATCH'] = 'W/"something", "other"';
|
|
|
+ $response = $this->getMock('CakeResponse', array('notModified'));
|
|
|
+ $response->etag('something', true);
|
|
|
+ $response->expects($this->once())->method('notModified');
|
|
|
+ $this->assertTrue($response->checkNotModified(new CakeRequest));
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test checkNotModified method
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ **/
|
|
|
+ public function testCheckNotModifiedByEtagAndTime() {
|
|
|
+ $_SERVER['HTTP_IF_NONE_MATCH'] = 'W/"something", "other"';
|
|
|
+ $_SERVER['HTTP_IF_MODIFIED_SINCE'] = '2012-01-01 00:00:00';
|
|
|
+ $response = $this->getMock('CakeResponse', array('notModified'));
|
|
|
+ $response->etag('something', true);
|
|
|
+ $response->modified('2012-01-01 00:00:00');
|
|
|
+ $response->expects($this->once())->method('notModified');
|
|
|
+ $this->assertTrue($response->checkNotModified(new CakeRequest));
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test checkNotModified method
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ **/
|
|
|
+ public function testCheckNotModifiedByEtagAndTimeMismatch() {
|
|
|
+ $_SERVER['HTTP_IF_NONE_MATCH'] = 'W/"something", "other"';
|
|
|
+ $_SERVER['HTTP_IF_MODIFIED_SINCE'] = '2012-01-01 00:00:00';
|
|
|
+ $response = $this->getMock('CakeResponse', array('notModified'));
|
|
|
+ $response->etag('something', true);
|
|
|
+ $response->modified('2012-01-01 00:00:01');
|
|
|
+ $response->expects($this->never())->method('notModified');
|
|
|
+ $this->assertFalse($response->checkNotModified(new CakeRequest));
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test checkNotModified method
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ **/
|
|
|
+ public function testCheckNotModifiedByEtagMismatch() {
|
|
|
+ $_SERVER['HTTP_IF_NONE_MATCH'] = 'W/"something-else", "other"';
|
|
|
+ $_SERVER['HTTP_IF_MODIFIED_SINCE'] = '2012-01-01 00:00:00';
|
|
|
+ $response = $this->getMock('CakeResponse', array('notModified'));
|
|
|
+ $response->etag('something', true);
|
|
|
+ $response->modified('2012-01-01 00:00:00');
|
|
|
+ $response->expects($this->never())->method('notModified');
|
|
|
+ $this->assertFalse($response->checkNotModified(new CakeRequest));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test checkNotModified method
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ **/
|
|
|
+ public function testCheckNotModifiedByTime() {
|
|
|
+ $_SERVER['HTTP_IF_MODIFIED_SINCE'] = '2012-01-01 00:00:00';
|
|
|
+ $response = $this->getMock('CakeResponse', array('notModified'));
|
|
|
+ $response->modified('2012-01-01 00:00:00');
|
|
|
+ $response->expects($this->once())->method('notModified');
|
|
|
+ $this->assertTrue($response->checkNotModified(new CakeRequest));
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test checkNotModified method
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ **/
|
|
|
+ public function testCheckNotModifiedNoHints() {
|
|
|
+ $_SERVER['HTTP_IF_NONE_MATCH'] = 'W/"something", "other"';
|
|
|
+ $_SERVER['HTTP_IF_MODIFIED_SINCE'] = '2012-01-01 00:00:00';
|
|
|
+ $response = $this->getMock('CakeResponse', array('notModified'));
|
|
|
+ $response->expects($this->never())->method('notModified');
|
|
|
+ $this->assertFalse($response->checkNotModified(new CakeRequest));
|
|
|
+ }
|
|
|
}
|