File: bug67440.phpt

package info (click to toggle)
php8.4 8.4.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 211,276 kB
  • sloc: ansic: 1,176,142; php: 35,419; sh: 11,964; cpp: 7,208; pascal: 4,951; javascript: 3,091; asm: 2,817; yacc: 2,411; makefile: 696; xml: 446; python: 301; awk: 148
file content (151 lines) | stat: -rw-r--r-- 5,946 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
--TEST--
Bug #67440 (append_node of a DOMDocumentFragment does not reconcile namespaces)
--EXTENSIONS--
dom
--FILE--
<?php

function createDocument() {
    $document = new DOMDocument();
    $document->loadXML('<?xml version="1.0"?><rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2"></rootElement>');
    $fragment = $document->createDocumentFragment();
    $fragment->appendChild($document->createTextNode("\n"));
    $fragment->appendChild($document->createElementNS('http://example/ns', 'myns:childNode', '1'));
    $fragment->appendChild($document->createTextNode("\n"));
    $fragment->appendChild($document->createElementNS('http://example/ns', 'myns:childNode', '2'));
    $fragment->appendChild($document->createTextNode("\n"));
    return array($document, $fragment);
}

function case1($method) {
    list($document, $fragment) = createDocument();
    $document->documentElement->{$method}($fragment);
    echo $document->saveXML();
}

function case2($method) {
    list($document, $fragment) = createDocument();
    $childNodes = iterator_to_array($fragment->childNodes);
    foreach ($childNodes as $childNode) {
        $document->documentElement->{$method}($childNode);
    }
    echo $document->saveXML();
}

function case3($method) {
    list($document, $fragment) = createDocument();
    $fragment->removeChild($fragment->firstChild);
    $document->documentElement->{$method}($fragment);
    echo $document->saveXML();
}

function case4($method) {
    list($document, $fragment) = createDocument();
    $fragment->childNodes[1]->appendChild($document->createElementNS('http://example/ns2', 'myns2:childNode', '3'));
    $document->documentElement->{$method}($fragment);
    echo $document->saveXML();
}

echo "== appendChild ==\n";
echo "-- fragment to document element --\n"; case1('appendChild'); echo "\n";
echo "-- children manually document element --\n"; case2('appendChild'); echo "\n";
echo "-- fragment to document where first element is not a text node --\n"; case3('appendChild'); echo "\n";
echo "-- fragment with namespace declarations in children --\n"; case4('appendChild'); echo "\n";

echo "== insertBefore ==\n";
echo "-- fragment to document element --\n"; case1('insertBefore'); echo "\n";
echo "-- children manually document element --\n"; case2('insertBefore'); echo "\n";
echo "-- fragment to document where first element is not a text node --\n"; case3('insertBefore'); echo "\n";
echo "-- fragment with namespace declarations in children --\n"; case4('insertBefore'); echo "\n";

echo "== insertAfter ==\n";
echo "-- fragment to document element --\n"; case1('insertBefore'); echo "\n";
echo "-- children manually document element --\n"; case2('insertBefore'); echo "\n";
echo "-- fragment to document where first element is not a text node --\n"; case3('insertBefore'); echo "\n";
echo "-- fragment with namespace declarations in children --\n"; case4('insertBefore'); echo "\n";

?>
--EXPECT--
== appendChild ==
-- fragment to document element --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2">
<myns:childNode>1</myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

-- children manually document element --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2">
<myns:childNode>1</myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

-- fragment to document where first element is not a text node --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2"><myns:childNode>1</myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

-- fragment with namespace declarations in children --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2">
<myns:childNode>1<myns2:childNode>3</myns2:childNode></myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

== insertBefore ==
-- fragment to document element --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2">
<myns:childNode>1</myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

-- children manually document element --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2">
<myns:childNode>1</myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

-- fragment to document where first element is not a text node --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2"><myns:childNode>1</myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

-- fragment with namespace declarations in children --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2">
<myns:childNode>1<myns2:childNode>3</myns2:childNode></myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

== insertAfter ==
-- fragment to document element --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2">
<myns:childNode>1</myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

-- children manually document element --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2">
<myns:childNode>1</myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

-- fragment to document where first element is not a text node --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2"><myns:childNode>1</myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>

-- fragment with namespace declarations in children --
<?xml version="1.0"?>
<rootElement xmlns:myns="http://example/ns" xmlns:myns2="http://example/ns2">
<myns:childNode>1<myns2:childNode>3</myns2:childNode></myns:childNode>
<myns:childNode>2</myns:childNode>
</rootElement>