Changeset 1466 -- 2009-12-20 05:29:17
- Author
させざき
- Comment
- add test
Diffs
Diggin_Http_Response_CharactorEncoding/trunk/tests/Diggin/Http/Response/CharactorEncodingTest.php
@@ -54,6 +54,49 @@
mb_detect_order($this->detectOrder);
}
+ ///////////////
+
+
+
+ public function testEncode() {
+$header = <<<HEADER
+HTTP/1.1 200 OK
+Content-type: text/html charset=Shift-JIS;
+HEADER;
+
+$sjis1= mb_convert_encoding('あいうえお', 'SJIS', 'UTF-8');
+$sjis2= mb_convert_encoding('かきくけこ', 'SJIS', 'UTF-8');
+
+ $resBody = <<<BODY
+<html lang="ja">
+<head>
+<body>
+$sjis2
+</body>
+</html>
+BODY;
+ $expect = <<<BODY
+<html lang="ja">
+<head>
+<body>
+かきくけこ
+</body>
+</html>
+BODY;
+
+ $responseString = $header."\r\n\r\n".$resBody;
+ $response = Zend_Http_Response::fromString($responseString);
+
+ // via Zend_Http_Response
+ $ret =
+ Diggin_Http_Response_CharactorEncoding::createWrapper($response, 'UTF-8');
+
+ //$this->assertEquals('array', $ret);
+
+ $this->assertEquals($expect, $ret->getBody());
+
+ }
+
/**
* test "detect" part.1
*
Diggin_Http_Response_CharactorEncoding/trunk/tests/Diggin/Http/Response/CharactorEncoding/Wrapper/ZfTest.php
@@ -5,7 +5,6 @@
/**
* Test class for Diggin_Http_Response_CharactorEncoding_Wrapper_Zf.
- * Generated by PHPUnit on 2009-10-03 at 20:37:07.
*/
class Diggin_Http_Response_CharactorEncoding_Wrapper_ZfTest extends PHPUnit_Framework_TestCase
{
@@ -15,6 +14,13 @@
*/
protected $object;
+ protected $response;
+
+ protected $responseBody;
+
+ protected $responseSjis;
+ protected $responseBodyBody;
+
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
@@ -23,7 +29,41 @@
*/
protected function setUp()
{
- $this->object = new Diggin_Http_Response_CharactorEncoding_Wrapper_Zf;
+ $this->header = $header = <<<HEADER
+HTTP/1.1 200 OK
+Content-type: text/html charset=Shift-JIS;
+HEADER;
+
+ $this->responseBodyBody = 'あいうえお';
+ $sjis1= mb_convert_encoding('あいうえお', 'SJIS', 'UTF-8');
+
+ $this->responseBody = $resBody = <<<BODY
+<html lang="ja">
+<head>
+<body>
+あいうえお
+</body>
+</html>
+BODY;
+
+ $responseBodySjis = <<<BODY
+<html lang="ja">
+<head>
+<body>
+$sjis1
+</body>
+</html>
+BODY;
+ // create response
+ $responseString = $header."\r\n\r\n".$resBody;
+ $this->response = Zend_Http_Response::fromString($responseString);
+
+ $this->responseSjis = Zend_Http_Response::fromString($header."\r\n\r\n".$responseBodySjis);
+
+ $wrapper = Diggin_Http_Response_CharactorEncoding_Wrapper_Zf::createWrapper($this->response,
+ Diggin_Http_Response_CharactorEncoding::detect($resBody, $this->response->getHeader('content-type')));
+
+ $this->object = $wrapper;
}
/**
@@ -41,10 +81,8 @@
*/
public function testCreateWrapper()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ $this->assertTrue($this->object instanceof Zend_Http_Response);
+ $this->assertTrue($this->object instanceof Diggin_Http_Response_CharactorEncoding_Wrapper_WrapperInterface);
}
/**
@@ -52,54 +90,29 @@
*/
public function testGetBody()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ $this->assertEquals($this->object->getBody(), $this->responseBody);
}
/**
* @todo Implement testSetEncodingFrom().
*/
- public function testSetEncodingFrom()
+ public function testBodyisUTF8()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
- /**
- * @todo Implement testGetEncodingFrom().
- */
- public function testGetEncodingFrom()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ $wrapper = Diggin_Http_Response_CharactorEncoding_Wrapper_Zf::createWrapper($this->responseSjis,
+ 'SJIS');
+ $body = $wrapper->getBody();
+
+ $expectBodyBody = $this->responseBodyBody;
+ $expect = <<<DOC
+<html lang="ja">
+<head>
+<body>
+あいうえお
+</body>
+</html>
+DOC;
+ $this->assertEquals($body, $expect);
}
-
- /**
- * @todo Implement testSetEncodingTo().
- */
- public function testSetEncodingTo()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
-
- /**
- * @todo Implement testGetEncodingTo().
- */
- public function testGetEncodingTo()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
}
?>