Skip to content
Permalink
Browse files

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

  • Loading branch information...
predominant committed Mar 26, 2010
1 parent 9f5949a commit ec3f4b8d34005d533d5d0f6d4003e65971a3e394
Showing with 39 additions and 1 deletion.
  1. +2 −1 cake/libs/xml.php
  2. +37 −0 cake/tests/cases/libs/xml.test.php
@@ -664,6 +664,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;
@@ -688,7 +689,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)) {
@@ -1244,6 +1244,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);
}
/**
* testAppend method

0 comments on commit ec3f4b8

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.