From 9f9fb0e5005d537bbf9f4ddea631f5e9c5e40175 Mon Sep 17 00:00:00 2001 From: Tom N Harris Date: Fri, 2 Feb 2007 08:05:09 +0100 Subject: Encode/Decode numeric HTML entities correctly. utf8_tohtml handles all codepoints, and the inverse function, utf8_unhtml, is added. darcs-hash:20070202070509-6942e-09ed9dc37f1469055a7c04d44044768e160d60e6.gz --- _test/cases/inc/utf8_html.test.php | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 _test/cases/inc/utf8_html.test.php (limited to '_test') diff --git a/_test/cases/inc/utf8_html.test.php b/_test/cases/inc/utf8_html.test.php new file mode 100644 index 000000000..57c9df259 --- /dev/null +++ b/_test/cases/inc/utf8_html.test.php @@ -0,0 +1,72 @@ +assertEqual(utf8_tohtml($in),$out); + } + + function test_from_2byte(){ + $in = "\xc3\xbc"; + $out = 'ü'; + $this->assertEqual(utf8_tohtml($in),$out); + } + + function test_from_3byte(){ + $in = "\xe2\x99\x8a"; + $out = '♊'; + $this->assertEqual(utf8_tohtml($in),$out); + } + + function test_from_4byte(){ + $in = "\xf4\x80\x80\x81"; + $out = '􀀁'; + $this->assertEqual(utf8_tohtml($in),$out); + } + + function test_to_1byte(){ + $out = 'a'; + $in = 'a'; + $this->assertEqual(utf8_unhtml($in),$out); + } + + function test_to_2byte(){ + $out = "\xc3\xbc"; + $in = 'ü'; + $this->assertEqual(utf8_unhtml($in),$out); + } + + function test_to_3byte(){ + $out = "\xe2\x99\x8a"; + $in = '♊'; + $this->assertEqual(utf8_unhtml($in),$out); + } + + function test_to_4byte(){ + $out = "\xf4\x80\x80\x81"; + $in = '􀀁'; + $this->assertEqual(utf8_unhtml($in),$out); + } + + function test_without_entities(){ + $out = '&&'; + $in = '&&'; + $this->assertEqual(utf8_unhtml($in),$out); + } + + function test_with_entities(){ + $out = '&&'; + $in = '&&'; + $this->assertEqual(utf8_unhtml($in,HTML_ENTITIES),$out); + } + +} + +//Setup VIM: ex: et ts=4 enc=utf-8 : -- cgit v1.2.3