Unit tests for dump
Got coverage up to 90% probably need @IMSoP to finish the rest as I'm having a hard time getting tests to hit the logic.
This commit is contained in:
parent
af30ba47b6
commit
3cad264843
2 changed files with 83 additions and 6 deletions
|
@ -35,7 +35,35 @@ class simplexml_dump_bootstrap extends PHPUnit_Framework_TestCase
|
||||||
</movies>
|
</movies>
|
||||||
');
|
');
|
||||||
|
|
||||||
$this->simpleXML_NS = simplexml_load_string('<?xml version="1.0" standalone="yes"?>
|
$this->simpleXML_default_NS = simplexml_load_string('<?xml version="1.0" standalone="yes"?>
|
||||||
|
<movies xmlns="https://github.com/IMSoP/simplexml_debug">
|
||||||
|
<movie>
|
||||||
|
<title>PHP: Behind the Parser</title>
|
||||||
|
<characters>
|
||||||
|
<character>
|
||||||
|
<name>Ms. Coder</name>
|
||||||
|
<actor>Onlivia Actora</actor>
|
||||||
|
</character>
|
||||||
|
<character>
|
||||||
|
<name>Mr. Coder</name>
|
||||||
|
<actor>El ActÓr</actor>
|
||||||
|
</character>
|
||||||
|
</characters>
|
||||||
|
<plot>
|
||||||
|
So, this language. It\'s like, a programming language.
|
||||||
|
Or is it a scripting language? All is revealed in this
|
||||||
|
thrilling horror spoof of a documentary.
|
||||||
|
</plot>
|
||||||
|
<great-lines>
|
||||||
|
<line>PHP solves all my web problems</line>
|
||||||
|
</great-lines>
|
||||||
|
<rating type="thumbs">7</rating>
|
||||||
|
<rating type="stars">5</rating>
|
||||||
|
</movie>
|
||||||
|
</movies>
|
||||||
|
');
|
||||||
|
|
||||||
|
$this->simpleXML_named_NS = simplexml_load_string('<?xml version="1.0" standalone="yes"?>
|
||||||
<movies xmlns:test="https://github.com/IMSoP/simplexml_debug">
|
<movies xmlns:test="https://github.com/IMSoP/simplexml_debug">
|
||||||
<test:movie>
|
<test:movie>
|
||||||
<test:title>PHP: Behind the Parser</test:title>
|
<test:title>PHP: Behind the Parser</test:title>
|
||||||
|
|
|
@ -18,7 +18,25 @@ class simplexml_dump_Test extends simplexml_dump_bootstrap
|
||||||
]
|
]
|
||||||
";
|
";
|
||||||
|
|
||||||
$this->expected_NS = "SimpleXML object (1 item)
|
$this->expected_default_NS = "SimpleXML object (1 item)
|
||||||
|
[
|
||||||
|
Element {
|
||||||
|
Namespace: 'https://github.com/IMSoP/simplexml_debug'
|
||||||
|
(Default Namespace)
|
||||||
|
Name: 'movies'
|
||||||
|
String Content: '
|
||||||
|
|
||||||
|
'
|
||||||
|
Content in Default Namespace
|
||||||
|
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
|
||||||
|
Children: 1 - 1 'movie'
|
||||||
|
Attributes: 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
";
|
||||||
|
|
||||||
|
|
||||||
|
$this->expected_named_NS = "SimpleXML object (1 item)
|
||||||
[
|
[
|
||||||
Element {
|
Element {
|
||||||
Name: 'movies'
|
Name: 'movies'
|
||||||
|
@ -52,13 +70,19 @@ class simplexml_dump_Test extends simplexml_dump_bootstrap
|
||||||
$this->assertEquals($this->expected, $return);
|
$this->assertEquals($this->expected, $return);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDumpWithNS()
|
public function testDumpWithDefaultNS()
|
||||||
{
|
{
|
||||||
$return = simplexml_dump($this->simpleXML_NS, true);
|
$return = simplexml_dump($this->simpleXML_default_NS, true);
|
||||||
$this->assertEquals($this->expected_NS, $return);
|
$this->assertEquals($this->expected_default_NS, $return);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDumpWithSingleNodeWithAttributesAndNS()
|
public function testDumpWithNamedNS()
|
||||||
|
{
|
||||||
|
$return = simplexml_dump($this->simpleXML_named_NS, true);
|
||||||
|
$this->assertEquals($this->expected_named_NS, $return);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDumpAttributeWithNamedNS()
|
||||||
{
|
{
|
||||||
$xml = '<parent xmlns:ns="ns"><ns:child ns:foo="bar" /></parent>';
|
$xml = '<parent xmlns:ns="ns"><ns:child ns:foo="bar" /></parent>';
|
||||||
$sxml = simplexml_load_string($xml);
|
$sxml = simplexml_load_string($xml);
|
||||||
|
@ -74,6 +98,31 @@ class simplexml_dump_Test extends simplexml_dump_bootstrap
|
||||||
Value: 'bar'
|
Value: 'bar'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
";
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $return);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDumpMultipleAttributes()
|
||||||
|
{
|
||||||
|
$xml = '<parent xmlns:ns="ns"><child ns:one="1" ns:two="2" ns:three="3" /></parent>';
|
||||||
|
$sxml = simplexml_load_string($xml);
|
||||||
|
|
||||||
|
$return = simplexml_dump($sxml->child, true);
|
||||||
|
|
||||||
|
$expected = "SimpleXML object (1 item)
|
||||||
|
[
|
||||||
|
Element {
|
||||||
|
Namespace: 'ns'
|
||||||
|
Namespace Alias: 'ns'
|
||||||
|
Name: 'child'
|
||||||
|
String Content: ''
|
||||||
|
Content in Namespace ns
|
||||||
|
Namespace URI: 'ns'
|
||||||
|
Children: 0
|
||||||
|
Attributes: 3 - 'one', 'two', 'three'
|
||||||
|
}
|
||||||
|
]
|
||||||
";
|
";
|
||||||
|
|
||||||
$this->assertEquals($expected, $return);
|
$this->assertEquals($expected, $return);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue