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 hello with world's child and text --\n";
26$dom = clone $dom_original;
27$b_hello = $dom->firstChild->firstChild;
28$b_world = $b_hello->nextSibling;
29$b_hello->append($b_world->firstChild, "foo");
30var_dump($dom->saveHTML());
31
32echo "-- Append world's child with hello --\n";
33$dom = clone $dom_original;
34$b_hello = $dom->firstChild->firstChild;
35$b_world = $b_hello->nextSibling;
36$b_world->firstChild->append($b_hello);
37var_dump($dom->saveHTML());
38
39echo "-- Append hello with itself --\n";
40$dom = clone $dom_original;
41$b_hello = $dom->firstChild->firstChild;
42try {
43    $b_hello->append($b_hello);
44} catch (\DOMException $e) {
45    echo $e->getMessage(), "\n";
46}
47var_dump($dom->saveHTML());
48
49echo "-- Append hello with itself and text --\n";
50$dom = clone $dom_original;
51$b_hello = $dom->firstChild->firstChild;
52try {
53    $b_hello->append($b_hello, "foo");
54} catch (\DOMException $e) {
55    echo $e->getMessage(), "\n";
56}
57var_dump($dom->saveHTML());
58
59echo "-- Append world's i tag with the parent --\n";
60$dom = clone $dom_original;
61$b_hello = $dom->firstChild->firstChild;
62$b_world = $b_hello->nextSibling;
63try {
64    $b_world->firstChild->append($b_world);
65} catch (\DOMException $e) {
66    echo $e->getMessage(), "\n";
67}
68var_dump($dom->saveHTML());
69
70echo "-- Append from another document --\n";
71$dom = clone $dom_original;
72$dom2 = new DOMDocument;
73$dom2->loadXML('<p>other</p>');
74try {
75    $dom->firstChild->firstChild->prepend($dom2->firstChild);
76} catch (\DOMException $e) {
77    echo $e->getMessage(), "\n";
78}
79var_dump($dom2->saveHTML());
80var_dump($dom->saveHTML());
81
82?>
83--EXPECT--
84-- Append hello with world --
85string(39) "<p><b>hello<b><i>world</i></b></b></p>
86"
87-- Append hello with world's child --
88string(39) "<p><b>hello<i>world</i></b><b></b></p>
89"
90-- Append hello with world's child and text --
91string(42) "<p><b>hello<i>world</i>foo</b><b></b></p>
92"
93-- Append world's child with hello --
94string(39) "<p><b><i>world<b>hello</b></i></b></p>
95"
96-- Append hello with itself --
97Hierarchy Request Error
98string(39) "<p><b>hello</b><b><i>world</i></b></p>
99"
100-- Append hello with itself and text --
101Hierarchy Request Error
102string(27) "<p><b><i>world</i></b></p>
103"
104-- Append world's i tag with the parent --
105Hierarchy Request Error
106string(39) "<p><b>hello</b><b><i>world</i></b></p>
107"
108-- Append from another document --
109Wrong Document Error
110string(13) "<p>other</p>
111"
112string(39) "<p><b>hello</b><b><i>world</i></b></p>
113"
114