1--TEST-- 2DOMParentNode::replaceChildren() 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8$dom = new DOMDocument(); 9$dom->loadHTML('<!DOCTYPE HTML><html><p>hi</p> test <p>hi2</p></html>'); 10 11echo "--- Edge cases ---\n"; 12 13try { 14 $dom->documentElement->replaceChildren($dom->documentElement); 15} catch (DOMException $e) { 16 echo $e->getMessage(), "\n"; 17} 18 19try { 20 $dom->documentElement->firstElementChild->replaceChildren($dom->documentElement); 21} catch (DOMException $e) { 22 echo $e->getMessage(), "\n"; 23} 24 25echo "--- Normal cases ---\n"; 26 27$dom->documentElement->replaceChildren('foo', $dom->createElement('p'), 'bar'); 28echo $dom->saveXML(); 29 30$fragment1 = $dom->createDocumentFragment(); 31$fragment1->appendChild($dom->createElement('a')); 32$fragment1->appendChild($dom->createElement('b')); 33$fragment2 = $dom->createDocumentFragment(); 34$fragment2->append('text'); 35$fragment3 = $dom->createDocumentFragment(); 36$dom->documentElement->replaceChildren($fragment1, $fragment2, $fragment3); 37echo $dom->saveXML(); 38 39echo "--- Fragment case ---\n"; 40 41$fragment = $dom->createDocumentFragment(); 42$fragment->replaceChildren(); 43var_dump($dom->saveXML($fragment)); 44 45$old = $fragment->appendChild($dom->createElement('p', 'test')); 46$fragment->replaceChildren($dom->createElement('b', 'test')); 47echo $dom->saveXML($fragment), "\n"; 48var_dump($old->nodeValue); 49 50echo "--- Idempotent case ---\n"; 51 52$dom->replaceChildren($dom->documentElement); 53echo $dom->saveXML(); 54 55echo "--- Removal shortcut ---\n"; 56 57$dom->documentElement->replaceChildren(); 58echo $dom->saveXML(); 59 60?> 61--EXPECT-- 62--- Edge cases --- 63Hierarchy Request Error 64Hierarchy Request Error 65--- Normal cases --- 66<?xml version="1.0" standalone="yes"?> 67<!DOCTYPE HTML> 68<html>foo<p/>bar</html> 69<?xml version="1.0" standalone="yes"?> 70<!DOCTYPE HTML> 71<html><a/><b/>text</html> 72--- Fragment case --- 73string(0) "" 74<b>test</b> 75string(4) "test" 76--- Idempotent case --- 77<?xml version="1.0" standalone="yes"?> 78<html><a/><b/>text</html> 79--- Removal shortcut --- 80<?xml version="1.0" standalone="yes"?> 81<html/> 82