Annotation of embedaddon/php/ext/dom/tests/DOMNode_cloneNode_basic.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: DOM cloneNode : Basic Functionality
3: --SKIPIF--
4: <?php
5: require_once('skipif.inc');
6: ?>
7: --CREDITS--
8: Simon Hughes <odbc3@hotmail.com>
9: --FILE--
10: <?php
11:
12: $xml = <<< EOXML
13: <?xml version="1.0" encoding="ISO-8859-1"?>
14: <courses>
15: <course title="one">
16: <notes>
17: <note>c1n1</note>
18: <note>c1n2</note>
19: </notes>
20: </course>
21: <course title="two">
22: <notes>
23: <note>c2n1</note>
24: <note>c2n2</note>
25: </notes>
26: </course>
27: </courses>
28: EOXML;
29:
30: function dumpcourse($current) {
31: $title = ($current->nodeType != XML_TEXT_NODE && $current->hasAttribute('title')) ? $current->getAttribute('title'):"no title";
1.1.1.2 ! misho 32: echo "Course: $title:";echo(get_class($current)), "\n";
1.1 misho 33: echo "~";var_dump($current->textContent);
34: }
35:
36: $dom = new DOMDocument();
37: $dom->loadXML($xml);
38: $root = $dom->documentElement;
39:
40: // strip all text nodes from this tree
41: $children = $root->childNodes;
42: $len = $children->length;
43: for ($index = $children->length - 1; $index >=0; $index--) {
44: $current = $children->item($index);
45: if ($current->nodeType == XML_TEXT_NODE) {
46: $noderemoved = $root->removeChild($current);
47: }
48: }
49:
50: echo "Start cloneNode test\n";
51: $first_course = $children->item(0);
52: $cloned_first_course_default = $first_course->cloneNode();
53: $first_course->setAttribute('title', 'new title1');
54:
55: $cloned_first_course_true = $first_course->cloneNode(true);
56: $first_course->setAttribute('title', 'new title2');
57:
58: $cloned_first_course_false = $first_course->cloneNode(false);
59: $first_course->setAttribute('title', 'new title3');
60:
61: $cloned_first_course_default->setAttribute('title', 'new title default');
62: $cloned_first_course_true->setAttribute('title', 'new title true');
63: $cloned_first_course_false->setAttribute('title', 'new title false');
64:
65: $root->appendChild($cloned_first_course_default);
66: $root->appendChild($cloned_first_course_true);
67: $root->appendChild($cloned_first_course_false);
68:
69: $children = $root->childNodes;
70: for ($index = 0; $index < $children->length; $index++) {
71: echo "node $index\n";
72: dumpcourse($children->item($index));
73: }
74:
75: --EXPECTF--
76: Start cloneNode test
77: node 0
1.1.1.2 ! misho 78: Course: new title3:DOMElement
1.1 misho 79: ~string(24) "
80:
81: c1n1
82: c1n2
83:
84: "
85: node 1
1.1.1.2 ! misho 86: Course: two:DOMElement
1.1 misho 87: ~string(24) "
88:
89: c2n1
90: c2n2
91:
92: "
93: node 2
1.1.1.2 ! misho 94: Course: new title default:DOMElement
1.1 misho 95: ~string(0) ""
96: node 3
1.1.1.2 ! misho 97: Course: new title true:DOMElement
1.1 misho 98: ~string(24) "
99:
100: c1n1
101: c1n2
102:
103: "
104: node 4
1.1.1.2 ! misho 105: Course: new title false:DOMElement
! 106: ~string(0) ""
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>