diff options
-rw-r--r-- | ext/dom/tests/DOMDocumentFragment_appendXML_hasChildNodes_basic.phpt | 21 | ||||
-rw-r--r-- | ext/dom/tests/DOMDocument_loadHTML_basic.phpt | 18 | ||||
-rw-r--r-- | ext/dom/tests/DOMDocument_save_basic.phpt | 33 | ||||
-rw-r--r-- | ext/dom/tests/DOMNode_hasChildNodes_basic.phpt | 43 | ||||
-rw-r--r-- | ext/dom/tests/DOMNode_replaceChild_basic.phpt | 44 |
5 files changed, 159 insertions, 0 deletions
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-- +<?php +$doc = new DOMDocument(); + +$fragment = $doc->createDocumentFragment(); +if ($fragment->hasChildNodes()) { + echo "has child nodes\n"; +} else { + echo "has no child nodes\n"; +} +$fragment->appendXML('<foo>bar</foo>'); +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-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$doc = new DOMDocument(); +$doc->loadHTML("<html><body><p>Test<br></p></body></html>"); +echo $doc->saveHTML(); +?> +--EXPECTF-- +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> +<html><body><p>Test<br></p></body></html> 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-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$doc = new DOMDocument('1.0'); +$doc->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-- +<?php + $temp_filename = dirname(__FILE__)."/DomDocument_save_basic.tmp"; + unlink($temp_filename); +?> +--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-- +<?php +include('skipif.inc'); +?> +--FILE-- +<?php + +/* Create an XML document + * with strcuture + * <book> + * <title>This is the title</title> + * </book> + * Check for child nodes of the <book>, <title> 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> |