1--TEST--
2DOMDocument::importNode() with attribute prefix name conflict
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8echo "--- Non-default namespace test case without a default namespace in the destination ---\n";
9
10$dom1 = new DOMDocument();
11$dom2 = new DOMDocument();
12$dom1->loadXML('<?xml version="1.0"?><container xmlns:foo="http://php.net" foo:bar="yes"/>');
13$dom2->loadXML('<?xml version="1.0"?><container xmlns:foo="http://php.net/2"/>');
14$attribute = $dom1->documentElement->getAttributeNode('foo:bar');
15$imported = $dom2->importNode($attribute);
16$dom2->documentElement->setAttributeNodeNS($imported);
17
18echo $dom1->saveXML();
19echo $dom2->saveXML();
20
21echo "--- Non-default namespace test case with a default namespace in the destination ---\n";
22
23$dom1 = new DOMDocument();
24$dom2 = new DOMDocument();
25$dom1->loadXML('<?xml version="1.0"?><container xmlns:foo="http://php.net" foo:bar="yes"/>');
26$dom2->loadXML('<?xml version="1.0"?><container xmlns="http://php.net" xmlns:foo="http://php.net/2"/>');
27$attribute = $dom1->documentElement->getAttributeNode('foo:bar');
28$imported = $dom2->importNode($attribute);
29var_dump($imported->prefix, $imported->namespaceURI);
30$dom2->documentElement->setAttributeNodeNS($imported);
31var_dump($imported->prefix, $imported->namespaceURI);
32
33echo $dom1->saveXML();
34echo $dom2->saveXML();
35
36echo "--- Default namespace test case ---\n";
37
38// We don't expect the namespace to be imported because default namespaces on the same element don't apply to attributes
39// but the attribute should be imported
40$dom1 = new DOMDocument();
41$dom2 = new DOMDocument();
42$dom1->loadXML('<?xml version="1.0"?><container xmlns="http://php.net" bar="yes"/>');
43$dom2->loadXML('<?xml version="1.0"?><container xmlns="http://php.net/2"/>');
44$attribute = $dom1->documentElement->getAttributeNode('bar');
45$imported = $dom2->importNode($attribute);
46$dom2->documentElement->setAttributeNodeNS($imported);
47
48echo $dom1->saveXML();
49echo $dom2->saveXML();
50
51?>
52--EXPECT--
53--- Non-default namespace test case without a default namespace in the destination ---
54<?xml version="1.0"?>
55<container xmlns:foo="http://php.net" foo:bar="yes"/>
56<?xml version="1.0"?>
57<container xmlns:foo="http://php.net/2" xmlns:default="http://php.net" default:bar="yes"/>
58--- Non-default namespace test case with a default namespace in the destination ---
59string(7) "default"
60string(14) "http://php.net"
61string(7) "default"
62string(14) "http://php.net"
63<?xml version="1.0"?>
64<container xmlns:foo="http://php.net" foo:bar="yes"/>
65<?xml version="1.0"?>
66<container xmlns="http://php.net" xmlns:foo="http://php.net/2" xmlns:default="http://php.net" default:bar="yes"/>
67--- Default namespace test case ---
68<?xml version="1.0"?>
69<container xmlns="http://php.net" bar="yes"/>
70<?xml version="1.0"?>
71<container xmlns="http://php.net/2" bar="yes"/>
72