Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
--TEST--
2
XML Parser: mixing character encodings
3
--SKIPIF--
4
<?php
5
if (true) {
6
    print 'skip - incomplete test!';
7
}
8
if (!extension_loaded('xml')) {
9
    print 'skip - xml extension not available';
10
}
11
if (!extension_loaded('mbstring')) {
12
    print 'skip - mbstring extension not available';
13
}
14
?>
15
--FILE--
16
<?php
17
 
18
/* Test for: XML/Parser.php
19
 * Parts tested: - mixing character encodings
20
 *
21
 * This is what we test:
22
 * 1 UTF-8      -> ISO-8859-1
23
 * 2 UTF-8      -> US-ASCII
24
 * 3 ISO-8859-1 -> UTF-8
25
 * 4 ISO-8859-1 -> US-ASCII
26
 * 5 US-ASCII   -> UTF-8
27
 * 6 US-ASCII   -> ISO-8859-1
28
 */
29
 
30
require_once 'XML/Parser.php';
31
 
32
class TestEncodings1 extends XML_Parser {
33
    var $output = '';
34
 
35
    function TestEncodings1($to, $mode, $from) {
36
        $this->XML_Parser($from, $mode, $to);
37
    }
38
    function startHandler($xp, $elem, $attribs) {
39
        $this->output .= "<$elem>";
40
    }
41
    function endHandler($xp, $elem) {
42
        $this->output .= "</$elem>";
43
    }
44
    function cdataHandler($xp, $data) {
45
        $this->output .= $data;
46
    }
47
    function test($data) {
48
        $result = $this->parseString($data, true);
49
        if (PEAR::isError($result)) {
50
            return $result;
51
        }
52
    }
53
}
54
 
55
$xml = "<?xml version='1.0' ?>";
56
$input = array(
57
    "UTF-8"      => "<a>abcæøå</a>",
58
 
59
    /* are these special chars allowed in ISO-8859-1 context??? */
60
    "ISO-8859-1" => "<a>abc���</a>", //    "ISO-8859-1" => "<a>abc�<a>",
61
 
62
    "US-ASCII"   => "<a>abcaoa</a>"
63
);
64
 
65
$encodings = array_keys($input);
66
foreach ($input as $srcenc => $string) {
67
    foreach ($encodings as $tgtenc) {
68
        if ($srcenc == $tgtenc) {
69
            continue;
70
        }
71
        print "Testing $srcenc -> $tgtenc: ";
72
        $p =& new TestEncodings1($tgtenc, 'event', $srcenc);
73
        $e = $p->test($input[$srcenc]);
74
        if (PEAR::isError($e)) {
75
            printf("OOPS: %s\n", $e->getMessage());
76
        } else {
77
            var_dump($p->output);
78
        }
79
    }
80
}
81
 
82
?>
83
--EXPECT--
84
Testing UTF-8 -> ISO-8859-1: string(13) "<A>abc���</A>"
85
Testing UTF-8 -> US-ASCII: string(13) "<A>abc???</A>"
86
Testing ISO-8859-1 -> UTF-8: string(16) "<A>abcæøå</A>"
87
Testing ISO-8859-1 -> US-ASCII: string(13) "<A>abc???</A>"
88
Testing US-ASCII -> UTF-8: string(13) "<A>abcaoa</A>"
89
Testing US-ASCII -> ISO-8859-1: string(13) "<A>abcaoa</A>"