mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-03 10:02:42 +00:00
Changing to Xml::toArray() return @ after attributes to dont conflict with tags with same name.
This commit is contained in:
parent
527446a3d1
commit
9611ab1027
2 changed files with 52 additions and 6 deletions
|
@ -136,7 +136,7 @@ class Xml {
|
|||
|
||||
foreach ($namespaces as $namespace) {
|
||||
foreach ($xml->attributes($namespace, true) as $key => $value) {
|
||||
$data[$key] = (string)$value;
|
||||
$data['@' . $key] = (string)$value;
|
||||
}
|
||||
|
||||
foreach ($xml->children($namespace, true) as $child) {
|
||||
|
|
|
@ -256,6 +256,22 @@ class XmlTest extends CakeTestCase {
|
|||
$xml = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'fixtures' . DS . 'sample.xml';
|
||||
$obj = Xml::build($xml);
|
||||
$expected = array(
|
||||
'tags' => array(
|
||||
'tag' => array(
|
||||
array(
|
||||
'@id' => '1',
|
||||
'name' => 'defect'
|
||||
),
|
||||
array(
|
||||
'@id' => '2',
|
||||
'name' => 'enhancement'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEqual(Xml::toArray($obj), $expected);
|
||||
|
||||
$array = array(
|
||||
'tags' => array(
|
||||
'tag' => array(
|
||||
array(
|
||||
|
@ -269,11 +285,25 @@ class XmlTest extends CakeTestCase {
|
|||
)
|
||||
)
|
||||
);
|
||||
$this->assertEqual(Xml::toArray($obj), $expected);
|
||||
$this->assertEqual(Xml::toArray(Xml::fromArray($expected)), $expected);
|
||||
$this->assertEqual(Xml::toArray(Xml::fromArray($expected, 'tags')), $expected);
|
||||
$this->assertEqual(Xml::toArray(Xml::fromArray($array, 'tags')), $array);
|
||||
|
||||
$expected = array(
|
||||
'tags' => array(
|
||||
'tag' => array(
|
||||
array(
|
||||
'@id' => '1',
|
||||
'@name' => 'defect'
|
||||
),
|
||||
array(
|
||||
'@id' => '2',
|
||||
'@name' => 'enhancement'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEqual(Xml::toArray(Xml::fromArray($array)), $expected);
|
||||
|
||||
$array = array(
|
||||
'tags' => array(
|
||||
'tag' => array(
|
||||
'id' => '1',
|
||||
|
@ -289,7 +319,23 @@ class XmlTest extends CakeTestCase {
|
|||
)
|
||||
)
|
||||
);
|
||||
$this->assertEqual(Xml::toArray(Xml::fromArray($expected)), $expected);
|
||||
$expected = array(
|
||||
'tags' => array(
|
||||
'tag' => array(
|
||||
'@id' => '1',
|
||||
'posts' => array(
|
||||
array('@id' => '1'),
|
||||
array('@id' => '2')
|
||||
)
|
||||
),
|
||||
'tagOther' => array(
|
||||
'subtag' => array(
|
||||
'@id' => '1'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEqual(Xml::toArray(Xml::fromArray($array)), $expected);
|
||||
|
||||
$xml = '<root>';
|
||||
$xml .= '<tag id="1">defect</tag>';
|
||||
|
@ -299,7 +345,7 @@ class XmlTest extends CakeTestCase {
|
|||
$expected = array(
|
||||
'root' => array(
|
||||
'tag' => array(
|
||||
'id' => 1,
|
||||
'@id' => 1,
|
||||
'value' => 'defect'
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue