Fixed xml encoder test script, and group item tags into an array

This commit is contained in:
excelwebzone 2011-11-24 09:09:38 -08:00
parent a0561e5dde
commit c9a2b49eb7
2 changed files with 5 additions and 7 deletions

View File

@ -188,14 +188,11 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
$value = (string) $subnode;
}
if ($key === '*item') {
if ($key === 'item') {
if (isset($value['@key'])) {
$data[(string) $value['@key']] = $value['#'];
} elseif (isset($data['*item'])) {
$tmp = $data['*item'];
unset($data['*item']);
$data[] = $tmp;
$data[] = $value;
} else {
$data['item'][] = $value;
}
} elseif (array_key_exists($key, $data)) {
if ((false === is_array($data[$key])) || (false === isset($data[$key][0]))) {

View File

@ -239,6 +239,7 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase
'<foo><![CDATA[foo]]></foo>'.
'<bar><![CDATA[a]]></bar><bar><![CDATA[b]]></bar>'.
'<baz><key><![CDATA[val]]></key><key2><![CDATA[val]]></key2><item key="A B"><![CDATA[bar]]></item>'.
'<item><title><![CDATA[title1]]></title></item><item><title><![CDATA[title2]]></title></item>'.
'<Barry><FooBar id="1"><Baz><![CDATA[Ed]]></Baz></FooBar></Barry></baz>'.
'<qux>1</qux>'.
'</response>'."\n";
@ -249,7 +250,7 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase
$obj = new Dummy;
$obj->foo = 'foo';
$obj->bar = array('a', 'b');
$obj->baz = array('key' => 'val', 'key2' => 'val', 'A B' => 'bar', "Barry" => array('FooBar' => array("Baz"=>"Ed", "@id"=>1)));
$obj->baz = array('key' => 'val', 'key2' => 'val', 'A B' => 'bar', 'item' => array(array('title' => 'title1'), array('title' => 'title2')), 'Barry' => array('FooBar' => array('Baz' => 'Ed', '@id' => 1)));
$obj->qux = "1";
return $obj;