From: Zoe Slattery Date: Fri, 16 May 2008 17:14:57 +0000 (+0000) Subject: Tests from Testfest 2008 X-Git-Tag: BEFORE_HEAD_NS_CHANGE~1747 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d65cd01035edb3e30d569dcd141f84f430b2b99;p=php Tests from Testfest 2008 --- diff --git a/ext/dom/tests/DOMDocumentFragment_appendXML_hasChildNodes_basic.phpt b/ext/dom/tests/DOMDocumentFragment_appendXML_hasChildNodes_basic.phpt new file mode 100644 index 0000000000..d6fb632132 --- /dev/null +++ b/ext/dom/tests/DOMDocumentFragment_appendXML_hasChildNodes_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +Testing DOMDocumentFragment::appendXML and DOMDocumentFragment::hasChildNodes +--FILE-- +createDocumentFragment(); +if ($fragment->hasChildNodes()) { + echo "has child nodes\n"; +} else { + echo "has no child nodes\n"; +} +$fragment->appendXML('bar'); +if ($fragment->hasChildNodes()) { + echo "has child nodes\n"; +} else { + echo "has no child nodes\n"; +} +--EXPECT-- +has no child nodes +has child nodes diff --git a/ext/dom/tests/DOMDocument_loadHTML_basic.phpt b/ext/dom/tests/DOMDocument_loadHTML_basic.phpt new file mode 100644 index 0000000000..616d1d8371 --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadHTML_basic.phpt @@ -0,0 +1,18 @@ +--TEST-- +DOMDocument::loadHTML +--CREDITS-- +Frank Cassedanne franck@ouarz.net +#London TestFest 2008 +--SKIPIF-- + +--FILE-- +loadHTML("

Test

"); +echo $doc->saveHTML(); +?> +--EXPECTF-- + +

Test

diff --git a/ext/dom/tests/DOMDocument_save_basic.phpt b/ext/dom/tests/DOMDocument_save_basic.phpt new file mode 100644 index 0000000000..c7d1ead24b --- /dev/null +++ b/ext/dom/tests/DOMDocument_save_basic.phpt @@ -0,0 +1,33 @@ +--TEST-- +DOMDocument::save Test basic function of save method +--SKIPIF-- + +--FILE-- +formatOutput = true; + +$root = $doc->createElement('book'); + +$root = $doc->appendChild($root); + +$title = $doc->createElement('title'); +$title = $root->appendChild($title); + +$text = $doc->createTextNode('This is the title'); +$text = $title->appendChild($text); + +$temp_filename = dirname(__FILE__)."/DomDocument_save_basic.tmp"; + +echo 'Wrote: ' . $doc->save($temp_filename) . ' bytes'; // Wrote: 72 bytes +?> +--CLEAN-- + +--EXPECTF-- +Wrote: 72 bytes + diff --git a/ext/dom/tests/DOMNode_hasChildNodes_basic.phpt b/ext/dom/tests/DOMNode_hasChildNodes_basic.phpt new file mode 100644 index 0000000000..3a6f6b4218 --- /dev/null +++ b/ext/dom/tests/DOMNode_hasChildNodes_basic.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test whether a node has child nodes: hasChildNodes() +--SKIPIF-- + +--FILE-- + + * This is the title + * + * Check for child nodes of the , and This is the title + * +*/ + +$doc = new DOMDocument(); + +$root = $doc->createElement('book'); +$doc->appendChild($root); + +$title = $doc->createElement('title'); +$root->appendChild($title); + +$text = $doc->createTextNode('This is the title'); +$title->appendChild($text); + +echo "Root has child nodes: "; +var_dump($root->hasChildNodes()); + +echo "Title has child nodes: "; +var_dump($title->hasChildNodes()); + +echo "Text has child nodes: "; +var_dump($text->hasChildNodes()); + +?> +--EXPECTF-- +Root has child nodes: bool(true) +Title has child nodes: bool(true) +Text has child nodes: bool(false) \ No newline at end of file diff --git a/ext/dom/tests/DOMNode_replaceChild_basic.phpt b/ext/dom/tests/DOMNode_replaceChild_basic.phpt new file mode 100644 index 0000000000..49fc05501f --- /dev/null +++ b/ext/dom/tests/DOMNode_replaceChild_basic.phpt @@ -0,0 +1,44 @@ +--TEST-- +Replacing a child node +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--CREDITS-- +Matt Raines <matt@raines.me.uk> +#London TestFest 2008 +--FILE-- +<?php +$document = new DOMDocument(); +$document->loadXML('<?xml version="1.0" encoding="utf-8"?> +<root><foo><bar/><baz/></foo><spam><eggs/><eggs/></spam></root>'); + +// Replaces the child node oldChild with newChild in the list of children, and +// returns the oldChild node. +$parent = $document->getElementsByTagName('foo')->item(0); +$new_child = $document->createElement('qux'); +$old_child = $parent->replaceChild($new_child, $parent->firstChild); +echo "New child replaces old child:\n" . $document->saveXML(); +echo "Old child is returned:\n" . $old_child->tagName . "\n"; + +// If the newChild is already in the tree, it is first removed. +$parent = $document->getElementsByTagName('spam')->item(0); +$parent->replaceChild($new_child, $parent->firstChild); +echo "Existing child is removed from tree:\n" . $document->saveXML(); + +// Children are inserted in the correct order. +$new_child = $document->getElementsByTagName('spam')->item(0); +$parent = $document->getElementsByTagName('foo')->item(0); +$parent->replaceChild($new_child, $parent->firstChild); +echo "Children are inserted in order:\n" . $document->saveXML(); +?> +--EXPECT-- +New child replaces old child: +<?xml version="1.0" encoding="utf-8"?> +<root><foo><qux/><baz/></foo><spam><eggs/><eggs/></spam></root> +Old child is returned: +bar +Existing child is removed from tree: +<?xml version="1.0" encoding="utf-8"?> +<root><foo><baz/></foo><spam><qux/><eggs/></spam></root> +Children are inserted in order: +<?xml version="1.0" encoding="utf-8"?> +<root><foo><spam><qux/><eggs/></spam></foo></root>