Go to most recent revision |
Blame |
Last modification |
View Log
| RSS feed
1
<?php
require_once __DIR__ . '/../DOMDocument2.php';
use de\pointedears\dom\DOMDocument2;
class DOMDocument2Test extends \PHPUnit_Framework_Testcase
{
public function testRenameElementNode ()
{
$d = new DOMDocument2();
$d->appendChild($d->createElement("foo"))
->appendChild($d->createElement("bar"))
->setAttributeNS(null, 'evil', 23);
$d->firstChild->setAttributeNS(null, 'answer', 42);
echo "\nBefore:\n\n" . $d->saveXML() . "\n";
$d->renameNode($d->firstChild, null, "baz");
echo "After:\n\n" . $d->saveXML() . "\n";
$this->assertTrue($d->firstChild->nodeName === 'baz');
$this->assertTrue($d->firstChild->firstChild->nodeName === 'bar');
}
public function testRenameAttributeNode ()
{
$d = new DOMDocument2();
$d->appendChild($d->createElement("foo"))
->setAttributeNS(null, 'evil', 42);
echo "\nBefore:\n\n" . $d->saveXML() . "\n";
$attrNode = $d->firstChild->getAttributeNode("evil");
$d->renameNode($attrNode, null, "answer");
echo "After:\n\n" . $d->saveXML();
$this->assertTrue($d->firstChild->getAttribute("answer") === "42");
}
public function testRenameStandaloneAttr ()
{
$d = new DOMDocument2();
$attr = $d->renameNode(new \DOMAttr('evil', '42'), null, "answer");
$this->assertTrue($attr->name === "answer" && $attr->value === "42");
}
}