From: Scott MacVicar Date: Tue, 27 May 2008 10:21:21 +0000 (+0000) Subject: MFH: DOM Tests from London Testfest X-Git-Tag: BEFORE_NEW_PARAMETER_PARSE~143 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2da2a91b1278c21b73f1ef5c9f6d4500d6b0c45;p=php MFH: DOM Tests from London Testfest --- diff --git a/ext/dom/tests/DOMDocument_savexml_basic.phpt b/ext/dom/tests/DOMDocument_savexml_basic.phpt new file mode 100644 index 0000000000..34dfcc365e --- /dev/null +++ b/ext/dom/tests/DOMDocument_savexml_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +DOM Document : save and saveXML +--CREDIT-- +Sami Greenbury (sami@patabugen.co.uk) +# TestFest 2008 +--SKIPIF-- + +--FILE-- + + + + + + + + + +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) \ No newline at end of file diff --git a/ext/dom/tests/DOMNode_hasChildNodes.phpt b/ext/dom/tests/DOMNode_hasChildNodes.phpt new file mode 100644 index 0000000000..406f8d14ce --- /dev/null +++ b/ext/dom/tests/DOMNode_hasChildNodes.phpt @@ -0,0 +1,47 @@ +--TEST-- +Tests DOMNode::hasChildNodes() +--CREDITS-- +Michael Stillwell +# TestFest 2008 +--FILE-- +loadXML(''); + +echo $dom->saveXML(); + +echo "Document has child nodes\n"; +var_dump($dom->documentElement->hasChildNodes()); + +echo "Document has child nodes\n"; +$dom->loadXML(''); +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(''); +var_dump($dom->documentElement->hasChildNodes()); + +?> +--EXPECTF-- + + +Document has child nodes +bool(false) +Document has child nodes +bool(true) +Remove node and save + + +Document has child nodes +bool(false) +Document with 2 child nodes +bool(true) diff --git a/ext/dom/tests/DOMNode_insertBefore.phpt b/ext/dom/tests/DOMNode_insertBefore.phpt new file mode 100644 index 0000000000..85cd502b26 --- /dev/null +++ b/ext/dom/tests/DOMNode_insertBefore.phpt @@ -0,0 +1,32 @@ +--TEST-- +Tests DOMNode::insertBefore() +--CREDITS-- +Michael Stillwell +# TestFest 2008 +--FILE-- +loadXML(''); +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-- + + +Add new node B + + +Add new node A before B + + diff --git a/ext/dom/tests/DOMNode_normalize_basic.phpt b/ext/dom/tests/DOMNode_normalize_basic.phpt new file mode 100644 index 0000000000..8ab9080f69 --- /dev/null +++ b/ext/dom/tests/DOMNode_normalize_basic.phpt @@ -0,0 +1,64 @@ +--TEST-- +DomNode::normalize() +--SKIPIF-- + +--FILE-- + + * + * This is the title + * + * 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) \ No newline at end of file