Skip to content

Commit 159ac20

Browse files
committed
Testing remaining implemented methods
1 parent 2c7b21b commit 159ac20

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

cake/libs/cake_response.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ public function type($contentType = null) {
407407
}
408408
if (isset($this->_mimeTypes[$contentType])) {
409409
$contentType = $this->_mimeTypes[$contentType];
410+
$contentType = is_array($contentType) ? current($contentType) : $contentType;
410411
}
411412
return $this->_contentType = $contentType;
412413
}

cake/tests/cases/libs/cake_response.test.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
class CakeRequestTestCase extends CakeTestCase {
66

77

8+
/**
9+
* Tests the request object constructor
10+
*
11+
*/
812
public function testConstruct() {
913
$response = new CakeResponse();
1014
$this->assertNull($response->body());
@@ -24,4 +28,60 @@ public function testConstruct() {
2428
$this->assertEquals($response->type(), 'audio/mpeg');
2529
$this->assertEquals($response->statusCode(), 203);
2630
}
31+
32+
/**
33+
* Tests the body method
34+
*
35+
*/
36+
public function testBody() {
37+
$response = new CakeResponse();
38+
$this->assertNull($response->body());
39+
$response->body('Response body');
40+
$this->assertEquals($response->body(), 'Response body');
41+
$this->assertEquals($response->body('Changed Body'), 'Changed Body');
42+
}
43+
44+
/**
45+
* Tests the encoding method
46+
*
47+
*/
48+
public function testEncoding() {
49+
$response = new CakeResponse();
50+
$this->assertEquals($response->encoding(), 'UTF-8');
51+
$response->encoding('iso-8859-1');
52+
$this->assertEquals($response->encoding(), 'iso-8859-1');
53+
$this->assertEquals($response->encoding('UTF-16'), 'UTF-16');
54+
}
55+
56+
/**
57+
* Tests the statusCode method
58+
*
59+
* @expectedException OutOfRangeException
60+
*/
61+
public function testStatusCode() {
62+
$response = new CakeResponse();
63+
$this->assertEquals($response->statusCode(), 200);
64+
$response->statusCode(404);
65+
$this->assertEquals($response->statusCode(), 404);
66+
$this->assertEquals($response->statusCode(500), 500);
67+
68+
//Throws exception
69+
$response->statusCode(1001);
70+
}
71+
72+
/**
73+
* Tests the type method
74+
*
75+
*/
76+
public function testType() {
77+
$response = new CakeResponse();
78+
$this->assertEquals($response->type(), 'text/html');
79+
$response->type('pdf');
80+
$this->assertEquals($response->type(), 'application/pdf');
81+
$this->assertEquals($response->type('application/crazy-mime'), 'application/crazy-mime');
82+
$this->assertEquals($response->type('json'), 'application/json');
83+
$this->assertEquals($response->type('wap'), 'text/vnd.wap.wml');
84+
$this->assertEquals($response->type('xhtml-mobile'), 'application/vnd.wap.xhtml+xml');
85+
$this->assertEquals($response->type('csv'), 'text/csv');
86+
}
2787
}

0 commit comments

Comments
 (0)