X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2F0CharsetTest.php;h=549b0f421045518084f24f9d85f0dbb6757ed534;hb=5d63c263e763338952815b6724ffa4469061afc4;hp=c5332ad7883a6af0d19832a6797e836030fb6f67;hpb=f5456e63644d3d34194912d7c371759807be30ed;p=plcapi.git diff --git a/tests/0CharsetTest.php b/tests/0CharsetTest.php index c5332ad7..549b0f42 100644 --- a/tests/0CharsetTest.php +++ b/tests/0CharsetTest.php @@ -3,10 +3,10 @@ * @author JoakimLofgren */ -use PhpXmlRpc\Helper\Charset; - include_once __DIR__ . '/PolyfillTestCase.php'; +use PhpXmlRpc\Helper\Charset; + /** * Test conversion between encodings * @@ -14,6 +14,10 @@ include_once __DIR__ . '/PolyfillTestCase.php'; * and run the following in cmd: * chcp 28591 (latin1) * chcp 65001 (utf8) + * + * @todo add tests for conversion: utf8 -> ascii (incl. chars 0-31) + * @todo add tests for conversion: latin1 -> utf8 + * @todo add tests for conversion: latin1 -> ascii */ class CharsetTest extends PhpXmlRpc_PolyfillTestCase { @@ -24,6 +28,7 @@ class CharsetTest extends PhpXmlRpc_PolyfillTestCase protected $chinese = "我能吞下玻璃而不伤身体。"; protected $latinString; + /// @todo move to usage of a dataProvider and create the latinString there protected function set_up() { // construct a latin string with all chars (except control ones) @@ -36,7 +41,7 @@ class CharsetTest extends PhpXmlRpc_PolyfillTestCase } } - protected function utfToLatin($data) + protected function utf8ToLatin1($data) { return Charset::instance()->encodeEntities( $data, @@ -45,6 +50,15 @@ class CharsetTest extends PhpXmlRpc_PolyfillTestCase ); } + protected function utf8ToAscii($data) + { + return Charset::instance()->encodeEntities( + $data, + 'UTF-8', + 'US-ASCII' + ); + } + public function testUtf8ToLatin1All() { /*$this->assertEquals( @@ -53,42 +67,42 @@ class CharsetTest extends PhpXmlRpc_PolyfillTestCase 'Setup latinString is not ISO-8859-1 encoded...' );*/ $string = utf8_encode($this->latinString); - $encoded = $this->utfToLatin($string); + $encoded = $this->utf8ToLatin1($string); $this->assertEquals(str_replace(array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $this->latinString), $encoded); } public function testUtf8ToLatin1EuroSymbol() { $string = 'a.b.c.Ã¥.ä.ö.€.'; - $encoded = $this->utfToLatin($string); + $encoded = $this->utf8ToLatin1($string); $this->assertEquals(utf8_decode('a.b.c.Ã¥.ä.ö.€.'), $encoded); } public function testUtf8ToLatin1Runes() { $string = $this->runes; - $encoded = $this->utfToLatin($string); + $encoded = $this->utf8ToLatin1($string); $this->assertEquals('ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ', $encoded); } public function testUtf8ToLatin1Greek() { $string = $this->greek; - $encoded = $this->utfToLatin($string); + $encoded = $this->utf8ToLatin1($string); $this->assertEquals('Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ', $encoded); } public function testUtf8ToLatin1Russian() { $string = $this->russian; - $encoded = $this->utfToLatin($string); + $encoded = $this->utf8ToLatin1($string); $this->assertEquals('Река неслася; бедный чёлн', $encoded); } public function testUtf8ToLatin1Chinese() { $string = $this->chinese; - $encoded = $this->utfToLatin($string); + $encoded = $this->utf8ToLatin1($string); $this->assertEquals('我能吞下玻璃而不伤身体。', $encoded); } }