summaryrefslogtreecommitdiff
path: root/ext/dom
diff options
context:
space:
mode:
authorHannes Magnusson <bjori@php.net>2006-10-09 16:02:34 +0000
committerHannes Magnusson <bjori@php.net>2006-10-09 16:02:34 +0000
commite94670d4d6fde6bb34fd4e2ef7b00033d7ac6f31 (patch)
tree28ef2083341aa38276a57282f6c13799e1b75cf7 /ext/dom
parent20fc2d427480db979c575d653b466853cca4b50e (diff)
downloadphp-git-e94670d4d6fde6bb34fd4e2ef7b00033d7ac6f31.tar.gz
MFH tests
Diffstat (limited to 'ext/dom')
-rw-r--r--ext/dom/tests/domattributes.phpt43
-rw-r--r--ext/dom/tests/domchardata.phpt76
-rw-r--r--ext/dom/tests/domelement.phpt114
3 files changed, 233 insertions, 0 deletions
diff --git a/ext/dom/tests/domattributes.phpt b/ext/dom/tests/domattributes.phpt
new file mode 100644
index 0000000000..9097a887e9
--- /dev/null
+++ b/ext/dom/tests/domattributes.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Attributes: DOMAttribute functionality
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--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;
+
+$lang = $node->getAttributeNode('language');
+echo "Language: ".$lang->value."\n";
+
+$lang->value = 'en-US';
+echo "Language: ".$lang->value."\n";
+
+$parent = $lang->ownerElement;
+
+$chapter = new DOMAttr("num", "1");
+$parent->setAttributeNode($chapter);
+
+echo "Is ID?: ".($chapter->isId()?'YES':'NO')."\n";
+
+$top_element = $node->cloneNode();
+
+print $dom->saveXML($top_element);
+
+
+?>
+--EXPECT--
+
+Language: en
+Language: en-US
+Is ID?: NO
+<chapter language="en-US" num="1"/>
+
diff --git a/ext/dom/tests/domchardata.phpt b/ext/dom/tests/domchardata.phpt
new file mode 100644
index 0000000000..6baff6d148
--- /dev/null
+++ b/ext/dom/tests/domchardata.phpt
@@ -0,0 +1,76 @@
+--TEST--
+CharData: DOMCharacterData and related functionality
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--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;
+
+$charnode = $dom->createElement('charnode');
+$node->appendChild($charnode);
+
+/* DOMComment */
+$comment = new DOMComment('Testing character data and extending nodes');
+$charnode->appendChild($comment);
+
+echo "Comment Length: ".$comment->length."\n";
+
+$comment->data = 'Updated comment';
+echo "New Comment Length: ".$comment->length."\n";
+echo "New Comment Data: ".$comment->data."\n";
+
+/* DOMCDataSection */
+$cdata = new DOMCDataSection('Chars: <>&"');
+$charnode->appendChild($cdata);
+
+echo "Substring: ".$cdata->substringData(7, 4)."\n";
+$cdata->replaceData(10, 1, "'");
+echo "New Substring: ".$cdata->substringData(7, 4)."\n";
+
+/* DOMCharacterData using DOMComment */
+$comment = new DOMComment('instructions');
+echo "Comment Value: ".$comment->data."\n";
+$comment->data = 'some more instructions';
+echo "New Comment Value: ".$comment->data."\n";
+
+$comment->insertData(10, 'pi ');
+$comment->replaceData(18, 5, 'i');
+$comment->insertData(20, 'g');
+$comment->deleteData(13, 2);
+$comment->deleteData(10, 3);
+$comment->insertData(10, 'comment ');
+echo "Updated Comment Value: ".$comment->data."\n";
+
+/* DOMText */
+$text = new DOMText('some text characters');
+
+echo "Whole Text: ".$text->wholeText."\n";
+$text2 = $text->splitText(9);
+
+echo "Split text: ".$text2->wholeText."\n";
+$text3 = $text2->splitText(1);
+
+echo "Is Whitespace?: ".($text2->isElementContentWhitespace()?'YES':'NO');
+?>
+--EXPECT--
+
+Comment Length: 42
+New Comment Length: 15
+New Comment Data: Updated comment
+Substring: <>&"
+New Substring: <>&'
+Comment Value: instructions
+New Comment Value: some more instructions
+Updated Comment Value: some more comment strings
+Whole Text: some text characters
+Split text: characters
+Is Whitespace?: YES
diff --git a/ext/dom/tests/domelement.phpt b/ext/dom/tests/domelement.phpt
new file mode 100644
index 0000000000..bc69af602c
--- /dev/null
+++ b/ext/dom/tests/domelement.phpt
@@ -0,0 +1,114 @@
+--TEST--
+Elements: DOMElement functionality
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--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;
+echo "Tag Name: ".$node->tagName."\n";
+
+
+$node->setAttribute('num', '1');
+echo "Chapter: ".$node->getAttribute('num')."\n";
+echo 'Attribute num exists?: '.($node->hasAttribute('num')?'Yes':'No')."\n";
+$node->removeAttribute('num');
+echo "Chapter: ".$node->getAttribute('num')."\n";
+echo 'Attribute num exists?: '.($node->hasAttribute('num')?'Yes':'No')."\n";
+
+echo "Language: ".$node->getAttribute('language')."\n";
+$lang = $node->getAttributeNode('language');
+$lang->nodeValue = 'en-US';
+$node->setAttributeNode($lang);
+echo "Language: ".$node->getAttribute('language')."\n";
+$node->removeAttributeNode($lang);
+echo "Language: ".$node->getAttribute('language')."\n";
+
+echo "\n-- xml:lang --\n";
+$node->setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', 'en');
+echo "Language: ".$node->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang')."\n";
+echo 'Attribute xml:lang exists?: '.($node->hasAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang')?'Yes':'No')."\n";
+
+$node->removeAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang');
+echo "Language: ".$node->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang')."\n";
+echo 'Attribute xml:lang exists?: '.($node->hasAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang')?'Yes':'No')."\n";
+
+$lang = $dom->createAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang');
+$lang->nodeValue = 'en-GB';
+$node->setAttributeNodeNS($lang);
+unset($lang);
+echo "Language: ".$node->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang')."\n";
+$lang = $node->getAttributeNodeNS('http://www.w3.org/XML/1998/namespace', 'lang');
+echo "Language: ".$lang->value."\n";
+
+echo "\n-- Elements --\n";
+$rows = $node->getElementsByTagName('row');
+echo "Row Count: ".$rows->length."\n";
+
+$element_ns = new DOMElement('newns:myelement', 'default content', 'urn::dummyns');
+$node->appendChild($element_ns);
+$element_ns = new DOMElement('newns2:myelement', 'second default content', 'urn::dummyns');
+$node->appendChild($element_ns);
+
+$myelements = $node->getElementsByTagNameNS('urn::dummyns', 'myelement');
+$mylen = $myelements->length;
+echo "myelements Count: ".$mylen."\n";
+
+echo "\n-- IDs --\n";
+$node->setAttribute('idatt', 'n1');
+$node->setIdAttribute('idatt', TRUE);
+
+for ($x = 0; $x < $mylen; $x++) {
+ $current = $myelements->item($x);
+ $current->setAttributeNS('urn::dummyns', 'newns:idatt', 'n'.($x+2))."\n";
+ $current->setIdAttributeNS('urn::dummyns', 'idatt', TRUE);
+}
+
+echo 'Element Name: '.(($elem = $dom->getElementByID('n1'))?$elem->localName:'Not Found')."\n";
+$idatt = $node->getAttributeNode('idatt');
+$node->setIdAttributeNode($idatt, FALSE);
+echo 'Element Name: '.(($elem = $dom->getElementByID('n1'))?$elem->localName:'Not Found')."\n";
+
+echo 'Element Name: '.(($elem = $dom->getElementByID('n3'))?$elem->nodeName:'Not Found')."\n";
+for ($x = 0; $x < $mylen; $x++) {
+ $node = $myelements->item($x);
+ $node->setIdAttributeNS('urn::dummyns', 'idatt', FALSE);
+}
+echo 'Element Name: '.(($elem = $dom->getElementByID('n3'))?$elem->nodeName:'Not Found')."\n";
+?>
+--EXPECT--
+
+Tag Name: chapter
+Chapter: 1
+Attribute num exists?: Yes
+Chapter:
+Attribute num exists?: No
+Language: en
+Language: en-US
+Language:
+
+-- xml:lang --
+Language: en
+Attribute xml:lang exists?: Yes
+Language:
+Attribute xml:lang exists?: No
+Language: en-GB
+Language: en-GB
+
+-- Elements --
+Row Count: 3
+myelements Count: 2
+
+-- IDs --
+Element Name: chapter
+Element Name: Not Found
+Element Name: newns2:myelement
+Element Name: Not Found