Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #53, ordering of XML::toArray() operations.

  • Loading branch information...
commit 0dfc07ba0d8c44374f89998eda9c2dd0f995c1db 1 parent 5d3f0d7
@predominant predominant authored
Showing with 39 additions and 1 deletion.
  1. +2 −1  cake/libs/xml.php
  2. +37 −0 cake/tests/cases/libs/xml.test.php
View
3  cake/libs/xml.php
@@ -691,6 +691,7 @@ function toArray($camelize = true) {
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 @@ function toArray($camelize = true) {
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)) {
View
37 cake/tests/cases/libs/xml.test.php
@@ -1266,6 +1266,43 @@ function testToArray() {
)
);
$this->assertEqual($result, $expected);
+
+ $text = '<main><first label="first type node 1" /><first label="first type node 2" /><second label="second type node" /></main>';
+ $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 = '<main><first label="first type node 1" /><first label="first type node 2" /><second label="second type node" /><collection><fifth label="fifth type node"/><third label="third type node 1"/><third label="third type node 2"/><third label="third type node 3"/><fourth label="fourth type node"/></collection></main>';
+ $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);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.