1--TEST-- 2DOMElement::append() with hierarchy changes and errors 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8$dom_original = new DOMDocument; 9$dom_original->loadXML('<p><b>hello</b><b><i>world</i></b></p>'); 10 11echo "-- Append hello with world --\n"; 12$dom = clone $dom_original; 13$b_hello = $dom->firstChild->firstChild; 14$b_world = $b_hello->nextSibling; 15$b_hello->append($b_world); 16var_dump($dom->saveHTML()); 17 18echo "-- Append hello with world's child --\n"; 19$dom = clone $dom_original; 20$b_hello = $dom->firstChild->firstChild; 21$b_world = $b_hello->nextSibling; 22$b_hello->append($b_world->firstChild); 23var_dump($dom->saveHTML()); 24 25echo "-- Append world's child with hello --\n"; 26$dom = clone $dom_original; 27$b_hello = $dom->firstChild->firstChild; 28$b_world = $b_hello->nextSibling; 29$b_world->firstChild->append($b_hello); 30var_dump($dom->saveHTML()); 31 32echo "-- Append hello with itself --\n"; 33$dom = clone $dom_original; 34$b_hello = $dom->firstChild->firstChild; 35try { 36 $b_hello->append($b_hello); 37} catch (\DOMException $e) { 38 echo $e->getMessage(), "\n"; 39} 40var_dump($dom->saveHTML()); 41 42echo "-- Append world's i tag with the parent --\n"; 43$dom = clone $dom_original; 44$b_hello = $dom->firstChild->firstChild; 45$b_world = $b_hello->nextSibling; 46try { 47 $b_world->firstChild->append($b_world); 48} catch (\DOMException $e) { 49 echo $e->getMessage(), "\n"; 50} 51var_dump($dom->saveHTML()); 52 53echo "-- Append from another document --\n"; 54$dom = clone $dom_original; 55$dom2 = new DOMDocument; 56$dom2->loadXML('<p>other</p>'); 57try { 58 $dom->firstChild->firstChild->prepend($dom2->firstChild); 59} catch (\DOMException $e) { 60 echo $e->getMessage(), "\n"; 61} 62var_dump($dom2->saveHTML()); 63var_dump($dom->saveHTML()); 64 65?> 66--EXPECT-- 67-- Append hello with world -- 68string(39) "<p><b>hello<b><i>world</i></b></b></p> 69" 70-- Append hello with world's child -- 71string(39) "<p><b>hello<i>world</i></b><b></b></p> 72" 73-- Append world's child with hello -- 74string(39) "<p><b><i>world<b>hello</b></i></b></p> 75" 76-- Append hello with itself -- 77Hierarchy Request Error 78string(39) "<p><b>hello</b><b><i>world</i></b></p> 79" 80-- Append world's i tag with the parent -- 81Hierarchy Request Error 82string(39) "<p><b>hello</b><b><i>world</i></b></p> 83" 84-- Append from another document -- 85Wrong Document Error 86string(13) "<p>other</p> 87" 88string(39) "<p><b>hello</b><b><i>world</i></b></p> 89" 90