@@ -203,6 +203,14 @@ public function testEncode()
203
203
$ this ->assertEquals ($ source , $ this ->encoder ->encode ($ obj , 'xml ' ));
204
204
}
205
205
206
+ public function testEncodeWithNamespace ()
207
+ {
208
+ $ source = $ this ->getNamespacedXmlSource ();
209
+ $ array = $ this ->getNamespacedArray ();
210
+
211
+ $ this ->assertEquals ($ source , $ this ->encoder ->encode ($ array , 'xml ' ));
212
+ }
213
+
206
214
public function testEncodeSerializerXmlRootNodeNameOption ()
207
215
{
208
216
$ options = array ('xml_root_node_name ' => 'test ' );
@@ -253,6 +261,14 @@ public function testDecodeCdataWrappingAndWhitespace()
253
261
$ this ->assertEquals ($ expected , $ this ->encoder ->decode ($ xml , 'xml ' ));
254
262
}
255
263
264
+ public function testDecodeWithNamespace ()
265
+ {
266
+ $ source = $ this ->getNamespacedXmlSource ();
267
+ $ array = $ this ->getNamespacedArray ();
268
+
269
+ $ this ->assertEquals ($ array , $ this ->encoder ->decode ($ source , 'xml ' ));
270
+ }
271
+
256
272
public function testDecodeScalarWithAttribute ()
257
273
{
258
274
$ source = '<?xml version="1.0"?> ' ."\n" .
@@ -414,6 +430,53 @@ protected function getXmlSource()
414
430
'</response> ' ."\n" ;
415
431
}
416
432
433
+ protected function getNamespacedXmlSource ()
434
+ {
435
+ return '<?xml version="1.0"?> ' ."\n" .
436
+ '<response xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:media="http://search.yahoo.com/mrss/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:yt="http://gdata.youtube.com/schemas/2007"> ' .
437
+ '<qux>1</qux> ' .
438
+ '<app:foo>foo</app:foo> ' .
439
+ '<yt:bar>a</yt:bar><yt:bar>b</yt:bar> ' .
440
+ '<media:baz><media:key>val</media:key><media:key2>val</media:key2><item key="A B">bar</item> ' .
441
+ '<item><title>title1</title></item><item><title>title2</title></item> ' .
442
+ '<Barry size="large"><FooBar gd:id="1"><Baz>Ed</Baz></FooBar></Barry></media:baz> ' .
443
+ '</response> ' ."\n" ;
444
+ }
445
+
446
+ protected function getNamespacedArray ()
447
+ {
448
+ return array (
449
+ '@xmlns ' => 'http://www.w3.org/2005/Atom ' ,
450
+ '@xmlns:app ' => 'http://www.w3.org/2007/app ' ,
451
+ '@xmlns:media ' => 'http://search.yahoo.com/mrss/ ' ,
452
+ '@xmlns:gd ' => 'http://schemas.google.com/g/2005 ' ,
453
+ '@xmlns:yt ' => 'http://gdata.youtube.com/schemas/2007 ' ,
454
+ 'qux ' => "1 " ,
455
+ 'app:foo ' => "foo " ,
456
+ 'yt:bar ' => array ("a " , "b " ),
457
+ 'media:baz ' => array (
458
+ 'media:key ' => "val " ,
459
+ 'media:key2 ' => "val " ,
460
+ 'A B ' => "bar " ,
461
+ 'item ' => array (
462
+ array (
463
+ 'title ' => 'title1 ' ,
464
+ ),
465
+ array (
466
+ 'title ' => 'title2 ' ,
467
+ )
468
+ ),
469
+ 'Barry ' => array (
470
+ '@size ' => 'large ' ,
471
+ 'FooBar ' => array (
472
+ 'Baz ' => 'Ed ' ,
473
+ '@gd:id ' => 1 ,
474
+ ),
475
+ ),
476
+ ),
477
+ );
478
+ }
479
+
417
480
protected function getObject ()
418
481
{
419
482
$ obj = new Dummy ();
0 commit comments