xref: /PHP-7.3/ext/dom/tests/bug34276.phpt (revision b3b51269)
1--TEST--
2Bug #34276 (setAttributeNS and default namespace)
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5--FILE--
6<?php
7$xml = <<<HERE
8<?xml version="1.0" encoding="ISO-8859-1" ?>
9<foo xmlns="http://www.example.com/ns/foo"
10     xmlns:fubar="http://www.example.com/ns/fubar" attra="attra" />
11HERE;
12
13function dump($elems) {
14	foreach ($elems as $elem) {
15		var_dump($elem->nodeName);
16		dump($elem->childNodes);
17	}
18}
19
20$dom = new DOMDocument();
21$dom->loadXML($xml);
22$foo = $dom->documentElement;
23var_dump($foo->hasAttributeNS('http://www.example.com/ns/foo', 'attra'));
24var_dump($foo->getAttributeNS('http://www.example.com/ns/foo', 'attra'));
25
26$foo->setAttributeNS('http://www.example.com/ns/foo', 'attra', 'attranew');
27$foo->setAttributeNS('http://www.example.com/ns/fubar', 'attrb', 'attrbnew');
28$foo->setAttributeNS('http://www.example.com/ns/foo', 'attrc', 'attrc');
29
30var_dump($foo->getAttributeNS('http://www.example.com/ns/foo', 'attra'));
31var_dump($foo->getAttributeNS('http://www.example.com/ns/fubar', 'attrb'));
32var_dump($foo->getAttributeNS('http://www.example.com/ns/foo', 'attrc'));
33
34print $dom->saveXML();
35?>
36--EXPECT--
37bool(false)
38string(0) ""
39string(8) "attranew"
40string(8) "attrbnew"
41string(5) "attrc"
42<?xml version="1.0" encoding="ISO-8859-1"?>
43<foo xmlns="http://www.example.com/ns/foo" xmlns:fubar="http://www.example.com/ns/fubar" xmlns:default="http://www.example.com/ns/foo" attra="attra" default:attra="attranew" fubar:attrb="attrbnew" default:attrc="attrc"/>
44