From 159ac2038ebe07a7c48f5ee54267ddd0c49b2bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Sat, 31 Jul 2010 13:04:53 -0430 Subject: [PATCH] Testing remaining implemented methods --- cake/libs/cake_response.php | 1 + cake/tests/cases/libs/cake_response.test.php | 60 ++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/cake/libs/cake_response.php b/cake/libs/cake_response.php index fa3594824..3fb974dc7 100644 --- a/cake/libs/cake_response.php +++ b/cake/libs/cake_response.php @@ -407,6 +407,7 @@ class CakeResponse { } if (isset($this->_mimeTypes[$contentType])) { $contentType = $this->_mimeTypes[$contentType]; + $contentType = is_array($contentType) ? current($contentType) : $contentType; } return $this->_contentType = $contentType; } diff --git a/cake/tests/cases/libs/cake_response.test.php b/cake/tests/cases/libs/cake_response.test.php index b4a44b131..b6d4172c6 100644 --- a/cake/tests/cases/libs/cake_response.test.php +++ b/cake/tests/cases/libs/cake_response.test.php @@ -5,6 +5,10 @@ App::import('Core', array('CakeResponse', 'CakeRequest')); class CakeRequestTestCase extends CakeTestCase { +/** +* Tests the request object constructor +* +*/ public function testConstruct() { $response = new CakeResponse(); $this->assertNull($response->body()); @@ -24,4 +28,60 @@ class CakeRequestTestCase extends CakeTestCase { $this->assertEquals($response->type(), 'audio/mpeg'); $this->assertEquals($response->statusCode(), 203); } + +/** +* Tests the body method +* +*/ + public function testBody() { + $response = new CakeResponse(); + $this->assertNull($response->body()); + $response->body('Response body'); + $this->assertEquals($response->body(), 'Response body'); + $this->assertEquals($response->body('Changed Body'), 'Changed Body'); + } + +/** +* Tests the encoding method +* +*/ + public function testEncoding() { + $response = new CakeResponse(); + $this->assertEquals($response->encoding(), 'UTF-8'); + $response->encoding('iso-8859-1'); + $this->assertEquals($response->encoding(), 'iso-8859-1'); + $this->assertEquals($response->encoding('UTF-16'), 'UTF-16'); + } + +/** +* Tests the statusCode method +* +* @expectedException OutOfRangeException +*/ + public function testStatusCode() { + $response = new CakeResponse(); + $this->assertEquals($response->statusCode(), 200); + $response->statusCode(404); + $this->assertEquals($response->statusCode(), 404); + $this->assertEquals($response->statusCode(500), 500); + + //Throws exception + $response->statusCode(1001); + } + +/** +* Tests the type method +* +*/ + public function testType() { + $response = new CakeResponse(); + $this->assertEquals($response->type(), 'text/html'); + $response->type('pdf'); + $this->assertEquals($response->type(), 'application/pdf'); + $this->assertEquals($response->type('application/crazy-mime'), 'application/crazy-mime'); + $this->assertEquals($response->type('json'), 'application/json'); + $this->assertEquals($response->type('wap'), 'text/vnd.wap.wml'); + $this->assertEquals($response->type('xhtml-mobile'), 'application/vnd.wap.xhtml+xml'); + $this->assertEquals($response->type('csv'), 'text/csv'); + } } \ No newline at end of file