1--TEST--
2Node renaming
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$dom = Dom\XMLDocument::createFromString(<<<XML
9<root xmlns:a="urn:a">
10    <a:child attrib="value"/>
11</root>
12XML);
13
14function test($target, $namespaceURI, $qualifiedName) {
15    $namespaceURIPretty = json_encode($namespaceURI);
16    $qualifiedNamePretty = json_encode($qualifiedName);
17    echo "--- rename to $namespaceURIPretty $qualifiedNamePretty ---\n";
18    $target->rename($namespaceURI, $qualifiedName);
19    echo $target->ownerDocument->saveXML(), "\n";
20    var_dump($target->namespaceURI, $target->prefix);
21}
22
23echo "=== Element test ===\n";
24
25test($dom->documentElement, "urn:x", "x:foo");
26test($dom->documentElement, "urn:x", "a:foo");
27test($dom->documentElement, "", "foo");
28test($dom->documentElement, null, "bar");
29
30echo "=== Attribute test ===\n";
31
32$attribute = $dom->documentElement->firstElementChild->attributes[0];
33
34test($attribute, "urn:x", "x:foo");
35test($attribute, "urn:x", "a:foo");
36test($attribute, "", "foo");
37test($attribute, null, "bar");
38
39?>
40--EXPECT--
41=== Element test ===
42--- rename to "urn:x" "x:foo" ---
43<?xml version="1.0" encoding="UTF-8"?>
44<x:foo xmlns:x="urn:x" xmlns:a="urn:a">
45    <a:child attrib="value"/>
46</x:foo>
47string(5) "urn:x"
48string(1) "x"
49--- rename to "urn:x" "a:foo" ---
50<?xml version="1.0" encoding="UTF-8"?>
51<ns1:foo xmlns:ns1="urn:x" xmlns:a="urn:a">
52    <a:child attrib="value"/>
53</ns1:foo>
54string(5) "urn:x"
55string(1) "a"
56--- rename to "" "foo" ---
57<?xml version="1.0" encoding="UTF-8"?>
58<foo xmlns:a="urn:a">
59    <a:child attrib="value"/>
60</foo>
61NULL
62NULL
63--- rename to null "bar" ---
64<?xml version="1.0" encoding="UTF-8"?>
65<bar xmlns:a="urn:a">
66    <a:child attrib="value"/>
67</bar>
68NULL
69NULL
70=== Attribute test ===
71--- rename to "urn:x" "x:foo" ---
72<?xml version="1.0" encoding="UTF-8"?>
73<bar xmlns:a="urn:a">
74    <a:child xmlns:x="urn:x" x:foo="value"/>
75</bar>
76string(5) "urn:x"
77string(1) "x"
78--- rename to "urn:x" "a:foo" ---
79<?xml version="1.0" encoding="UTF-8"?>
80<bar xmlns:a="urn:a">
81    <a:child xmlns:a="urn:x" a:foo="value"/>
82</bar>
83string(5) "urn:x"
84string(1) "a"
85--- rename to "" "foo" ---
86<?xml version="1.0" encoding="UTF-8"?>
87<bar xmlns:a="urn:a">
88    <a:child foo="value"/>
89</bar>
90NULL
91NULL
92--- rename to null "bar" ---
93<?xml version="1.0" encoding="UTF-8"?>
94<bar xmlns:a="urn:a">
95    <a:child bar="value"/>
96</bar>
97NULL
98NULL
99