3 * @author JoakimLofgren
6 use PhpXmlRpc\Helper\Charset;
8 include_once __DIR__ . '/PolyfillTestCase.php';
11 * Test conversion between encodings
13 * For Windows if you want to test the output use Consolas font
14 * and run the following in cmd:
18 class CharsetTest extends PhpXmlRpc_PolyfillTestCase
20 // Consolas font should render these properly
21 protected $runes = "ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ";
22 protected $greek = "Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ";
23 protected $russian = "Река неслася; бедный чёлн";
24 protected $chinese = "我能吞下玻璃而不伤身体。";
25 protected $latinString;
27 protected function set_up()
29 // construct a latin string with all chars (except control ones)
30 $this->latinString = "\n\r\t";
31 for($i = 32; $i < 127; $i++) {
32 $this->latinString .= chr($i);
34 for($i = 160; $i < 256; $i++) {
35 $this->latinString .= chr($i);
39 protected function utfToLatin($data)
41 return Charset::instance()->encodeEntities(
48 public function testUtf8ToLatin1All()
50 /*$this->assertEquals(
52 mb_detect_encoding($this->latinString, 'ISO-8859-1, UTF-8, WINDOWS-1251, ASCII', true),
53 'Setup latinString is not ISO-8859-1 encoded...'
55 $string = utf8_encode($this->latinString);
56 $encoded = $this->utfToLatin($string);
57 $this->assertEquals(str_replace(array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $this->latinString), $encoded);
60 public function testUtf8ToLatin1EuroSymbol()
62 $string = 'a.b.c.å.ä.ö.€.';
63 $encoded = $this->utfToLatin($string);
64 $this->assertEquals(utf8_decode('a.b.c.å.ä.ö.€.'), $encoded);
67 public function testUtf8ToLatin1Runes()
69 $string = $this->runes;
70 $encoded = $this->utfToLatin($string);
71 $this->assertEquals('ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ', $encoded);
74 public function testUtf8ToLatin1Greek()
76 $string = $this->greek;
77 $encoded = $this->utfToLatin($string);
78 $this->assertEquals('Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ', $encoded);
81 public function testUtf8ToLatin1Russian()
83 $string = $this->russian;
84 $encoded = $this->utfToLatin($string);
85 $this->assertEquals('Река неслася; бедный чёлн', $encoded);
88 public function testUtf8ToLatin1Chinese()
90 $string = $this->chinese;
91 $encoded = $this->utfToLatin($string);
92 $this->assertEquals('我能吞下玻璃而不伤身体。', $encoded);