1010 */
1111class XmlConstructTest extends TestCase
1212{
13- protected $ in = [
13+ private $ in1 = [
1414 [
1515 'tag ' => 'root ' ,
1616 'elements ' => [
@@ -37,8 +37,27 @@ class XmlConstructTest extends TestCase
3737 ],
3838 ],
3939 ];
40+ private $ in2 = [
41+ [
42+ 'tag ' => 'root ' ,
43+ 'elements ' => [
44+ [
45+ 'tag ' => 'tag1 ' ,
46+ // 'content' => 'content1', // no content
47+ ],
48+ [
49+ 'tag ' => 'tag2 ' ,
50+ 'content ' => 'content2 ' ,
51+ ],
52+ [
53+ 'tag ' => 'tag3 ' ,
54+ // 'content' => 'content3', // no content
55+ ],
56+ ],
57+ ],
58+ ];
4059
41- public function testDefaultDocument ()
60+ public function testDefaultDocument1 ()
4261 {
4362 $ out1 = <<<XML
4463<?xml version="1.0" encoding="UTF-8"?>
@@ -51,10 +70,25 @@ public function testDefaultDocument()
5170</root>
5271XML ;
5372 $ xml = new XmlConstructor ;
54- $ out2 = $ xml ->fromArray ($ this ->in )->toOutput ();
73+ $ out2 = $ xml ->fromArray ($ this ->in1 )->toOutput ();
5574 $ this ->assertEquals ($ this ->prepare ($ out1 ), $ this ->prepare ($ out2 ));
5675 }
57-
76+
77+ public function testDefaultDocument2 ()
78+ {
79+ $ out1 = <<<XML
80+ <?xml version="1.0" encoding="UTF-8"?>
81+ <root>
82+ <tag1/>
83+ <tag2>content2</tag2>
84+ <tag3/>
85+ </root>
86+ XML ;
87+ $ xml = new XmlConstructor ;
88+ $ out2 = $ xml ->fromArray ($ this ->in2 )->toOutput ();
89+ $ this ->assertEquals ($ this ->prepare ($ out1 ), $ this ->prepare ($ out2 ));
90+ }
91+
5892 public function testWithoutStartDocument ()
5993 {
6094 $ out1 = <<<XML
@@ -67,7 +101,7 @@ public function testWithoutStartDocument()
67101</root>
68102XML ;
69103 $ xml = new XmlConstructor (['startDocument ' => false ]);
70- $ out2 = $ xml ->fromArray ($ this ->in )->toOutput ();
104+ $ out2 = $ xml ->fromArray ($ this ->in1 )->toOutput ();
71105 $ this ->assertEquals ($ this ->prepare ($ out1 ), $ this ->prepare ($ out2 ));
72106 }
73107
@@ -84,7 +118,7 @@ public function testCustomIndentString()
84118</root>
85119XML ;
86120 $ xml = new XmlConstructor (['indentString ' => false ]);
87- $ out2 = $ xml ->fromArray ($ this ->in )->toOutput ();
121+ $ out2 = $ xml ->fromArray ($ this ->in1 )->toOutput ();
88122 $ this ->assertEquals ($ this ->prepare ($ out1 ), $ this ->prepare ($ out2 ));
89123 }
90124
@@ -97,8 +131,12 @@ public function testError()
97131 $ out2 = $ xml ->fromArray (['incorrect ' => 'array ' ])->toOutput ();
98132 $ this ->assertEquals ($ this ->prepare ($ out1 ), $ this ->prepare ($ out2 ));
99133 }
100-
101- protected function prepare ($ xml )
134+
135+ /**
136+ * @param string $xml
137+ * @return string
138+ */
139+ private function prepare ($ xml )
102140 {
103141 return preg_replace ('/\s/ ' , '' , $ xml );
104142 }
0 commit comments