From 72e8a2ec60bf4c0ac3e934313dbf513ec7a78d76 Mon Sep 17 00:00:00 2001 From: Ant Phillips Date: Mon, 1 Dec 2008 11:29:35 +0000 Subject: [PATCH] DOM tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows, Linux and Linux 64 bit). --- .../DOMCharacterData_appendData_basic.phpt | 35 ++++++ .../tests/DOMComment_appendData_basic.phpt | 21 ++++ .../DOMComment_appendData_basic_Sullivan.phpt | 35 ++++++ .../tests/DOMComment_insertData_basic.phpt | 21 ++++ .../tests/DOMComment_insertData_error1.phpt | 24 ++++ .../tests/DOMComment_insertData_error2.phpt | 24 ++++ .../tests/DOMComment_replaceData_basic.phpt | 29 +++++ .../tests/DOMComment_replaceData_error1.phpt | 24 ++++ .../tests/DOMComment_replaceData_error2.phpt | 24 ++++ ...ragment_appendXML_hasChildNodes_basic.phpt | 21 ++++ .../DOMDocument_createAttribute_basic.phpt | 24 ++++ .../DOMDocument_createAttribute_error.phpt | 25 ++++ .../DOMDocument_createAttribute_error1.phpt | 27 +++++ ...DOMDocument_createAttribute_variation.phpt | 12 ++ ...ent_createProcessingInstruction_basic.phpt | 28 +++++ ...ent_createProcessingInstruction_error.phpt | 29 +++++ ext/dom/tests/DOMDocument_loadHTML_basic.phpt | 18 +++ ext/dom/tests/DOMDocument_save_basic.phpt | 33 +++++ .../tests/DOMElement_hasAttributes_basic.phpt | 49 ++++++++ ext/dom/tests/DOMNode_cloneNode_basic.phpt | 111 +++++++++++++++++ .../tests/DOMNode_hasChildNodes_basic.phpt | 43 +++++++ ext/dom/tests/DOMNode_issamenode_basic.phpt | 35 ++++++ ext/dom/tests/DOMNode_normalize_basic.phpt | 64 ++++++++++ ext/dom/tests/DOMNode_removeChild_basic.phpt | 113 ++++++++++++++++++ ext/dom/tests/DOMNode_replaceChild_basic.phpt | 44 +++++++ ext/dom/tests/DOMText_appendData_basic.phpt | 35 ++++++ 26 files changed, 948 insertions(+) create mode 100644 ext/dom/tests/DOMCharacterData_appendData_basic.phpt create mode 100644 ext/dom/tests/DOMComment_appendData_basic.phpt create mode 100644 ext/dom/tests/DOMComment_appendData_basic_Sullivan.phpt create mode 100644 ext/dom/tests/DOMComment_insertData_basic.phpt create mode 100644 ext/dom/tests/DOMComment_insertData_error1.phpt create mode 100644 ext/dom/tests/DOMComment_insertData_error2.phpt create mode 100644 ext/dom/tests/DOMComment_replaceData_basic.phpt create mode 100644 ext/dom/tests/DOMComment_replaceData_error1.phpt create mode 100644 ext/dom/tests/DOMComment_replaceData_error2.phpt create mode 100644 ext/dom/tests/DOMDocumentFragment_appendXML_hasChildNodes_basic.phpt create mode 100644 ext/dom/tests/DOMDocument_createAttribute_basic.phpt create mode 100644 ext/dom/tests/DOMDocument_createAttribute_error.phpt create mode 100644 ext/dom/tests/DOMDocument_createAttribute_error1.phpt create mode 100644 ext/dom/tests/DOMDocument_createAttribute_variation.phpt create mode 100644 ext/dom/tests/DOMDocument_createProcessingInstruction_basic.phpt create mode 100644 ext/dom/tests/DOMDocument_createProcessingInstruction_error.phpt create mode 100644 ext/dom/tests/DOMDocument_loadHTML_basic.phpt create mode 100644 ext/dom/tests/DOMDocument_save_basic.phpt create mode 100644 ext/dom/tests/DOMElement_hasAttributes_basic.phpt create mode 100644 ext/dom/tests/DOMNode_cloneNode_basic.phpt create mode 100644 ext/dom/tests/DOMNode_hasChildNodes_basic.phpt create mode 100644 ext/dom/tests/DOMNode_issamenode_basic.phpt create mode 100644 ext/dom/tests/DOMNode_normalize_basic.phpt create mode 100644 ext/dom/tests/DOMNode_removeChild_basic.phpt create mode 100644 ext/dom/tests/DOMNode_replaceChild_basic.phpt create mode 100644 ext/dom/tests/DOMText_appendData_basic.phpt diff --git a/ext/dom/tests/DOMCharacterData_appendData_basic.phpt b/ext/dom/tests/DOMCharacterData_appendData_basic.phpt new file mode 100644 index 0000000000..ee590de80c --- /dev/null +++ b/ext/dom/tests/DOMCharacterData_appendData_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +DOMCharacterData::appendData basic functionality test +--CREDITS-- +Mike Sullivan +#TestFest 2008 (London) +--FILE-- +createElement('root'); +$document->appendChild($root); + +$cdata = $document->createElement('cdata'); +$root->appendChild($cdata); + +$cdatanode = $document->createCDATASection(''); +$cdata->appendChild($cdatanode); +$cdatanode->appendData('data'); +echo "CDATA Length (one append): " . $cdatanode->length . "\n"; + +$cdatanode->appendData('><&"'); +echo "CDATA Length (two appends): " . $cdatanode->length . "\n"; + +echo "CDATA Content: " . $cdatanode->data . "\n"; + +echo "\n" . $document->saveXML(); + +?> +--EXPECT-- +CDATA Length (one append): 4 +CDATA Length (two appends): 8 +CDATA Content: data><&" + + +<&"]]> \ No newline at end of file diff --git a/ext/dom/tests/DOMComment_appendData_basic.phpt b/ext/dom/tests/DOMComment_appendData_basic.phpt new file mode 100644 index 0000000000..c756f1665a --- /dev/null +++ b/ext/dom/tests/DOMComment_appendData_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test adding data to a DOMComment +--CREDITS-- +Andrew Larssen +London TestFest 2008 +--SKIPIF-- + +--FILE-- +createComment('test-comment'); +$comment->appendData('-more-data'); +$dom->appendChild($comment); +$dom->saveXML(); +echo $dom->saveXML(); + +?> +--EXPECTF-- + + \ No newline at end of file diff --git a/ext/dom/tests/DOMComment_appendData_basic_Sullivan.phpt b/ext/dom/tests/DOMComment_appendData_basic_Sullivan.phpt new file mode 100644 index 0000000000..b7d90a1194 --- /dev/null +++ b/ext/dom/tests/DOMComment_appendData_basic_Sullivan.phpt @@ -0,0 +1,35 @@ +--TEST-- +DOMComment::appendData basic functionality test +--CREDITS-- +Mike Sullivan +#TestFest 2008 (London) +--FILE-- +createElement('root'); +$document->appendChild($root); + +$comment = $document->createElement('comment'); +$root->appendChild($comment); + +$commentnode = $document->createComment(''); +$comment->appendChild($commentnode); +$commentnode->appendData('data'); +echo "Comment Length (one append): " . $commentnode->length . "\n"; + +$commentnode->appendData('><&"'); +echo "Comment Length (two appends): " . $commentnode->length . "\n"; + +echo "Comment Content: " . $commentnode->data . "\n"; + +echo "\n" . $document->saveXML(); + +?> +--EXPECT-- +Comment Length (one append): 4 +Comment Length (two appends): 8 +Comment Content: data><&" + + + \ No newline at end of file diff --git a/ext/dom/tests/DOMComment_insertData_basic.phpt b/ext/dom/tests/DOMComment_insertData_basic.phpt new file mode 100644 index 0000000000..5a4857d677 --- /dev/null +++ b/ext/dom/tests/DOMComment_insertData_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test inserting data into a DOMComment basic test +--CREDITS-- +Andrew Larssen +London TestFest 2008 +--SKIPIF-- + +--FILE-- +createComment('test-comment'); +$comment->insertData(4,'-inserted'); +$dom->appendChild($comment); +echo $dom->saveXML(); + +?> +--EXPECTF-- + + diff --git a/ext/dom/tests/DOMComment_insertData_error1.phpt b/ext/dom/tests/DOMComment_insertData_error1.phpt new file mode 100644 index 0000000000..56922ac518 --- /dev/null +++ b/ext/dom/tests/DOMComment_insertData_error1.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test inserting data into a DOMComment basic test +--CREDITS-- +Andrew Larssen +London TestFest 2008 +--SKIPIF-- + +--FILE-- +createComment('test-comment'); +try { + $comment->insertData(-1,'-inserted'); +} catch (DOMException $e ) { + if ($e->getMessage() == 'Index Size Error'){ + echo "Throws DOMException for -ve offset\n"; + } +} + +?> +--EXPECTF-- +Throws DOMException for -ve offset diff --git a/ext/dom/tests/DOMComment_insertData_error2.phpt b/ext/dom/tests/DOMComment_insertData_error2.phpt new file mode 100644 index 0000000000..d2affa89e7 --- /dev/null +++ b/ext/dom/tests/DOMComment_insertData_error2.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test inserting data into a DOMComment basic test +--CREDITS-- +Andrew Larssen +London TestFest 2008 +--SKIPIF-- + +--FILE-- +createComment('test-comment'); +try { + $comment->insertData(999,'-inserted'); +} catch (DOMException $e ) { + if ($e->getMessage() == 'Index Size Error'){ + echo "Throws DOMException for offset too large\n"; + } +} + +?> +--EXPECTF-- +Throws DOMException for offset too large \ No newline at end of file diff --git a/ext/dom/tests/DOMComment_replaceData_basic.phpt b/ext/dom/tests/DOMComment_replaceData_basic.phpt new file mode 100644 index 0000000000..10bf677ff3 --- /dev/null +++ b/ext/dom/tests/DOMComment_replaceData_basic.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test replacing data into a DOMComment basic test +--CREDITS-- +Andrew Larssen +London TestFest 2008 +--SKIPIF-- + +--FILE-- +createComment('test-comment'); +$comment->replaceData(4,1,'replaced'); +$dom->appendChild($comment); +echo $dom->saveXML(); + +// Replaces rest of string if count is greater than length of existing string +$dom = new DomDocument(); +$comment = $dom->createComment('test-comment'); +$comment->replaceData(0,50,'replaced'); +$dom->appendChild($comment); +echo $dom->saveXML(); + +?> +--EXPECTF-- + + + + diff --git a/ext/dom/tests/DOMComment_replaceData_error1.phpt b/ext/dom/tests/DOMComment_replaceData_error1.phpt new file mode 100644 index 0000000000..4ae4cb61da --- /dev/null +++ b/ext/dom/tests/DOMComment_replaceData_error1.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test replacing data into a DOMComment basic test +--CREDITS-- +Andrew Larssen +London TestFest 2008 +--SKIPIF-- + +--FILE-- +createComment('test-comment'); +try { + $comment->replaceData(-1,4,'-inserted'); +} catch (DOMException $e ) { + if ($e->getMessage() == 'Index Size Error'){ + echo "Throws DOMException for -ve offest\n"; + } +} + +?> +--EXPECTF-- +Throws DOMException for -ve offest diff --git a/ext/dom/tests/DOMComment_replaceData_error2.phpt b/ext/dom/tests/DOMComment_replaceData_error2.phpt new file mode 100644 index 0000000000..89614f9756 --- /dev/null +++ b/ext/dom/tests/DOMComment_replaceData_error2.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test replacing data into a DOMComment basic test +--CREDITS-- +Andrew Larssen +London TestFest 2008 +--SKIPIF-- + +--FILE-- +createComment('test-comment'); +try { + $comment->replaceData(999,4,'-inserted'); +} catch (DOMException $e ) { + if ($e->getMessage() == 'Index Size Error'){ + echo "Throws DOMException for offest too large\n"; + } +} + +?> +--EXPECTF-- +Throws DOMException for offest too large \ No newline at end of file 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_createAttribute_basic.phpt b/ext/dom/tests/DOMDocument_createAttribute_basic.phpt new file mode 100644 index 0000000000..5205a3e30f --- /dev/null +++ b/ext/dom/tests/DOMDocument_createAttribute_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +DomDocument::createAttribute() - basic test for DomDocument::createAttribute() +--CREDITS-- +Muhammad Khalid Adnan +# TestFest 2008 +--FILE-- +createElement("para"); +$newnode = $doc->appendChild($node); + +// A pass case. +$test_attribute = $doc->createAttribute("hahaha"); +$node->appendChild($test_attribute); + +echo $doc->saveXML(); + +?> +--EXPECT-- + + + diff --git a/ext/dom/tests/DOMDocument_createAttribute_error.phpt b/ext/dom/tests/DOMDocument_createAttribute_error.phpt new file mode 100644 index 0000000000..3b318d40d2 --- /dev/null +++ b/ext/dom/tests/DOMDocument_createAttribute_error.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test DOMDocument::createAttribute() for expected expection thrown when wrong parameter passed +--FILE-- +createAttribute(0); +} +catch(DOMException $e) { + $code = $e->getCode(); + if(DOM_INVALID_CHARACTER_ERR === $code) { + echo "PASS"; + } + else { + echo 'Wrong exception code'; + } +} +catch(Exception $e) { + echo 'Wrong exception thrown'; +} + +?> +--EXPECTF-- +PASS diff --git a/ext/dom/tests/DOMDocument_createAttribute_error1.phpt b/ext/dom/tests/DOMDocument_createAttribute_error1.phpt new file mode 100644 index 0000000000..153b18b5a2 --- /dev/null +++ b/ext/dom/tests/DOMDocument_createAttribute_error1.phpt @@ -0,0 +1,27 @@ +--TEST-- +DomDocument::createAttribute() - error test for DomDocument::createAttribute() +--CREDITS-- +Muhammad Khalid Adnan +# TestFest 2008 +--FILE-- +createElement("para"); +$newnode = $doc->appendChild($node); + +try { + $failed_test_attribute = $doc->createAttribute("ha haha"); + $node->appendChild($failed_test_attribute); + + echo $doc->saveXML(); +} +catch (DOMException $e) { + echo 'Test failed!', PHP_EOL; +} + +?> +--EXPECT-- +Test failed! + diff --git a/ext/dom/tests/DOMDocument_createAttribute_variation.phpt b/ext/dom/tests/DOMDocument_createAttribute_variation.phpt new file mode 100644 index 0000000000..f00493455c --- /dev/null +++ b/ext/dom/tests/DOMDocument_createAttribute_variation.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test DOMDocument::createAttribute() for expected return value +--FILE-- +createAttribute('string'); +echo get_class($attr); + +?> +--EXPECTF-- +DOMAttr diff --git a/ext/dom/tests/DOMDocument_createProcessingInstruction_basic.phpt b/ext/dom/tests/DOMDocument_createProcessingInstruction_basic.phpt new file mode 100644 index 0000000000..ea0910417c --- /dev/null +++ b/ext/dom/tests/DOMDocument_createProcessingInstruction_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +DomDocument::createProcessingInstruction() - basic test for DomDocument::createProcessingInstruction() +--CREDITS-- +Muhammad Khalid Adnan +# TestFest 2008 +--FILE-- +createElement("para"); +$newnode = $doc->appendChild($node); + +$test_proc_inst0 = + $doc->createProcessingInstruction( "blablabla" ); +$node->appendChild($test_proc_inst0); + +$test_proc_inst1 = + $doc->createProcessingInstruction( "blablabla", "datadata" ); +$node->appendChild($test_proc_inst1); + +echo $doc->saveXML(); + +?> +--EXPECT-- + + + diff --git a/ext/dom/tests/DOMDocument_createProcessingInstruction_error.phpt b/ext/dom/tests/DOMDocument_createProcessingInstruction_error.phpt new file mode 100644 index 0000000000..d050b17714 --- /dev/null +++ b/ext/dom/tests/DOMDocument_createProcessingInstruction_error.phpt @@ -0,0 +1,29 @@ +--TEST-- +DomDocument::createProcessingInstruction() - error test for DomDocument::createProcessingInstruction() +--CREDITS-- +Muhammad Khalid Adnan +# TestFest 2008 +--FILE-- +createElement("para"); +$newnode = $doc->appendChild($node); + +try { + $test_proc_inst = + $doc->createProcessingInstruction( "bla bla bla" ); + $node->appendChild($test_proc_inst); + + echo $doc->saveXML(); +} +catch (DOMException $e) +{ + echo 'Test failed!', PHP_EOL; +} + +?> +--EXPECT-- +Test failed! + 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/DOMElement_hasAttributes_basic.phpt b/ext/dom/tests/DOMElement_hasAttributes_basic.phpt new file mode 100644 index 0000000000..f0d0c355b8 --- /dev/null +++ b/ext/dom/tests/DOMElement_hasAttributes_basic.phpt @@ -0,0 +1,49 @@ +--TEST-- +DOMNode: hasAttributes() +--CREDITS-- +James Lewis +#TestFest 2008 +--FILE-- +loadXML($xmlstr); +if(!$dom) { + echo "Error while parsing the document\n"; + exit; +} + +$element = $dom->documentElement; + +echo "Verify that we have a DOMElement object:\n"; +var_dump($element); + +echo "\nElement should have attributes:\n"; +var_dump($element->hasAttributes()); + +$nodelist=$dom->getElementsByTagName('tbody') ; +$element = $nodelist->item(0); + +echo "\nVerify that we have a DOMElement object:\n"; +var_dump($element); + +echo "\nElement should have no attributes:\n"; +var_dump($element->hasAttributes()) + + +?> +--EXPECTF-- +Verify that we have a DOMElement object: +object(DOMElement)#%d (0) { +} + +Element should have attributes: +bool(true) + +Verify that we have a DOMElement object: +object(DOMElement)#%d (0) { +} + +Element should have no attributes: +bool(false) diff --git a/ext/dom/tests/DOMNode_cloneNode_basic.phpt b/ext/dom/tests/DOMNode_cloneNode_basic.phpt new file mode 100644 index 0000000000..16b8533f71 --- /dev/null +++ b/ext/dom/tests/DOMNode_cloneNode_basic.phpt @@ -0,0 +1,111 @@ +--TEST-- +DOM cloneNode : Basic Functionality +--SKIPIF-- + +--CREDITS-- +Simon Hughes +--FILE-- + + + + + c1n1 + c1n2 + + + + + c2n1 + c2n2 + + + +EOXML; + +function dumpcourse($current) { + $title = ($current->nodeType != XML_TEXT_NODE && $current->hasAttribute('title')) ? $current->getAttribute('title'):"no title"; + echo "Course: $title:";var_dump($current); + echo "~";var_dump($current->textContent); +} + +$dom = new DOMDocument(); +$dom->loadXML($xml); +$root = $dom->documentElement; + +// strip all text nodes from this tree +$children = $root->childNodes; +$len = $children->length; +for ($index = $children->length - 1; $index >=0; $index--) { + $current = $children->item($index); + if ($current->nodeType == XML_TEXT_NODE) { + $noderemoved = $root->removeChild($current); + } +} + +echo "Start cloneNode test\n"; +$first_course = $children->item(0); +$cloned_first_course_default = $first_course->cloneNode(); +$first_course->setAttribute('title', 'new title1'); + +$cloned_first_course_true = $first_course->cloneNode(true); +$first_course->setAttribute('title', 'new title2'); + +$cloned_first_course_false = $first_course->cloneNode(false); +$first_course->setAttribute('title', 'new title3'); + +$cloned_first_course_default->setAttribute('title', 'new title default'); +$cloned_first_course_true->setAttribute('title', 'new title true'); +$cloned_first_course_false->setAttribute('title', 'new title false'); + +$root->appendChild($cloned_first_course_default); +$root->appendChild($cloned_first_course_true); +$root->appendChild($cloned_first_course_false); + +$children = $root->childNodes; +for ($index = 0; $index < $children->length; $index++) { + echo "node $index\n"; + dumpcourse($children->item($index)); +} + +--EXPECTF-- +Start cloneNode test +node 0 +Course: new title3:object(DOMElement)#6 (0) { +} +~string(24) " + + c1n1 + c1n2 + + " +node 1 +Course: two:object(DOMElement)#3 (0) { +} +~string(24) " + + c2n1 + c2n2 + + " +node 2 +Course: new title default:object(DOMElement)#4 (0) { +} +~string(0) "" +node 3 +Course: new title true:object(DOMElement)#7 (0) { +} +~string(24) " + + c1n1 + c1n2 + + " +node 4 +Course: new title false:object(DOMElement)#8 (0) { +} +~string(0) "" \ No newline at end of file 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_issamenode_basic.phpt b/ext/dom/tests/DOMNode_issamenode_basic.phpt new file mode 100644 index 0000000000..beccb8fb62 --- /dev/null +++ b/ext/dom/tests/DOMNode_issamenode_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +DOMNode: isSameNode() +--CREDITS-- +James Lewis <james@s-1.com> +#TestFest 2008 +--FILE-- +<?php +require_once("dom_test.inc"); + +$dom = new DOMDocument; +$dom->loadXML($xmlstr); +if(!$dom) { + echo "Error while parsing the document\n"; + exit; +} + +$node = $dom->documentElement; +if($node->isSameNode($node)) + echo "EXPECTING SAME NODE, PASSED\n" ; +else + echo "EXPECTING SAME NODE, FAILED\n" ; + +$nodelist=$dom->getElementsByTagName('tbody') ; + +if($nodelist->item(0)->isSameNode($node)) + echo "EXPECTING NOT SAME NODE, FAILED\n" ; +else + echo "EXPECTING NOT SAME NODE, PASSED\n" ; + +?> +===DONE=== +--EXPECT-- +EXPECTING SAME NODE, PASSED +EXPECTING NOT SAME NODE, PASSED +===DONE=== diff --git a/ext/dom/tests/DOMNode_normalize_basic.phpt b/ext/dom/tests/DOMNode_normalize_basic.phpt new file mode 100644 index 0000000000..79f5294d63 --- /dev/null +++ b/ext/dom/tests/DOMNode_normalize_basic.phpt @@ -0,0 +1,64 @@ +--TEST-- +normalize() +--SKIPIF-- +<?php +include('skipif.inc'); +?> +--FILE-- +<?php + +/* Create an XML document + * with structure + * <book> + * <author></author> + * <title>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 diff --git a/ext/dom/tests/DOMNode_removeChild_basic.phpt b/ext/dom/tests/DOMNode_removeChild_basic.phpt new file mode 100644 index 0000000000..8609e58be5 --- /dev/null +++ b/ext/dom/tests/DOMNode_removeChild_basic.phpt @@ -0,0 +1,113 @@ +--TEST-- +DOM removeChild : Basic Functionality +--SKIPIF-- + +--CREDITS-- +Simon Hughes +--FILE-- + + + + + c1n1 + c1n2 + + + + + c2n1 + c2n2 + + + +EOXML; + +function dumpcourse($current) { + $title = ($current->nodeType != XML_TEXT_NODE && $current->hasAttribute('title')) ? $current->getAttribute('title'):"no title"; + echo "Course: $title:";var_dump($current); + echo "~";var_dump($current->textContent); +} + +$dom = new DOMDocument(); +$dom->loadXML($xml); +$root = $dom->documentElement; + +$children = $root->childNodes; +$len = $children->length; +echo "orignal has $len nodes\n"; +for ($index = $children->length - 1; $index >=0; $index--) { + echo "node $index\n"; + $current = $children->item($index); + dumpcourse($current); + if ($current->nodeType == XML_TEXT_NODE) { + $noderemoved = $root->removeChild($current); + } +} +$children = $root->childNodes; +$len = $children->length; +echo "after text removed it now has $len nodes\n"; +for ($index = 0; $index < $children->length; $index++) { + echo "node $index\n"; + $current = $children->item($index); + dumpcourse($current); +} + +--EXPECTF-- +orignal has 5 nodes +node 4 +Course: no title:object(DOMText)#4 (0) { +} +~string(1) " +" +node 3 +Course: two:object(DOMElement)#5 (0) { +} +~string(24) " + + c2n1 + c2n2 + + " +node 2 +Course: no title:object(DOMText)#6 (0) { +} +~string(2) " + " +node 1 +Course: one:object(DOMElement)#4 (0) { +} +~string(24) " + + c1n1 + c1n2 + + " +node 0 +Course: no title:object(DOMText)#5 (0) { +} +~string(2) " + " +after text removed it now has 2 nodes +node 0 +Course: one:object(DOMElement)#3 (0) { +} +~string(24) " + + c1n1 + c1n2 + + " +node 1 +Course: two:object(DOMElement)#4 (0) { +} +~string(24) " + + c2n1 + c2n2 + + " \ 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-- + +--CREDITS-- +Matt Raines +#London TestFest 2008 +--FILE-- +loadXML(' +'); + +// 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: + + +Old child is returned: +bar +Existing child is removed from tree: + + +Children are inserted in order: + + diff --git a/ext/dom/tests/DOMText_appendData_basic.phpt b/ext/dom/tests/DOMText_appendData_basic.phpt new file mode 100644 index 0000000000..6a28a9ae45 --- /dev/null +++ b/ext/dom/tests/DOMText_appendData_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +DOMText::appendData basic functionality test +--CREDITS-- +Mike Sullivan +#TestFest 2008 (London) +--FILE-- +createElement('root'); +$document->appendChild($root); + +$text = $document->createElement('text'); +$root->appendChild($text); + +$textnode = $document->createTextNode(''); +$text->appendChild($textnode); +$textnode->appendData('data'); +echo "Text Length (one append): " . $textnode->length . "\n"; + +$textnode->appendData('><&"'); +echo "Text Length (two appends): " . $textnode->length . "\n"; + +echo "Text Content: " . $textnode->data . "\n"; + +echo "\n" . $document->saveXML(); + +?> +--EXPECT-- +Text Length (one append): 4 +Text Length (two appends): 8 +Text Content: data><&" + + +data><&" \ No newline at end of file -- 2.40.0