-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path19EqualXMLStructure.php
84 lines (72 loc) · 2.33 KB
/
19EqualXMLStructure.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* assertEqualXMLStructure(
* DOMElement $expectedElement,
* DOMElement $actualElement[,
* boolean $checkAttributes = FALSE,
* string $message = '']
* )
*
* Reports an error identified by $message if the XML Structure of the DOMElement
* in $actualElement is not equal to the XML structure of the DOMElement
* in $expectedElement.
*/
class EqualXMLStructureTest extends PHPUnit_Framework_TestCase
{
/**
* This function is pretty straight forward and it checks the
* two simplest xml structures.
*/
public function testFailureWithDifferentNodeNames()
{
$expected = new DOMElement('foo');
$actual = new DOMElement('bar');
#$actual = new DOMElement('bar');
#Uncommenting above line will pass this test
$this->assertEqualXMLStructure($expected, $actual);
}
/**
* This function is to test same element but with different
* attributes. Third parameter in the function assertEqualXMLStructure
* is just used to test that.
*/
public function testFailureWithDifferentNodeAttributes()
{
$expected = new DOMDocument;
$expected->loadXML('<foo bar="true" />');
$actual = new DOMDocument;
$actual->loadXML('<foo/>');
$this->assertEqualXMLStructure(
$expected->firstChild, $actual->firstChild, TRUE
);
}
/**
* This function is to test the same node in the xml
* but with different count of child nodes.
*/
public function testFailureWithDifferentChildrenCount()
{
$expected = new DOMDocument;
$expected->loadXML('<foo><bar/><bar/><bar/></foo>');
$actual = new DOMDocument;
$actual->loadXML('<foo><bar/></foo>');
$this->assertEqualXMLStructure(
$expected->firstChild, $actual->firstChild
);
}
/**
* This function is used to test the same xml node
* but different child nodes
*/
public function testFailureWithDifferentChildren()
{
$expected = new DOMDocument;
$expected->loadXML('<foo><bar/><bar/><bar/></foo>');
$actual = new DOMDocument;
$actual->loadXML('<foo><baz/><baz/><baz/></foo>');
$this->assertEqualXMLStructure(
$expected->firstChild, $actual->firstChild
);
}
}
?>