summaryrefslogtreecommitdiff
path: root/tests/xml.t
blob: d127fd820e39c771ed045b0d8667ddc57e7275d7 (plain)
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
#!/www/server/bin/php -qC
<?php
#
# $Id$
#
# Tests for itools/xml.class

require 'searchlib/search_test.class';

function match($xmldata, $expected, $name, $prefix = "")
{
	$classname = $prefix ? ($prefix . "_xml") : "it_xml";
	$varname  = $prefix . "foo";
	$xml = new $classname("<root>$xmldata</root>");

	is(
		preg_replace('/[#\s]+/', " ", search_test::dump($xml->$varname)),
		$expected,
		$name,
	);
}

match(
	'<foo />',
	'class foo { }',
	'empty tag'
);

match(
	'<foo /><foo />',
	'array ( 0 => class foo { }, 1 => class foo { }, )',
	'multiple empty tags converted to array'
);

match(
	'<foo title="Zürich">Stüssihofstadt</foo>',
	'class foo { var $attr = array( \'title\' => \'Zürich\' ); var $val = \'Stüssihofstadt\'; }',
	'simple tag with latin1 content and attribute'
);

match(
	'<foo><ns:a.b.-c ns2:d.e-f="value" /></foo>',
	'class foo { var $a_b__c = class a_b__c { var $attr = array( \'d_e_f\' => \'value\' ); }; }',
	'Tags and attributes with name space and special characters'
);

# 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 />',
	'class myfoo { var $inheritbaseclass = false; }',
	'Inheritance and constructor (critical for e.g. tel_xmlentry)',
	'my'
);

?>