Test attribute setting better

This commit is contained in:
J. King 2021-04-09 17:48:58 -04:00
parent 0d7f7ef0bf
commit 45411b7ccc
2 changed files with 14 additions and 4 deletions

View file

@ -46,6 +46,14 @@ class Element extends \DOMElement {
return ($tree->current() !== null);
}
public function hasAttribute($name) {
$out = parent::hasAttribute($name);
if (!$out && strpos($name, "xmlns:") === 0 && $this->hasAttributeNS(Parser::XMLNS_NAMESPACE, substr($name, 6))) {
return true;
}
return $out;
}
public function setAttribute($name, $value) {
$this->setAttributeNS(null, $name, $value);
}

View file

@ -128,7 +128,9 @@ class TestDOM extends \PHPUnit\Framework\TestCase {
$d = new Document;
$e = $d->createElementNS($elementNS, "test");
$e->setAttributeNS($attrNS, $nameIn, "test");
$this->assertTrue($e->hasAttributeNS($attrNS, $nameOut));
$this->assertSame(1, $e->attributes->length);
$this->assertTrue($e->hasAttribute($nameOut));
$this->assertSame($attrNS, $e->attributes[0]->namespaceURI);
}
public function provideNamespacedAttributeSettings(): iterable {
@ -141,11 +143,11 @@ class TestDOM extends \PHPUnit\Framework\TestCase {
[null, null, "TEST:TEST", "testU00003Atest"],
["http://www.w3.org/1999/xhtml", null, "test:test", "testU00003Atest"],
["http://www.w3.org/1999/xhtml", null, "TEST:TEST", "testU00003Atest"],
[null, "http://www.w3.org/1999/xhtml", "test:test", "test"],
[null, "http://www.w3.org/1999/xhtml", "TEST:TEST", "TEST"],
[null, "http://www.w3.org/1999/xhtml", "test:test", "test:test"],
[null, "http://www.w3.org/1999/xhtml", "TEST:TEST", "TEST:TEST"],
["http://www.w3.org/1998/Math/MathML", null, "test", "test"],
["http://www.w3.org/1998/Math/MathML", null, "TEST", "TEST"],
[null, "http://www.w3.org/2000/xmlns/", "xmlns:xlink", "xlink"],
[null, "http://www.w3.org/2000/xmlns/", "xmlns:xlink", "xmlns:xlink"],
];
}
}