|
1 | 1 | <?php |
2 | 2 |
|
3 | | -class simplexml_dump_Test extends simplexml_dump_bootstrap |
| 3 | +class simplexml_dump_test extends PHPUnit_Framework_TestCase |
4 | 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_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 | | - $this->expected_named_NS = "SimpleXML object (1 item) |
39 | | -[ |
40 | | - Element { |
41 | | - Name: 'movies' |
42 | | - String Content: ' |
43 | | - |
44 | | - ' |
45 | | - Content in Namespace test |
46 | | - Namespace URI: 'https://github.com/IMSoP/simplexml_debug' |
47 | | - Children: 1 - 1 'movie' |
48 | | - Attributes: 0 |
49 | | - } |
50 | | -] |
51 | | -"; |
52 | | - |
53 | | - parent::setUp(); |
54 | | - } |
55 | | - |
56 | | - public function testDump() |
57 | | - { |
58 | | - ob_start(); |
59 | | - simplexml_dump($this->simpleXML); |
60 | | - $return = ob_get_contents(); |
61 | | - ob_end_clean(); |
62 | | - |
63 | | - $this->assertEquals($this->expected, $return); |
64 | | - } |
65 | | - |
66 | | - public function testDumpReturn() |
67 | | - { |
68 | | - $return = simplexml_dump($this->simpleXML, true); |
69 | | - $this->assertEquals($this->expected, $return); |
70 | | - } |
71 | | - |
72 | | - public function testDumpWithDefaultNS() |
73 | | - { |
74 | | - $return = simplexml_dump($this->simpleXML_default_NS, true); |
75 | | - $this->assertEquals($this->expected_default_NS, $return); |
76 | | - } |
77 | | - |
78 | | - public function testDumpWithNamedNS() |
79 | | - { |
80 | | - $return = simplexml_dump($this->simpleXML_named_NS, true); |
81 | | - $this->assertEquals($this->expected_named_NS, $return); |
82 | | - } |
83 | | - |
84 | | - public function testDumpAttributeWithNamedNS() |
85 | | - { |
86 | | - $xml = '<parent xmlns:ns="ns"><ns:child ns:foo="bar" /></parent>'; |
87 | | - $sxml = simplexml_load_string($xml); |
88 | | - |
89 | | - $return = simplexml_dump($sxml->children('ns', true)->child->attributes('ns'), true); |
90 | | - |
91 | | - $expected = "SimpleXML object (1 item) |
92 | | -[ |
93 | | - Attribute { |
94 | | - Namespace: 'ns' |
95 | | - Namespace Alias: 'ns' |
96 | | - Name: 'foo' |
97 | | - Value: 'bar' |
98 | | - } |
99 | | -] |
100 | | -"; |
101 | | - |
102 | | - $this->assertEquals($expected, $return); |
103 | | - } |
104 | | - |
105 | | - public function testDumpMultipleAttributes() |
106 | | - { |
107 | | - $xml = '<parent xmlns:ns="ns"><child ns:one="1" ns:two="2" ns:three="3" /></parent>'; |
108 | | - $sxml = simplexml_load_string($xml); |
109 | | - |
110 | | - $return = simplexml_dump($sxml->child, true); |
111 | | - |
112 | | - $expected = "SimpleXML object (1 item) |
113 | | -[ |
114 | | - Element { |
115 | | - Namespace: 'ns' |
116 | | - Namespace Alias: 'ns' |
117 | | - Name: 'child' |
118 | | - String Content: '' |
119 | | - Content in Namespace ns |
120 | | - Namespace URI: 'ns' |
121 | | - Children: 0 |
122 | | - Attributes: 3 - 'one', 'two', 'three' |
123 | | - } |
124 | | -] |
125 | | -"; |
126 | | - |
127 | | - $this->assertEquals($expected, $return); |
128 | | - } |
| 5 | + public function loadExamples() |
| 6 | + { |
| 7 | + $test_cases = array(); |
| 8 | + |
| 9 | + foreach ( new DirectoryIterator(__DIR__ . '/dump-output') as $fileInfo ) |
| 10 | + { |
| 11 | + if($fileInfo->isDot()) { |
| 12 | + continue; |
| 13 | + } |
| 14 | + |
| 15 | + $filename = $fileInfo->getFilename(); |
| 16 | + |
| 17 | + $test_cases[$filename] = array( |
| 18 | + file_get_contents(__DIR__ . '/input/' . $filename . '.xml'), |
| 19 | + file_get_contents(__DIR__ . '/dump-output/' . $filename) |
| 20 | + ); |
| 21 | + } |
| 22 | + |
| 23 | + return $test_cases; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @dataProvider loadExamples |
| 28 | + */ |
| 29 | + public function testDumpReturn($xml, $expected_output) |
| 30 | + { |
| 31 | + $return = simplexml_dump(simplexml_load_string($xml), true); |
| 32 | + $this->assertSame($expected_output, $return); |
| 33 | + } |
129 | 34 | } |
130 | | - |
131 | | -?> |
0 commit comments