Annotation of embedaddon/php/ext/simplexml/tests/bug42259.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Bug #42259 (SimpleXMLIterator loses ancestry)
3: --SKIPIF--
4: <?php
5: if (!extension_loaded('simplexml')) print 'skip';
6: if (!extension_loaded("libxml")) print "skip LibXML not present";
7: ?>
8: --FILE--
9: <?php
10: $xml =<<<EOF
11: <xml>
12: <fieldset1>
13: <field1/>
14: <field2/>
15: </fieldset1>
16: <fieldset2>
17: <options>
18: <option1/>
19: <option2/>
20: <option3/>
21: </options>
22: <field1/>
23: <field2/>
24: </fieldset2>
25: </xml>
26: EOF;
27:
28: $sxe = new SimpleXMLIterator($xml);
29: $rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::LEAVES_ONLY);
30: foreach ($rit as $child) {
31: $path = '';
32: $ancestry = $child->xpath('ancestor-or-self::*');
33: foreach ($ancestry as $ancestor) {
34: $path .= $ancestor->getName() . '/';
35: }
36: $path = substr($path, 0, strlen($path) - 1);
37: echo count($ancestry) . ' steps: ' . $path . PHP_EOL;
38: }
39: ?>
40: ===DONE===
41: --EXPECT--
42: 3 steps: xml/fieldset1/field1
43: 3 steps: xml/fieldset1/field2
44: 4 steps: xml/fieldset2/options/option1
45: 4 steps: xml/fieldset2/options/option2
46: 4 steps: xml/fieldset2/options/option3
47: 3 steps: xml/fieldset2/field1
48: 3 steps: xml/fieldset2/field2
49: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>