Skip to content

Commit 75acba3

Browse files
committed
Started on some unit tests.
1 parent 24b9c67 commit 75acba3

3 files changed

Lines changed: 130 additions & 0 deletions

File tree

tests/bootstrap.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
require_once 'src/simplexml_dump.php';
4+
require_once 'src/simplexml_tree.php';
5+
6+
class simplexml_dump_bootstrap extends PHPUnit_Framework_TestCase
7+
{
8+
public function setUp()
9+
{
10+
$this->simpleXML = simplexml_load_string('<?xml version="1.0" standalone="yes"?>
11+
<movies>
12+
<movie>
13+
<title>PHP: Behind the Parser</title>
14+
<characters>
15+
<character>
16+
<name>Ms. Coder</name>
17+
<actor>Onlivia Actora</actor>
18+
</character>
19+
<character>
20+
<name>Mr. Coder</name>
21+
<actor>El Act&#211;r</actor>
22+
</character>
23+
</characters>
24+
<plot>
25+
So, this language. It\'s like, a programming language.
26+
Or is it a scripting language? All is revealed in this
27+
thrilling horror spoof of a documentary.
28+
</plot>
29+
<great-lines>
30+
<line>PHP solves all my web problems</line>
31+
</great-lines>
32+
<rating type="thumbs">7</rating>
33+
<rating type="stars">5</rating>
34+
</movie>
35+
</movies>
36+
');
37+
38+
$this->simpleXML_NS = simplexml_load_string('<?xml version="1.0" standalone="yes"?>
39+
<movies xmlns:test="https://github.com/IMSoP/simplexml_debug">
40+
<test:movie>
41+
<test:title>PHP: Behind the Parser</test:title>
42+
<test:characters>
43+
<test:character>
44+
<test:name>Ms. Coder</test:name>
45+
<test:actor>Onlivia Actora</test:actor>
46+
</test:character>
47+
<test:character>
48+
<test:name>Mr. Coder</test:name>
49+
<test:actor>El Act&#211;r</test:actor>
50+
</test:character>
51+
</test:characters>
52+
<test:plot>
53+
So, this language. It\'s like, a programming language.
54+
Or is it a scripting language? All is revealed in this
55+
thrilling horror spoof of a documentary.
56+
</test:plot>
57+
<test:great-lines>
58+
<test:line>PHP solves all my web problems</test:line>
59+
</test:great-lines>
60+
<test:rating type="thumbs">7</test:rating>
61+
<test:rating type="stars">5</test:rating>
62+
</test:movie>
63+
</movies>
64+
');
65+
}
66+
}
67+
68+
?>

tests/simplexml_dump_Test.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
class simplexml_dump_Test extends simplexml_dump_bootstrap
4+
{
5+
public function setUp()
6+
{
7+
$this->expected = "SimpleXML object (1 item)
8+
[
9+
Element {
10+
Name: 'movies'
11+
String Content: '
12+
13+
'
14+
Content in Default Namespace
15+
Children: 1 - 1 'movie'
16+
Attributes: 0
17+
}
18+
]
19+
";
20+
21+
$this->expected_NS = "SimpleXML object (1 item)
22+
[
23+
Element {
24+
Name: 'movies'
25+
String Content: '
26+
27+
'
28+
Content in Namespace test
29+
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
30+
Children: 1 - 1 'movie'
31+
Attributes: 0
32+
}
33+
]
34+
";
35+
36+
parent::setUp();
37+
}
38+
39+
public function testDump()
40+
{
41+
ob_start();
42+
simplexml_dump($this->simpleXML);
43+
$return = ob_get_contents();
44+
ob_end_clean();
45+
46+
$this->assertEquals($this->expected, $return);
47+
}
48+
49+
public function testDumpReturn()
50+
{
51+
$return = simplexml_dump($this->simpleXML, true);
52+
$this->assertEquals($this->expected, $return);
53+
}
54+
55+
public function testDumpWithNS()
56+
{
57+
$return = simplexml_dump($this->simpleXML_NS, true);
58+
$this->assertEquals($this->expected_NS, $return);
59+
}
60+
}
61+
62+
?>

tests/simplexml_tree_Test.php

Whitespace-only changes.

0 commit comments

Comments
 (0)