xref: /PHP-8.0/ext/simplexml/tests/sxe_004.phpt (revision f8d79582)
1--TEST--
2SPL: SimpleXMLIterator and overridden iterator methods()
3--SKIPIF--
4<?php
5if (!extension_loaded('simplexml')) print 'skip';
6if (!extension_loaded("libxml")) print "skip LibXML not present";
7?>
8--FILE--
9<?php
10
11$xml =<<<EOF
12<?xml version='1.0'?>
13<!DOCTYPE sxe SYSTEM "notfound.dtd">
14<sxe id="elem1">
15 Plain text.
16 <elem1 attr1='first'>
17  Bla bla 1.
18  <!-- comment -->
19  <elem2>
20   Here we have some text data.
21   <elem3>
22    And here some more.
23    <elem4>
24     Wow once again.
25    </elem4>
26   </elem3>
27  </elem2>
28 </elem1>
29 <elem11 attr2='second'>
30  Bla bla 2.
31  <elem111>
32   Foo Bar
33  </elem111>
34 </elem11>
35</sxe>
36EOF;
37
38class SXETest extends SimpleXMLIterator
39{
40    function rewind()
41    {
42        echo __METHOD__ . "\n";
43        return parent::rewind();
44    }
45    function valid()
46    {
47        echo __METHOD__ . "\n";
48        return parent::valid();
49    }
50    function current()
51    {
52        echo __METHOD__ . "\n";
53        return parent::current();
54    }
55    function key()
56    {
57        echo __METHOD__ . "\n";
58        return parent::key();
59    }
60    function next()
61    {
62        echo __METHOD__ . "\n";
63        return parent::next();
64    }
65    function hasChildren()
66    {
67        echo __METHOD__ . "\n";
68        return parent::hasChildren();
69    }
70    function getChildren()
71    {
72        echo __METHOD__ . "\n";
73        return parent::getChildren();
74    }
75}
76
77$sxe = new SXETest($xml);
78$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::SELF_FIRST);
79
80foreach($rit as $data) {
81    var_dump(get_class($data));
82    var_dump(trim($data));
83}
84
85?>
86--EXPECT--
87SXETest::rewind
88SXETest::valid
89SXETest::hasChildren
90SXETest::valid
91SXETest::current
92string(7) "SXETest"
93string(10) "Bla bla 1."
94SXETest::getChildren
95SXETest::rewind
96SXETest::valid
97SXETest::hasChildren
98SXETest::valid
99SXETest::current
100string(7) "SXETest"
101string(28) "Here we have some text data."
102SXETest::getChildren
103SXETest::rewind
104SXETest::valid
105SXETest::hasChildren
106SXETest::valid
107SXETest::current
108string(7) "SXETest"
109string(19) "And here some more."
110SXETest::getChildren
111SXETest::rewind
112SXETest::valid
113SXETest::hasChildren
114SXETest::valid
115SXETest::current
116string(7) "SXETest"
117string(15) "Wow once again."
118SXETest::next
119SXETest::valid
120SXETest::next
121SXETest::valid
122SXETest::next
123SXETest::valid
124SXETest::next
125SXETest::valid
126SXETest::hasChildren
127SXETest::valid
128SXETest::current
129string(7) "SXETest"
130string(10) "Bla bla 2."
131SXETest::getChildren
132SXETest::rewind
133SXETest::valid
134SXETest::hasChildren
135SXETest::valid
136SXETest::current
137string(7) "SXETest"
138string(7) "Foo Bar"
139SXETest::next
140SXETest::valid
141SXETest::next
142SXETest::valid
143SXETest::valid
144