From 0dfc07ba0d8c44374f89998eda9c2dd0f995c1db Mon Sep 17 00:00:00 2001 From: predominant Date: Fri, 26 Mar 2010 19:59:09 +1100 Subject: [PATCH] Fixes #53, ordering of XML::toArray() operations. --- cake/libs/xml.php | 3 ++- cake/tests/cases/libs/xml.test.php | 37 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 3447141a5..5c8cb40c3 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -691,6 +691,7 @@ class XmlNode extends Object { foreach ($this->children as $child) { $key = $camelize ? Inflector::camelize($child->name) : $child->name; + //debug($key); if (is_a($child, 'XmlTextNode')) { $out['value'] = $child->value; @@ -715,7 +716,7 @@ class XmlNode extends Object { if (isset($out[$key]) || isset($multi[$key])) { if (!isset($multi[$key])) { $multi[$key] = array($out[$key]); - unset($out[$key]); + //unset($out[$key]); } $multi[$key][] = $value; } elseif (!empty($value)) { diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index 435d5b341..aa237fb07 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -1266,6 +1266,43 @@ class XmlTest extends CakeTestCase { ) ); $this->assertEqual($result, $expected); + + $text = '
'; + $xml = new Xml($text); + $result = $xml->toArray(); + $expected = array( + 'Main' => array( + 'First' => array( + array('label' => 'first type node 1'), + array('label' => 'first type node 2') + ), + 'Second' => array('label'=>'second type node') + ) + ); + $this->assertIdentical($result,$expected); + + $text = '
'; + $xml = new Xml($text); + $result = $xml->toArray(); + $expected = array( + 'Main' => array( + 'First' => array( + array('label' => 'first type node 1'), + array('label' => 'first type node 2') + ), + 'Second' => array('label'=>'second type node'), + 'Collection' => array( + 'Fifth' => array('label' => 'fifth type node'), + 'Third' => array( + array('label' => 'third type node 1'), + array('label' => 'third type node 2'), + array('label' => 'third type node 3'), + ), + 'Fourth' => array('label' => 'fourth type node'), + ) + ) + ); + $this->assertIdentical($result,$expected); } /**