--TEST-- GH-11625 (DOMElement::replaceWith() doesn't replace node with DOMDocumentFragment but just deletes node or causes wrapping <> depending on libxml2 version) --EXTENSIONS-- dom --FILE--
XML; $dom = new DOMDocument(); $dom->loadXML($html); $divs = iterator_to_array($dom->getElementsByTagName('div')->getIterator()); $i = 0; foreach ($divs as $div) { $mutator($dom, $div, $i); echo $dom->saveHTML(); $i++; } } echo "--- Single replacement ---\n"; test(function($dom, $div, $i) { $fragment = $dom->createDocumentFragment(); $fragment->appendXML("

Hi $i!

"); $div->replaceWith($fragment); }); echo "--- Multiple replacement ---\n"; test(function($dom, $div, $i) { $fragment = $dom->createDocumentFragment(); $fragment->appendXML("

Hi $i!

"); $div->replaceWith($fragment, $dom->createElement('x'), "hello"); }); echo "--- Empty fragment replacement ---\n"; test(function($dom, $div, $i) { $fragment = $dom->createDocumentFragment(); $div->replaceWith($fragment); }); ?> --EXPECT-- --- Single replacement ---

Hi 0!

Hi 0!

Hi 1!

--- Multiple replacement ---

Hi 0!

hello

Hi 0!

hello

Hi 1!

hello --- Empty fragment replacement ---