Skip to content
This repository was archived by the owner on Oct 12, 2024. It is now read-only.

Commit dca2b0e

Browse files
committed
Added dump() method to element
1 parent b135378 commit dca2b0e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/Element.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,15 @@ public function evaluate($expression, \DOMNode $context = null)
4949
{
5050
return $this->ownerDocument->xpath()->evaluate($expression, $context ?: $this);
5151
}
52+
53+
/**
54+
* Dump the current node
55+
*/
56+
public function dump()
57+
{
58+
$document = new Document();
59+
$document->appendChild($document->importNode($this, true));
60+
61+
return $document->dump();
62+
}
5263
}

tests/Unit/ElementTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ public function testQueryOneNone()
7979
$this->assertNull($node);
8080
}
8181

82+
/**
83+
* It should return the XML contained in the node.
84+
*/
85+
public function testDumpNode()
86+
{
87+
$this->element->appendElement('boo');
88+
$dump = $this->element->dump();
89+
90+
$this->assertEquals(<<<EOT
91+
<?xml version="1.0"?>
92+
<test>
93+
<boo/>
94+
</test>
95+
96+
EOT
97+
, $dump);
98+
}
99+
82100
private function getXml()
83101
{
84102
$xml = <<<EOT

0 commit comments

Comments
 (0)