Skip to content

Commit

Permalink
Changing the encoding method for "charset"
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jul 31, 2010
1 parent d413115 commit d1808db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
27 changes: 14 additions & 13 deletions cake/libs/cake_response.php
Expand Up @@ -298,11 +298,11 @@ class CakeResponse {
protected $_body = null;

/**
* Encoding string to send
* The charset the response body is encoded with
*
* @var string
*/
protected $_encoding = 'UTF-8';
protected $_charset = 'UTF-8';

/**
* Class constructor
Expand All @@ -311,7 +311,7 @@ class CakeResponse {
* - body: the rensonse text that should be sent to the client
* - status: the HTTP status code to respond with
* - type: a complete mime-type string or an extension mapepd in this class
* - encoding: the encoding for the response body
* - charset: the charset for the response body
* @return void
*/
public function __construct(array $options = array()) {
Expand All @@ -324,8 +324,8 @@ public function __construct(array $options = array()) {
if (isset($options['type'])) {
$this->type($options['type']);
}
if (isset($options['encoding'])) {
$this->encoding($options['encoding']);
if (isset($options['charset'])) {
$this->charset($options['charset']);
}
}

Expand All @@ -334,6 +334,7 @@ public function __construct(array $options = array()) {
*
*/
public function send() {

}

/**
Expand Down Expand Up @@ -447,17 +448,17 @@ public function type($contentType = null) {
}

/**
* Sets the response encoding or charset
* if $encoding is null the current encoding is returned
* Sets the response charset
* if $charset is null the current charset is returned
*
* @param string $encoding
* @return string current status code
* @param string $charset
* @return string current charset
*/
public function encoding($encoding = null) {
if (is_null($encoding)) {
return $this->_encoding;
public function charset($charset = null) {
if (is_null($charset)) {
return $this->_charset;
}
return $this->_encoding = $encoding;
return $this->_charset = $charset;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions cake/tests/cases/libs/cake_response.test.php
Expand Up @@ -12,19 +12,19 @@ class CakeRequestTestCase extends CakeTestCase {
public function testConstruct() {
$response = new CakeResponse();
$this->assertNull($response->body());
$this->assertEquals($response->encoding(), 'UTF-8');
$this->assertEquals($response->charset(), 'UTF-8');
$this->assertEquals($response->type(), 'text/html');
$this->assertEquals($response->statusCode(), 200);

$options = array(
'body' => 'This is the body',
'encoding' => 'my-custom-encoding',
'charset' => 'my-custom-charset',
'type' => 'mp3',
'status' => '203'
);
$response = new CakeResponse($options);
$this->assertEquals($response->body(), 'This is the body');
$this->assertEquals($response->encoding(), 'my-custom-encoding');
$this->assertEquals($response->charset(), 'my-custom-charset');
$this->assertEquals($response->type(), 'audio/mpeg');
$this->assertEquals($response->statusCode(), 203);
}
Expand All @@ -42,15 +42,15 @@ public function testBody() {
}

/**
* Tests the encoding method
* Tests the charset method
*
*/
public function testEncoding() {
public function testCharset() {
$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');
$this->assertEquals($response->charset(), 'UTF-8');
$response->charset('iso-8859-1');
$this->assertEquals($response->charset(), 'iso-8859-1');
$this->assertEquals($response->charset('UTF-16'), 'UTF-16');
}

/**
Expand Down

0 comments on commit d1808db

Please sign in to comment.