From 42fac9ec71eaa48b4f8fc2f1fff93227fac4e580 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Tue, 22 Sep 2009 17:47:11 -0300 Subject: [PATCH] Fixing Xml::toArray() when blank nodes are provided. Fixes #87. --- cake/libs/xml.php | 7 +++---- cake/tests/cases/libs/xml.test.php | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 830701e2670..d9d804e40d3 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -704,7 +704,6 @@ function toArray($camelize = true) { continue; } elseif (isset($child->children[0]) && is_a($child->children[0], 'XmlTextNode')) { $value = $child->children[0]->value; - if ($child->attributes) { $value = array_merge(array('value' => $value), $child->attributes); } @@ -720,10 +719,10 @@ function toArray($camelize = true) { continue; } elseif (count($child->children) === 0 && $child->value == '') { $value = $child->attributes; - if (isset($out[$child->name]) || isset($multi[$key])) { + if (isset($out[$key]) || isset($multi[$key])) { if (!isset($multi[$key])) { - $multi[$key] = array($out[$child->name]); - unset($out[$child->name]); + $multi[$key] = array($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 5d5a01358c8..9082b86381e 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -784,7 +784,7 @@ function testElementCollapsing() { /** * test that empty values do not casefold collapse - * + * * @see http://code.cakephp.org/tickets/view/8 * @return void **/ @@ -820,7 +820,7 @@ function testCaseFoldingWithEmptyValues() { varchar(45) '; - + $xml =& new XML($emptyValue); $expected = array( 'Method' => array( @@ -1204,7 +1204,29 @@ function testToArray() { ) ) )); + $this->assertEqual($result, $expected); + $text = ' + + + + + + + '; + $xml = new Xml($text); + $result = $xml->toArray(); + $expected = array( + 'Root' => array( + 'Child' => array( + array('id' => 1, 'other' => 1), + array('id' => 2, 'other' => 1), + array('id' => 3, 'other' => 1), + array('id' => 4, 'other' => 1), + array('id' => 5, 'other' => 1) + ) + ) + ); $this->assertEqual($result, $expected); }