|
| 1 | +--TEST-- |
| 2 | +setAttributeNodeNS with same URI but different prefix |
| 3 | +--EXTENSIONS-- |
| 4 | +dom |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +// Spec doesn't require to remove redundant namespace declarations. |
| 8 | +// This means that when appending a new attribute the old namespace declaration is reused, hence the prefix stays "foo". |
| 9 | +// Firefox cleans up the old namespace declaration, so there the prefix does change. |
| 10 | +// Chrome doesn't clean it up, so there the prefix doesn't change. |
| 11 | +// Our behaviour is the same as Chrome's due to implementation difficulties. |
| 12 | +$doc = new DOMDocument(); |
| 13 | +$doc->appendChild($doc->createElement('container')); |
| 14 | +$attribute = $doc->createAttributeNS('http://php.net/ns1', 'foo:hello'); |
| 15 | +$attribute->nodeValue = '1'; |
| 16 | +var_dump($doc->documentElement->setAttributeNodeNS($attribute)?->nodeValue); |
| 17 | +echo $doc->saveXML(), "\n"; |
| 18 | +$attribute = $doc->createAttributeNS('http://php.net/ns1', 'bar:hello'); |
| 19 | +$attribute->nodeValue = '2'; |
| 20 | +var_dump($doc->documentElement->setAttributeNodeNS($attribute)?->nodeValue); |
| 21 | +echo $doc->saveXML(), "\n"; |
| 22 | +$attribute = $doc->createAttributeNS('http://php.net/ns1', 'hello'); |
| 23 | +$attribute->nodeValue = '3'; |
| 24 | +var_dump($doc->documentElement->setAttributeNodeNS($attribute)?->nodeValue); |
| 25 | +echo $doc->saveXML(), "\n"; |
| 26 | +?> |
| 27 | +--EXPECT-- |
| 28 | +NULL |
| 29 | +<?xml version="1.0"?> |
| 30 | +<container xmlns:foo="http://php.net/ns1" foo:hello="1"/> |
| 31 | + |
| 32 | +string(1) "1" |
| 33 | +<?xml version="1.0"?> |
| 34 | +<container xmlns:foo="http://php.net/ns1" foo:hello="2"/> |
| 35 | + |
| 36 | +string(1) "2" |
| 37 | +<?xml version="1.0"?> |
| 38 | +<container xmlns:foo="http://php.net/ns1" foo:hello="3"/> |
0 commit comments