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