Started on some unit tests.
This commit is contained in:
parent
24b9c670a3
commit
75acba318d
3 changed files with 130 additions and 0 deletions
68
tests/bootstrap.php
Normal file
68
tests/bootstrap.php
Normal 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Ó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Ó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>
|
||||||
|
');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
62
tests/simplexml_dump_Test.php
Normal file
62
tests/simplexml_dump_Test.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
0
tests/simplexml_tree_Test.php
Normal file
0
tests/simplexml_tree_Test.php
Normal file
Loading…
Add table
Add a link
Reference in a new issue