Permalink
Browse files

Adding test for encoded messages in \action\Response.

Reorganizing some tests to make it clearer what is tested.
  • Loading branch information...
1 parent 62ad34d commit 4b33020095c89469ea9ce5603fd8ee3d4b91977a @gwoo gwoo committed Sep 27, 2012
Showing with 35 additions and 14 deletions.
  1. +2 −1 action/Response.php
  2. +33 −13 tests/cases/action/ResponseTest.php
View
@@ -38,7 +38,8 @@ public function __construct(array $config = array()) {
'buffer' => 8192,
'location' => null,
'status' => 0,
- 'request' => null
+ 'request' => null,
+ 'decode' => false
);
parent::__construct($config + $defaults);
}
@@ -28,20 +28,40 @@ public function testTypeManipulation() {
$this->assertEqual(false, $this->response->type());
}
- public function testResponseRendering() {
+ public function testResponseRenderString() {
$this->response->body = 'Document body';
ob_start();
$this->response->render();
$result = ob_get_clean();
- $this->assertEqual('Document body', $result);
- $this->assertEqual(array('HTTP/1.1 200 OK'), $this->response->testHeaders);
+ $this->assertIdentical('Document body', $result);
+ $this->assertIdentical(array('HTTP/1.1 200 OK'), $this->response->testHeaders);
+ }
+
+ public function testResponseRenderJson() {
+ $this->response->type('json');
+ $this->response->body[] = '{"message": "Hello World"}';
+
+ ob_start();
+ $this->response->render();
+ $result = ob_get_clean();
+ $this->assertIdentical('{"message": "Hello World"}', $result);
+ $this->assertIdentical('HTTP/1.1 200 OK', $this->response->testHeaders[0]);
+ }
+
+ public function testResponseToString() {
+ $this->response->type(false);
+ $this->response->body = 'Document body';
ob_start();
echo $this->response;
$result = ob_get_clean();
- $this->assertEqual('Document body', $result);
- $this->assertEqual(array('HTTP/1.1 200 OK'), $this->response->testHeaders);
+ $this->assertIdentical('Document body', $result);
+ $this->assertIdentical(array('HTTP/1.1 200 OK'), $this->response->testHeaders);
+ }
+
+ public function testResponseCaching() {
+ $this->response->body = 'Document body';
$expires = strtotime('+1 hour');
$this->response->cache($expires);
@@ -54,7 +74,7 @@ public function testResponseRendering() {
'Cache-Control: max-age=' . ($expires - time()),
'Pragma: cache'
);
- $this->assertEqual($headers, $this->response->testHeaders);
+ $this->assertIdentical($headers, $this->response->testHeaders);
$expires = '+2 hours';
$this->response->cache($expires);
@@ -67,7 +87,7 @@ public function testResponseRendering() {
'Cache-Control: max-age=' . (strtotime($expires) - time()),
'Pragma: cache'
);
- $this->assertEqual($headers, $this->response->testHeaders);
+ $this->assertIdentical($headers, $this->response->testHeaders);
$this->response->body = 'Created';
$this->response->status(201);
@@ -80,12 +100,12 @@ public function testResponseRendering() {
'Cache-Control: max-age=0',
'Pragma: no-cache'
);
- $this->assertEqual($expected, $result);
+ $this->assertIdentical($expected, $result);
ob_start();
$this->response->render();
$result = ob_get_clean();
- $this->assertEqual('Created', $result);
+ $this->assertIdentical('Created', $result);
$headers = array (
'HTTP/1.1 201 Created',
@@ -97,7 +117,7 @@ public function testResponseRendering() {
),
'Pragma: no-cache'
);
- $this->assertEqual($headers, $this->response->testHeaders);
+ $this->assertIdentical($headers, $this->response->testHeaders);
}
/**
@@ -135,7 +155,7 @@ public function testHeaderTypes() {
$this->response->headers('download', 'report.csv');
ob_start();
$this->response->render();
- ob_end_clean();
+ ob_get_clean();
$headers = array(
'HTTP/1.1 200 OK',
@@ -147,7 +167,7 @@ public function testHeaderTypes() {
$this->response->headers('location', '/');
ob_start();
$this->response->render();
- ob_end_clean();
+ ob_get_clean();
$headers = array('HTTP/1.1 302 Found', 'Location: /');
$this->assertEqual($headers, $this->response->testHeaders);
@@ -159,7 +179,7 @@ public function testLocationHeaderStatus() {
$this->response->headers('location', '/');
ob_start();
$this->response->render();
- ob_end_clean();
+ ob_get_clean();
$headers = array('HTTP/1.1 301 Moved Permanently', 'Location: /');
$this->assertEqual($headers, $this->response->testHeaders);

0 comments on commit 4b33020

Please sign in to comment.