Started on some unit tests.

This commit is contained in:
Josh Sherman 2014-08-07 22:47:07 -04:00
parent 24b9c670a3
commit 75acba318d
3 changed files with 130 additions and 0 deletions

68
tests/bootstrap.php Normal file
View file

@ -0,0 +1,68 @@
<?php
require_once 'src/simplexml_dump.php';
require_once 'src/simplexml_tree.php';
class simplexml_dump_bootstrap extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->simpleXML = simplexml_load_string('<?xml version="1.0" standalone="yes"?>
<movies>
<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&#211;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_NS = simplexml_load_string('<?xml version="1.0" standalone="yes"?>
<movies xmlns:test="https://github.com/IMSoP/simplexml_debug">
<test:movie>
<test:title>PHP: Behind the Parser</test:title>
<test:characters>
<test:character>
<test:name>Ms. Coder</test:name>
<test:actor>Onlivia Actora</test:actor>
</test:character>
<test:character>
<test:name>Mr. Coder</test:name>
<test:actor>El Act&#211;r</test:actor>
</test:character>
</test:characters>
<test: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.
</test:plot>
<test:great-lines>
<test:line>PHP solves all my web problems</test:line>
</test:great-lines>
<test:rating type="thumbs">7</test:rating>
<test:rating type="stars">5</test:rating>
</test:movie>
</movies>
');
}
}
?>

View file

@ -0,0 +1,62 @@
<?php
class simplexml_dump_Test extends simplexml_dump_bootstrap
{
public function setUp()
{
$this->expected = "SimpleXML object (1 item)
[
Element {
Name: 'movies'
String Content: '
'
Content in Default Namespace
Children: 1 - 1 'movie'
Attributes: 0
}
]
";
$this->expected_NS = "SimpleXML object (1 item)
[
Element {
Name: 'movies'
String Content: '
'
Content in Namespace test
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
Children: 1 - 1 'movie'
Attributes: 0
}
]
";
parent::setUp();
}
public function testDump()
{
ob_start();
simplexml_dump($this->simpleXML);
$return = ob_get_contents();
ob_end_clean();
$this->assertEquals($this->expected, $return);
}
public function testDumpReturn()
{
$return = simplexml_dump($this->simpleXML, true);
$this->assertEquals($this->expected, $return);
}
public function testDumpWithNS()
{
$return = simplexml_dump($this->simpleXML_NS, true);
$this->assertEquals($this->expected_NS, $return);
}
}
?>

View file