xref: /dokuwiki/_test/tests/inc/utf8_html.test.php (revision 5a0eec47d375f076d810160503bdd303f8cf62a0)
1<?php
2
3require_once DOKU_INC.'inc/utf8.php';
4
5// use no mbstring help here
6if(!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING',1);
7
8class utf8_html_test extends DokuWikiTest {
9
10    function test_from_1byte(){
11        $in  = 'a';
12        $out = 'a';
13        $this->assertEquals(utf8_tohtml($in),$out);
14    }
15
16    function test_from_2byte(){
17        $in  = "\xc3\xbc";
18        $out = '&#252;';
19        $this->assertEquals(utf8_tohtml($in),$out);
20    }
21
22    function test_from_3byte(){
23        $in  = "\xe2\x99\x8a";
24        $out = '&#x264a;';
25        $this->assertEquals(utf8_tohtml($in),$out);
26    }
27
28    function test_from_4byte(){
29        $in  = "\xf4\x80\x80\x81";
30        $out = '&#x100001;';
31        $this->assertEquals(utf8_tohtml($in),$out);
32    }
33
34    function test_to_1byte(){
35        $out  = 'a';
36        $in = 'a';
37        $this->assertEquals(utf8_unhtml($in),$out);
38    }
39
40    function test_to_2byte(){
41        $out  = "\xc3\xbc";
42        $in = '&#252;';
43        $this->assertEquals(utf8_unhtml($in),$out);
44    }
45
46    function test_to_3byte(){
47        $out  = "\xe2\x99\x8a";
48        $in = '&#x264a;';
49        $this->assertEquals(utf8_unhtml($in),$out);
50    }
51
52    function test_to_4byte(){
53        $out  = "\xf4\x80\x80\x81";
54        $in = '&#x100001;';
55        $this->assertEquals(utf8_unhtml($in),$out);
56    }
57
58    function test_without_entities(){
59        $out  = '&amp;#38;&amp;#38;';
60        $in = '&amp;#38;&#38;amp;#38;';
61        $this->assertEquals(utf8_unhtml($in),$out);
62    }
63
64    function test_with_entities(){
65        $out  = '&#38;&amp;#38;';
66        $in = '&amp;#38;&#38;amp;#38;';
67        $this->assertEquals(utf8_unhtml($in,HTML_ENTITIES),$out);
68    }
69
70}
71
72//Setup VIM: ex: et ts=4 :
73