xref: /PHP-8.0/ext/dom/tests/bug32615.phpt (revision d679f022)
1--TEST--
2Bug #32615 (Replacing and inserting Fragments)
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5--FILE--
6<?php
7$dom = new DomDocument;
8$frag = $dom->createDocumentFragment();
9$frag->appendChild(new DOMElement('root'));
10$dom->appendChild($frag);
11$root = $dom->documentElement;
12
13$frag->appendChild(new DOMElement('first'));
14$root->appendChild($frag);
15
16$frag->appendChild(new DOMElement('second'));
17$root->appendChild($frag);
18
19$node = $dom->createElement('newfirst');
20$frag->appendChild($node);
21$root->replaceChild($frag, $root->firstChild);
22
23unset($frag);
24$frag = $dom->createDocumentFragment();
25
26$frag->appendChild(new DOMElement('newsecond'));
27$root->replaceChild($frag, $root->lastChild);
28
29$node = $frag->appendChild(new DOMElement('fourth'));
30$root->insertBefore($frag, NULL);
31
32$frag->appendChild(new DOMElement('third'));
33$node = $root->insertBefore($frag, $node);
34
35$frag->appendChild(new DOMElement('start'));
36$root->insertBefore($frag, $root->firstChild);
37
38$frag->appendChild(new DOMElement('newthird'));
39$root->replaceChild($frag, $node);
40
41$frag->appendChild(new DOMElement('newfourth'));
42$root->replaceChild($frag, $root->lastChild);
43
44$frag->appendChild(new DOMElement('first'));
45$root->replaceChild($frag, $root->firstChild->nextSibling);
46
47$root->removeChild($root->firstChild);
48
49echo $dom->saveXML()."\n";
50
51while ($root->hasChildNodes()) {
52   $root->removeChild($root->firstChild);
53}
54
55$frag->appendChild(new DOMElement('first'));
56$root->insertBefore($frag, $root->firstChild);
57
58$node = $frag->appendChild(new DOMElement('fourth'));
59$root->appendChild($frag);
60
61$frag->appendChild(new DOMElement('second'));
62$frag->appendChild(new DOMElement('third'));
63$root->insertBefore($frag, $node);
64
65echo $dom->saveXML()."\n";
66
67$frag = $dom->createDocumentFragment();
68$root = $dom->documentElement;
69$root->replaceChild($frag, $root->firstChild);
70
71echo $dom->saveXML();
72
73?>
74--EXPECT--
75<?xml version="1.0"?>
76<root><first/><newsecond/><newthird/><newfourth/></root>
77
78<?xml version="1.0"?>
79<root><first/><second/><third/><fourth/></root>
80
81<?xml version="1.0"?>
82<root><second/><third/><fourth/></root>
83