@@ -111,6 +111,18 @@ public function testEncodeSimpleXML()
111
111
112
112
$ this ->assertEquals ($ expected , $ this ->encoder ->encode ($ array , 'xml ' ));
113
113
}
114
+
115
+ public function testEncodeScalarWithAttribute ()
116
+ {
117
+ $ array = array (
118
+ 'person ' => array ('@gender ' => 'M ' , '# ' => 'Peter ' ),
119
+ );
120
+
121
+ $ expected = '<?xml version="1.0"?> ' ."\n" .
122
+ '<response><person gender="M"><![CDATA[Peter]]></person></response> ' ."\n" ;
123
+
124
+ $ this ->assertEquals ($ expected , $ this ->encoder ->encode ($ array , 'xml ' ));
125
+ }
114
126
115
127
public function testDecodeScalar ()
116
128
{
@@ -135,6 +147,38 @@ public function testDecode()
135
147
136
148
$ this ->assertEquals (get_object_vars ($ obj ), $ this ->encoder ->decode ($ source , 'xml ' ));
137
149
}
150
+
151
+ public function testDecodeScalarWithAttribute ()
152
+ {
153
+ $ source = '<?xml version="1.0"?> ' ."\n" .
154
+ '<response><person gender="M">Peter</person></response> ' ."\n" ;
155
+
156
+ $ expected = array (
157
+ 'person ' => array ('@gender ' => 'M ' , '# ' => 'Peter ' ),
158
+ );
159
+
160
+ $ this ->assertEquals ($ expected , $ this ->encoder ->decode ($ source , 'xml ' ));
161
+ }
162
+
163
+ public function testDecodeArray ()
164
+ {
165
+ $ source = '<?xml version="1.0"?> ' ."\n" .
166
+ '<response> ' .
167
+ '<people> ' .
168
+ '<person><firstname>Benjamin</firstname><lastname>Alexandre</lastname></person> ' .
169
+ '<person><firstname>Damien</firstname><lastname>Clay</lastname></person> ' .
170
+ '</people> ' .
171
+ '</response> ' ."\n" ;
172
+
173
+ $ expected = array (
174
+ 'people ' => array ('person ' => array (
175
+ array ('firstname ' => 'Benjamin ' , 'lastname ' => 'Alexandre ' ),
176
+ array ('firstname ' => 'Damien ' , 'lastname ' => 'Clay ' )
177
+ ))
178
+ );
179
+
180
+ $ this ->assertEquals ($ expected , $ this ->encoder ->decode ($ source , 'xml ' ));
181
+ }
138
182
139
183
protected function getXmlSource ()
140
184
{
@@ -153,7 +197,7 @@ protected function getObject()
153
197
$ obj = new Dummy ;
154
198
$ obj ->foo = 'foo ' ;
155
199
$ obj ->bar = array ('a ' , 'b ' );
156
- $ obj ->baz = array ('key ' => 'val ' , 'key2 ' => 'val ' , 'A B ' => 'bar ' , "Barry " => array ('FooBar ' => array ("@id " =>1 , " Baz " =>" Ed " )));
200
+ $ obj ->baz = array ('key ' => 'val ' , 'key2 ' => 'val ' , 'A B ' => 'bar ' , "Barry " => array ('FooBar ' => array ("Baz " =>" Ed " , " @id " =>1 )));
157
201
$ obj ->qux = "1 " ;
158
202
return $ obj ;
159
203
}
0 commit comments