xref: /PHP-8.2/ext/dom/tests/bug81642.phpt (revision 23f70025)
1--TEST--
2Bug #81642 (DOMChildNode::replaceWith() bug when replacing a node with itself)
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8// Replace with itself
9$doc = new DOMDocument();
10$doc->appendChild($target = $doc->createElement('test'));
11$target->replaceWith($target);
12var_dump($doc->saveXML());
13
14// Replace with itself + another element
15$doc = new DOMDocument();
16$doc->appendChild($target = $doc->createElement('test'));
17$target->replaceWith($target, $doc->createElement('foo'));
18var_dump($doc->saveXML());
19
20// Replace with text node
21$doc = new DOMDocument();
22$doc->appendChild($target = $doc->createElement('test'));
23$target->replaceWith($target, 'foo');
24var_dump($doc->saveXML());
25
26// Replace with text node variant 2
27$doc = new DOMDocument();
28$doc->appendChild($target = $doc->createElement('test'));
29$target->replaceWith('bar', $target, 'foo');
30var_dump($doc->saveXML());
31
32?>
33--EXPECT--
34string(30) "<?xml version="1.0"?>
35<test/>
36"
37string(37) "<?xml version="1.0"?>
38<test/>
39<foo/>
40"
41string(34) "<?xml version="1.0"?>
42<test/>
43foo
44"
45string(38) "<?xml version="1.0"?>
46bar
47<test/>
48foo
49"
50