mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixes #53, ordering of XML::toArray() operations.
This commit is contained in:
parent
5d3f0d7fe0
commit
0dfc07ba0d
2 changed files with 39 additions and 1 deletions
|
@ -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)) {
|
||||
|
|
|
@ -1266,6 +1266,43 @@ class XmlTest extends CakeTestCase {
|
|||
)
|
||||
);
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue