Skip to content
Permalink
Browse files

Changing the encoding method for "charset"

  • Loading branch information...
lorenzo committed Jul 31, 2010
1 parent d413115 commit d1808db0df89c3a36d490f8ad16f2cca2a1b6130
Showing with 23 additions and 22 deletions.
  1. +14 −13 cake/libs/cake_response.php
  2. +9 −9 cake/tests/cases/libs/cake_response.test.php
@@ -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
@@ -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()) {
@@ -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']);
}
}
@@ -334,6 +334,7 @@ public function __construct(array $options = array()) {
*
*/
public function send() {
}
/**
@@ -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;
}
/**
@@ -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);
}
@@ -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');
}
/**

0 comments on commit d1808db

Please sign in to comment.
You can’t perform that action at this time.