1--TEST--
2Renaming an attribute node to a name that already exists
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$dom = DOM\XMLDocument::createFromString(<<<XML
9<!DOCTYPE root [
10    <!ELEMENT implied-attribute ANY>
11    <!ATTLIST implied-attribute hello CDATA #FIXED "world">
12]>
13<root a="b" c="d" xmlns:ns1="urn:a" ns1:foo="bar">
14    <implied-attribute my-attr="x"/>
15    <implied-attribute my-attr="x"/>
16</root>
17XML, LIBXML_DTDATTR);
18
19$root = $dom->documentElement;
20try {
21    $root->attributes[0]->rename(NULL, 'c');
22} catch (DOMException $e) {
23    echo $e->getMessage(), "\n";
24}
25try {
26    $root->attributes[0]->rename(NULL, 'c');
27} catch (DOMException $e) {
28    echo $e->getMessage(), "\n";
29}
30try {
31    $root->attributes[1]->rename(NULL, 'a');
32} catch (DOMException $e) {
33    echo $e->getMessage(), "\n";
34}
35try {
36    $root->attributes[1]->rename('urn:a', 'foo');
37} catch (DOMException $e) {
38    echo $e->getMessage(), "\n";
39}
40try {
41    $root->attributes[3]->rename('', 'a');
42} catch (DOMException $e) {
43    echo $e->getMessage(), "\n";
44}
45try {
46    $root->firstElementChild->attributes[0]->rename(NULL, 'hello');
47} catch (DOMException $e) {
48    echo $e->getMessage(), "\n";
49}
50try {
51    $root->firstElementChild->attributes[1]->rename(NULL, 'my-attr');
52} catch (DOMException $e) {
53    echo $e->getMessage(), "\n";
54}
55
56// This is here to validate that nothing actually changed
57echo $dom->saveXML();
58
59?>
60--EXPECT--
61An attribute with the given name in the given namespace already exists
62An attribute with the given name in the given namespace already exists
63An attribute with the given name in the given namespace already exists
64An attribute with the given name in the given namespace already exists
65An attribute with the given name in the given namespace already exists
66An attribute with the given name in the given namespace already exists
67<?xml version="1.0" encoding="UTF-8"?>
68<!DOCTYPE root [
69<!ELEMENT implied-attribute ANY>
70<!ATTLIST implied-attribute hello CDATA #FIXED "world">
71]>
72<root xmlns:ns1="urn:a" a="b" c="d" ns1:foo="bar">
73    <implied-attribute my-attr="x" hello="world"/>
74    <implied-attribute my-attr="x" hello="world"/>
75</root>
76