helly Wed Nov 10 14:22:29 2004 EDT Added files: /php-src/ext/spl/tests iterator_016.phpt sxe_004.phpt Log: - Add new tests
http://cvs.php.net/co.php/php-src/ext/spl/tests/iterator_016.phpt?r=1.1&p=1 Index: php-src/ext/spl/tests/iterator_016.phpt +++ php-src/ext/spl/tests/iterator_016.phpt --TEST-- SPL: RecursiveIteratorIterator and beginChildren/endChildren --FILE-- <?php class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator { function hasChildren() { return is_array($this->current()); } function getChildren() { return new RecursiveArrayIterator($this->current()); } } class Menu extends ArrayObject { function getIterator() { echo __METHOD__ . "\n"; return new RecursiveArrayIterator($this); } } class MenuOutput extends RecursiveIteratorIterator { function __construct(Menu $it) { parent::__construct($it); } function rewind() { echo "<ul>\n"; parent::rewind(); } function beginChildren() { echo str_repeat(' ',$this->getDepth())."<ul>\n"; } function endChildren() { echo str_repeat(' ',$this->getDepth()+1)."</ul>\n"; } function valid() { if (!parent::valid()) { echo "<ul>\n"; return false; } return true; } } $arr = array("a", array("ba", array("bba", "bbb"), array(array("bcaa"))), array("ca"), "d"); $obj = new Menu($arr); $rit = new MenuOutput($obj); foreach($rit as $k=>$v) { echo str_repeat(' ',$rit->getDepth()+1)."$k=>$v\n"; } ?> ===DONE=== <?php exit(0); ?> --EXPECTF-- Menu::getIterator <ul> 0=>a <ul> 0=>ba <ul> 0=>bba 1=>bbb </ul> <ul> <ul> 0=>bcaa </ul> </ul> </ul> <ul> 0=>ca </ul> 3=>d <ul> ===DONE=== http://cvs.php.net/co.php/php-src/ext/spl/tests/sxe_004.phpt?r=1.1&p=1 Index: php-src/ext/spl/tests/sxe_004.phpt +++ php-src/ext/spl/tests/sxe_004.phpt --TEST-- SPL: SimpleXMLIterator and getChildren() --SKIPIF-- <?php if (!extension_loaded('simplexml')) print 'skip'; if (!class_exists('RecursiveIteratorIterator')) print 'skip RecursiveIteratorIterator not available'; ?> --FILE-- <?php $xml =<<<EOF <?xml version='1.0'?> <!DOCTYPE sxe SYSTEM "notfound.dtd"> <sxe id="elem1"> Plain text. <elem1 attr1='first'> Bla bla 1. <!-- comment --> <elem2> Here we have some text data. <elem3> And here some more. <elem4> Wow once again. </elem4> </elem3> </elem2> </elem1> <elem11 attr2='second'> Bla bla 2. <elem111> Foo Bar </elem111> </elem11> </sxe> EOF; class SXETest extends SimpleXMLIterator { function rewind() { echo __METHOD__ . "\n"; return parent::rewind(); } function valid() { echo __METHOD__ . "\n"; return parent::valid(); } function current() { echo __METHOD__ . "\n"; return parent::current(); } function key() { echo __METHOD__ . "\n"; return parent::key(); } function next() { echo __METHOD__ . "\n"; return parent::next(); } function hasChildren() { echo __METHOD__ . "\n"; return parent::hasChildren(); } function getChildren() { echo __METHOD__ . "\n"; return parent::getChildren(); } } $sxe = new SXETest($xml); $rit = new RecursiveIteratorIterator($sxe, RIT_SELF_FIRST); foreach($rit as $data) { var_dump(get_class($data)); var_dump(trim($data)); } ?> ===DONE=== --EXPECTF-- SXETest::rewind SXETest::valid SXETest::hasChildren SXETest::valid SXETest::current string(7) "SXETest" string(10) "Bla bla 1." SXETest::getChildren SXETest::rewind SXETest::valid SXETest::hasChildren SXETest::valid SXETest::current string(7) "SXETest" string(28) "Here we have some text data." SXETest::getChildren SXETest::rewind SXETest::valid SXETest::hasChildren SXETest::valid SXETest::current string(7) "SXETest" string(19) "And here some more." SXETest::getChildren SXETest::rewind SXETest::valid SXETest::hasChildren SXETest::valid SXETest::current string(7) "SXETest" string(15) "Wow once again." SXETest::next SXETest::valid SXETest::next SXETest::valid SXETest::next SXETest::valid SXETest::next SXETest::valid SXETest::hasChildren SXETest::valid SXETest::current string(7) "SXETest" string(10) "Bla bla 2." SXETest::getChildren SXETest::rewind SXETest::valid SXETest::hasChildren SXETest::valid SXETest::current string(7) "SXETest" string(7) "Foo Bar" SXETest::next SXETest::valid SXETest::next SXETest::valid SXETest::valid ===DONE=== -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php