X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=php%2Fphpxmlrpc%2Ftests%2F0CharsetTest.php;h=a5789118f7b3aa0cd37481469062359a5ea482a8;hb=c379c0fff5edc592cc5d5d647c7fadb91317db87;hp=8a6250689d3f3e08482c9c84372849c9ad55a5e7;hpb=ae8b10f8363f7a1df02e77cbd820904c4ded10b8;p=plcapi.git diff --git a/php/phpxmlrpc/tests/0CharsetTest.php b/php/phpxmlrpc/tests/0CharsetTest.php index 8a62506..a578911 100644 --- a/php/phpxmlrpc/tests/0CharsetTest.php +++ b/php/phpxmlrpc/tests/0CharsetTest.php @@ -3,6 +3,8 @@ * @author JoakimLofgren */ +include_once __DIR__ . '/PolyfillTestCase.php'; + use PhpXmlRpc\Helper\Charset; /** @@ -12,17 +14,23 @@ use PhpXmlRpc\Helper\Charset; * and run the following in cmd: * chcp 28591 (latin1) * chcp 65001 (utf8) + * + * @todo add tests for conversion: utf8 -> ascii (incl. chars 0-31 and 127) + * @todo add tests for conversion: latin1 -> utf8 + * @todo add tests for conversion: latin1 -> ascii (incl. chars 0-31 and 127) */ -class CharsetTest extends PHPUnit_Framework_TestCase +class CharsetTest extends PhpXmlRpc_PolyfillTestCase { // Consolas font should render these properly protected $runes = "ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ"; protected $greek = "Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ"; protected $russian = "Река неслася; бедный чёлн"; protected $chinese = "我能吞下玻璃而不伤身体。"; + protected $latinString; - protected function setUp() + /// @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) $this->latinString = "\n\r\t"; @@ -34,7 +42,7 @@ class CharsetTest extends PHPUnit_Framework_TestCase } } - protected function utfToLatin($data) + protected function utf8ToLatin1($data) { return Charset::instance()->encodeEntities( $data, @@ -43,6 +51,15 @@ class CharsetTest extends PHPUnit_Framework_TestCase ); } + protected function utf8ToAscii($data) + { + return Charset::instance()->encodeEntities( + $data, + 'UTF-8', + 'US-ASCII' + ); + } + public function testUtf8ToLatin1All() { /*$this->assertEquals( @@ -51,42 +68,42 @@ class CharsetTest extends PHPUnit_Framework_TestCase '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); } }