cvs: php-src(PHP_5_3) /ext/dom/tests DOMDocument_savexml_basic.phpt DOMNode_hasChildNodes.phpt DOMNode_insertBefore.phpt DOMNode_normalize_basic.phpt

From: Date: Tue, 27 May 2008 10:21:21 +0000
Subject: cvs: php-src(PHP_5_3) /ext/dom/tests DOMDocument_savexml_basic.phpt DOMNode_hasChildNodes.phpt DOMNode_insertBefore.phpt DOMNode_normalize_basic.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-50167@lists.php.net to get a copy of this message
scottmac Tue May 27 10:21:21 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/dom/tests DOMDocument_savexml_basic.phpt DOMNode_hasChildNodes.phpt DOMNode_insertBefore.phpt DOMNode_normalize_basic.phpt Log: MFH: DOM Tests from London Testfest http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/DOMDocument_savexml_basic.phpt?view=markup&rev=1.1 Index: php-src/ext/dom/tests/DOMDocument_savexml_basic.phpt +++ php-src/ext/dom/tests/DOMDocument_savexml_basic.phpt --TEST-- DOM Document : save and saveXML --CREDIT-- Sami Greenbury (sami@patabugen.co.uk) # TestFest 2008 --SKIPIF-- <?php require_once('skipif.inc'); ?> --FILE-- <?php $xml = <<< EOXML <?xml version="1.0" encoding="utf-8"?> <courses> <!-- Hello World! --> <aNode> <childNode> <childlessNode /> </childNode> </aNode> </courses> EOXML; $dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->documentElement; $directory = dirname(__FILE__); $filename = $directory."/tmp_dom_savexml".time(); var_dump($dom->save($filename)); $result = file_get_contents($filename); var_dump($result == $dom->saveXML()); unlink($filename); --EXPECTF-- int(151) bool(true) http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/DOMNode_hasChildNodes.phpt?view=markup&rev=1.1 Index: php-src/ext/dom/tests/DOMNode_hasChildNodes.phpt +++ php-src/ext/dom/tests/DOMNode_hasChildNodes.phpt --TEST-- Tests DOMNode::hasChildNodes() --CREDITS-- Michael Stillwell <mjs@beebo.org> # TestFest 2008 --FILE-- <?php $dom = new DOMDocument(); $dom->loadXML('<root/>'); echo $dom->saveXML(); echo "Document has child nodes\n"; var_dump($dom->documentElement->hasChildNodes()); echo "Document has child nodes\n"; $dom->loadXML('<root><a/></root>'); var_dump($dom->documentElement->hasChildNodes()); echo "Remove node and save\n"; $dom->documentElement->removeChild($dom->documentElement->firstChild); echo $dom->saveXML(); echo "Document has child nodes\n"; var_dump($dom->documentElement->hasChildNodes()); echo "Document with 2 child nodes\n"; $dom->loadXML('<root><a/><b/></root>'); var_dump($dom->documentElement->hasChildNodes()); ?> --EXPECTF-- <?xml version="1.0"?> <root/> Document has child nodes bool(false) Document has child nodes bool(true) Remove node and save <?xml version="1.0"?> <root/> Document has child nodes bool(false) Document with 2 child nodes bool(true) http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/DOMNode_insertBefore.phpt?view=markup&rev=1.1 Index: php-src/ext/dom/tests/DOMNode_insertBefore.phpt +++ php-src/ext/dom/tests/DOMNode_insertBefore.phpt --TEST-- Tests DOMNode::insertBefore() --CREDITS-- Michael Stillwell <mjs@beebo.org> # TestFest 2008 --FILE-- <?php $dom = new DOMDocument(); $dom->loadXML('<root/>'); echo $dom->saveXML(); $e1 = $dom->createElement("A"); $e2 = $dom->documentElement->appendChild($dom->createElement("B")); echo "Add new node B\n"; echo $dom->saveXML(); echo "Add new node A before B\n"; $e2->parentNode->insertBefore($e1, $e2); echo $dom->saveXML(); ?> --EXPECTF-- <?xml version="1.0"?> <root/> Add new node B <?xml version="1.0"?> <root><B/></root> Add new node A before B <?xml version="1.0"?> <root><A/><B/></root> http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/DOMNode_normalize_basic.phpt?view=markup&rev=1.1 Index: php-src/ext/dom/tests/DOMNode_normalize_basic.phpt +++ php-src/ext/dom/tests/DOMNode_normalize_basic.phpt --TEST-- DomNode::normalize() --SKIPIF-- <?php include('skipif.inc'); ?> --FILE-- <?php /* Create an XML document * with structure * <book> * <author></author> * <title>This is the title</title> * </book> * Calculate the number of title text nodes (1). * Add another text node to title. Calculate the number of title text nodes (2). * Normalize author. Calculate the number of title text nodes (2). * Normalize title. Calculate the number of title text nodes (1). */ $doc = new DOMDocument(); $root = $doc->createElement('book'); $doc->appendChild($root); $title = $doc->createElement('title'); $root->appendChild($title); $author = $doc->createElement('author'); $root->appendChild($author); $text = $doc->createTextNode('This is the first title'); $title->appendChild($text); echo "Number of child nodes of title = "; var_dump($title->childNodes->length); // add a second text node to title $text = $doc->createTextNode('This is the second title'); $title->appendChild($text); echo "Number of child nodes of title after adding second title = "; var_dump($title->childNodes->length); // should do nothing $author->normalize(); echo "Number of child nodes of title after normalizing author = "; var_dump($title->childNodes->length); // should concatenate first and second title text nodes $title->normalize(); echo "Number of child nodes of title after normalizing title = "; var_dump($title->childNodes->length); ?> --EXPECTF-- Number of child nodes of title = int(1) Number of child nodes of title after adding second title = int(2) Number of child nodes of title after normalizing author = int(2) Number of child nodes of title after normalizing title = int(1)

« previous php.cvs (#50167) next »