Changing the encoding method for "charset"

This commit is contained in:
José Lorenzo Rodríguez 2010-07-31 14:40:58 -04:30
parent d4131152cd
commit d1808db0df
2 changed files with 23 additions and 22 deletions

View file

@ -298,11 +298,11 @@ class CakeResponse {
protected $_body = null; protected $_body = null;
/** /**
* Encoding string to send * The charset the response body is encoded with
* *
* @var string * @var string
*/ */
protected $_encoding = 'UTF-8'; protected $_charset = 'UTF-8';
/** /**
* Class constructor * Class constructor
@ -311,7 +311,7 @@ class CakeResponse {
* - body: the rensonse text that should be sent to the client * - body: the rensonse text that should be sent to the client
* - status: the HTTP status code to respond with * - status: the HTTP status code to respond with
* - type: a complete mime-type string or an extension mapepd in this class * - 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 * @return void
*/ */
public function __construct(array $options = array()) { public function __construct(array $options = array()) {
@ -324,8 +324,8 @@ class CakeResponse {
if (isset($options['type'])) { if (isset($options['type'])) {
$this->type($options['type']); $this->type($options['type']);
} }
if (isset($options['encoding'])) { if (isset($options['charset'])) {
$this->encoding($options['encoding']); $this->charset($options['charset']);
} }
} }
@ -334,6 +334,7 @@ class CakeResponse {
* *
*/ */
public function send() { public function send() {
} }
/** /**
@ -447,17 +448,17 @@ class CakeResponse {
} }
/** /**
* Sets the response encoding or charset * Sets the response charset
* if $encoding is null the current encoding is returned * if $charset is null the current charset is returned
* *
* @param string $encoding * @param string $charset
* @return string current status code * @return string current charset
*/ */
public function encoding($encoding = null) { public function charset($charset = null) {
if (is_null($encoding)) { if (is_null($charset)) {
return $this->_encoding; return $this->_charset;
} }
return $this->_encoding = $encoding; return $this->_charset = $charset;
} }
/** /**

View file

@ -12,19 +12,19 @@ class CakeRequestTestCase extends CakeTestCase {
public function testConstruct() { public function testConstruct() {
$response = new CakeResponse(); $response = new CakeResponse();
$this->assertNull($response->body()); $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->type(), 'text/html');
$this->assertEquals($response->statusCode(), 200); $this->assertEquals($response->statusCode(), 200);
$options = array( $options = array(
'body' => 'This is the body', 'body' => 'This is the body',
'encoding' => 'my-custom-encoding', 'charset' => 'my-custom-charset',
'type' => 'mp3', 'type' => 'mp3',
'status' => '203' 'status' => '203'
); );
$response = new CakeResponse($options); $response = new CakeResponse($options);
$this->assertEquals($response->body(), 'This is the body'); $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->type(), 'audio/mpeg');
$this->assertEquals($response->statusCode(), 203); $this->assertEquals($response->statusCode(), 203);
} }
@ -42,15 +42,15 @@ class CakeRequestTestCase extends CakeTestCase {
} }
/** /**
* Tests the encoding method * Tests the charset method
* *
*/ */
public function testEncoding() { public function testCharset() {
$response = new CakeResponse(); $response = new CakeResponse();
$this->assertEquals($response->encoding(), 'UTF-8'); $this->assertEquals($response->charset(), 'UTF-8');
$response->encoding('iso-8859-1'); $response->charset('iso-8859-1');
$this->assertEquals($response->encoding(), 'iso-8859-1'); $this->assertEquals($response->charset(), 'iso-8859-1');
$this->assertEquals($response->encoding('UTF-16'), 'UTF-16'); $this->assertEquals($response->charset('UTF-16'), 'UTF-16');
} }
/** /**