Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
42 | PointedEar | 1 | <?php |
2 | |||
3 | require_once __DIR__ . '/../DOMDocument2.php'; |
||
4 | |||
5 | use de\pointedears\dom\DOMDocument2; |
||
6 | |||
7 | class DOMDocument2Test extends \PHPUnit_Framework_Testcase |
||
8 | { |
||
9 | public function testRenameElementNode () |
||
10 | { |
||
11 | $d = new DOMDocument2(); |
||
12 | $d->appendChild($d->createElement("foo")) |
||
13 | ->appendChild($d->createElement("bar")) |
||
14 | ->setAttributeNS(null, 'evil', 23); |
||
15 | $d->firstChild->setAttributeNS(null, 'answer', 42); |
||
16 | |||
17 | echo "\nBefore:\n\n" . $d->saveXML() . "\n"; |
||
18 | |||
19 | $d->renameNode($d->firstChild, null, "baz"); |
||
20 | echo "After:\n\n" . $d->saveXML() . "\n"; |
||
21 | |||
22 | $this->assertTrue($d->firstChild->nodeName === 'baz'); |
||
23 | $this->assertTrue($d->firstChild->firstChild->nodeName === 'bar'); |
||
24 | } |
||
25 | |||
26 | public function testRenameAttributeNode () |
||
27 | { |
||
28 | $d = new DOMDocument2(); |
||
29 | $d->appendChild($d->createElement("foo")) |
||
30 | ->setAttributeNS(null, 'evil', 42); |
||
31 | |||
32 | echo "\nBefore:\n\n" . $d->saveXML() . "\n"; |
||
33 | |||
34 | $attrNode = $d->firstChild->getAttributeNode("evil"); |
||
35 | |||
36 | $d->renameNode($attrNode, null, "answer"); |
||
37 | echo "After:\n\n" . $d->saveXML(); |
||
38 | |||
39 | $this->assertTrue($d->firstChild->getAttribute("answer") === "42"); |
||
40 | } |
||
41 | |||
42 | public function testRenameStandaloneAttr () |
||
43 | { |
||
44 | $d = new DOMDocument2(); |
||
45 | $attr = $d->renameNode(new \DOMAttr('evil', '42'), null, "answer"); |
||
46 | $this->assertTrue($attr->name === "answer" && $attr->value === "42"); |
||
47 | } |
||
48 | } |