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