Skip to content

Commit 3cad264

Browse files
committed
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.
1 parent af30ba4 commit 3cad264

2 files changed

Lines changed: 83 additions & 6 deletions

File tree

tests/bootstrap.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,35 @@ public function setUp()
3535
</movies>
3636
');
3737

38-
$this->simpleXML_NS = simplexml_load_string('<?xml version="1.0" standalone="yes"?>
38+
$this->simpleXML_default_NS = simplexml_load_string('<?xml version="1.0" standalone="yes"?>
39+
<movies xmlns="https://github.com/IMSoP/simplexml_debug">
40+
<movie>
41+
<title>PHP: Behind the Parser</title>
42+
<characters>
43+
<character>
44+
<name>Ms. Coder</name>
45+
<actor>Onlivia Actora</actor>
46+
</character>
47+
<character>
48+
<name>Mr. Coder</name>
49+
<actor>El Act&#211;r</actor>
50+
</character>
51+
</characters>
52+
<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+
</plot>
57+
<great-lines>
58+
<line>PHP solves all my web problems</line>
59+
</great-lines>
60+
<rating type="thumbs">7</rating>
61+
<rating type="stars">5</rating>
62+
</movie>
63+
</movies>
64+
');
65+
66+
$this->simpleXML_named_NS = simplexml_load_string('<?xml version="1.0" standalone="yes"?>
3967
<movies xmlns:test="https://github.com/IMSoP/simplexml_debug">
4068
<test:movie>
4169
<test:title>PHP: Behind the Parser</test:title>

tests/simplexml_dump_Test.php

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,25 @@ public function setUp()
1818
]
1919
";
2020

21-
$this->expected_NS = "SimpleXML object (1 item)
21+
$this->expected_default_NS = "SimpleXML object (1 item)
22+
[
23+
Element {
24+
Namespace: 'https://github.com/IMSoP/simplexml_debug'
25+
(Default Namespace)
26+
Name: 'movies'
27+
String Content: '
28+
29+
'
30+
Content in Default Namespace
31+
Namespace URI: 'https://github.com/IMSoP/simplexml_debug'
32+
Children: 1 - 1 'movie'
33+
Attributes: 0
34+
}
35+
]
36+
";
37+
38+
39+
$this->expected_named_NS = "SimpleXML object (1 item)
2240
[
2341
Element {
2442
Name: 'movies'
@@ -52,13 +70,19 @@ public function testDumpReturn()
5270
$this->assertEquals($this->expected, $return);
5371
}
5472

55-
public function testDumpWithNS()
73+
public function testDumpWithDefaultNS()
74+
{
75+
$return = simplexml_dump($this->simpleXML_default_NS, true);
76+
$this->assertEquals($this->expected_default_NS, $return);
77+
}
78+
79+
public function testDumpWithNamedNS()
5680
{
57-
$return = simplexml_dump($this->simpleXML_NS, true);
58-
$this->assertEquals($this->expected_NS, $return);
81+
$return = simplexml_dump($this->simpleXML_named_NS, true);
82+
$this->assertEquals($this->expected_named_NS, $return);
5983
}
6084

61-
public function testDumpWithSingleNodeWithAttributesAndNS()
85+
public function testDumpAttributeWithNamedNS()
6286
{
6387
$xml = '<parent xmlns:ns="ns"><ns:child ns:foo="bar" /></parent>';
6488
$sxml = simplexml_load_string($xml);
@@ -74,6 +98,31 @@ public function testDumpWithSingleNodeWithAttributesAndNS()
7498
Value: 'bar'
7599
}
76100
]
101+
";
102+
103+
$this->assertEquals($expected, $return);
104+
}
105+
106+
public function testDumpMultipleAttributes()
107+
{
108+
$xml = '<parent xmlns:ns="ns"><child ns:one="1" ns:two="2" ns:three="3" /></parent>';
109+
$sxml = simplexml_load_string($xml);
110+
111+
$return = simplexml_dump($sxml->child, true);
112+
113+
$expected = "SimpleXML object (1 item)
114+
[
115+
Element {
116+
Namespace: 'ns'
117+
Namespace Alias: 'ns'
118+
Name: 'child'
119+
String Content: ''
120+
Content in Namespace ns
121+
Namespace URI: 'ns'
122+
Children: 0
123+
Attributes: 3 - 'one', 'two', 'three'
124+
}
125+
]
77126
";
78127

79128
$this->assertEquals($expected, $return);

0 commit comments

Comments
 (0)