1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#!/www/server/bin/php -qC
<?php
# Tests for xml.class
function match($xmldata, $expected, $name, $prefix = "", $p = array())
{
$classname = $prefix ? ($prefix . "_xml") : "it_xml";
$varname = $prefix . "foo";
$xmldata = "<root>$xmldata</root>";
$xml = new $classname($xmldata, $p);
is(
preg_replace('/[#\s]+/', " ", print_r($xml->$varname, true)),
$expected,
"$name (string)"
);
$tmpfile = tmpfile();
fwrite($tmpfile, $xmldata);
rewind($tmpfile);
$xml = new $classname($tmpfile, $p);
fclose($tmpfile);
is(
preg_replace('/[#\s]+/', " ", print_r($xml->$varname, true)),
$expected,
"$name (file)"
);
}
match(
'<foo />',
'foo Object ( ) ',
'empty tag'
);
match(
'<foo /><foo />',
'Array ( [0] => foo Object ( ) [1] => foo Object ( ) ) ',
'multiple empty tags converted to array'
);
match(
'<foo title="Zürich">Stüssihofstadt</foo>',
'foo Object ( [attr] => Array ( [title] => Zürich ) [val] => Stüssihofstadt ) ',
'simple tag with latin1 content and attribute'
);
match(
'<foo><ns:a.b.-c ns2:d.e-f="value" /></foo>',
'foo Object ( [a_b__c] => a_b__c Object ( [attr] => Array ( [d_e_f] => value ) ) ) ',
'Tags and attributes with name space and special characters'
);
match(
'<foo>x & y</foo>',
'foo Object ( [val] => x & y ) ',
'Character data with entities'
);
match(
'<foo>&amp; <a> &amp; <b> &amp; <c> ü</foo>',
'foo Object ( [val] => & <a> & <b> & <c> ü ) ',
'Predecode illegal entities while keeping properly encoded ones',
);
match(
'<foo>&amp; <a> &amp; <b> &amp; <c> ü</foo>',
utf8_encode('foo Object ( [val] => & <a> & <b> & <c> ü ) '),
'Predecode illegal entities while keeping properly encoded ones (UTF-8)',
"",
array('encoding' => "UTF-8"),
);
# Test inheritance
class my_xml extends it_xml
{
function my_xml($xmldata)
{
parent::it_xml($xmldata);
# Code which should be executed in root and only there
$this->qux = new it_xml;
$this->qux->val = "qux";
if (is_object($this->myfoo))
$this->myfoo->inheritbaseclass = is_a($this->myfoo, "my_xml");
}
}
match(
'<myfoo />',
'myfoo Object ( [inheritbaseclass] => ) ',
'Inheritance and constructor (critical for e.g. tel_xmlentry)',
'my'
);
?>
|