#!/www/server/bin/php -qC $xmldata"; $xml = new $classname($xmldata, $p); $mod_utf8 = $p['encoding'] != "iso-8859-1" ? "u" : ""; is( preg_replace('/[#\s]+/' . $mod_utf8, " ", 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]+/' . $mod_utf8, " ", print_r($xml->$varname, true)), $expected, "$name (file)" ); } _match( '', 'foo Object ( ) ', 'empty tag' ); _match( '', 'Array ( [0] => foo Object ( ) [1] => foo Object ( ) ) ', 'multiple empty tags converted to array' ); _match( 'Stüssihofstadt', 'foo Object ( [attr] => Array ( [title] => Zürich ) [val] => Stüssihofstadt ) ', 'simple tag with latin1 content and attribute' ); _match( '', '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( 'x & y', 'foo Object ( [val] => x & y ) ', 'Character data with entities' ); _match( 'x ü y', utf8_decode('foo Object ( [val] => x ü y ) '), 'Manual encoding override', "", ['encoding' => "iso-8859-1"] ); _match( '&amp; <a> &amp; <b> &amp; <c> ü', 'foo Object ( [val] => & & & ü ) ', 'Predecode illegal entities while keeping properly encoded ones' ); _match( '&amp; <a> &amp; <b> &amp; <c> ü', utf8_decode('foo Object ( [val] => & & & ü ) '), 'Predecode illegal entities while keeping properly encoded ones (iso-8859-1)', "", ['encoding' => "iso-8859-1"] ); _match( "a\x05b", 'foo Object ( [val] => a b ) ', 'Illegal latin 1 character', "", ['encoding' => "iso-8859-1"] ); # Test inheritance class my_xml extends it_xml { function __construct($xmldata) { parent::__construct($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 Object ( [inheritbaseclass] => ) ', 'Inheritance and constructor (critical for e.g. tel_xmlentry)', 'my' ); $x = new foo("", ['prefix' => "test"]); $x->set(['gna' => 42, 'bar' => ['baz' => ["qux", "quux"]]]); _match( $x->to_xml(), 'foo Object ( [gna] => gna Object ( [val] => 42 ) [bar] => bar Object ( [baz] => Array ( [0] => baz Object ( [val] => qux ) [1] => baz Object ( [val] => quux ) ) ) ) ', "Method set()" ); ?>