1--TEST--
2DOMElement::prepend() 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 "-- Prepend hello with world --\n";
12$dom = clone $dom_original;
13$b_hello = $dom->firstChild->firstChild;
14$b_world = $b_hello->nextSibling;
15$b_hello->prepend($b_world);
16var_dump($dom->saveHTML());
17
18echo "-- Prepend 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->prepend($b_world->firstChild);
23var_dump($dom->saveHTML());
24
25echo "-- Prepend 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->prepend($b_hello);
30var_dump($dom->saveHTML());
31
32echo "-- Prepend hello with itself --\n";
33$dom = clone $dom_original;
34$b_hello = $dom->firstChild->firstChild;
35try {
36    $b_hello->prepend($b_hello);
37} catch (\DOMException $e) {
38    echo $e->getMessage(), "\n";
39}
40var_dump($dom->saveHTML());
41
42echo "-- Prepend 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->prepend($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-- Prepend hello with world --
68string(39) "<p><b><b><i>world</i></b>hello</b></p>
69"
70-- Prepend hello with world's child --
71string(39) "<p><b><i>world</i>hello</b><b></b></p>
72"
73-- Prepend world's child with hello --
74string(39) "<p><b><i><b>hello</b>world</i></b></p>
75"
76-- Prepend hello with itself --
77Hierarchy Request Error
78string(39) "<p><b>hello</b><b><i>world</i></b></p>
79"
80-- Prepend 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