Skip to content

Commit

Permalink
Fixing _name_ elements being inserted into serialized xml from Xml li…
Browse files Browse the repository at this point in the history
…b. Test case added. Fixes #367
  • Loading branch information
markstory committed Nov 27, 2009
1 parent ad20e43 commit 26aa373
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cake/libs/xml.php
Expand Up @@ -241,7 +241,7 @@ function normalize($object, $keyName = null, $options = array()) {
}

$n = $name;
if (!empty($chldObjs['_name_'])) {
if (isset($chldObjs['_name_'])) {
$n = null;
unset($chldObjs['_name_']);
}
Expand Down
29 changes: 23 additions & 6 deletions cake/tests/cases/libs/xml.test.php
Expand Up @@ -114,7 +114,6 @@ function testSerializeOnMultiDimensionalArray() {
$result =& new Xml($data, array('format' => 'tags'));
$expected = '<statuses><status><id>1</id></status><status><id>2</id></status></statuses>';
$this->assertIdentical($result->toString(), $expected);

}

/**
Expand Down Expand Up @@ -258,7 +257,7 @@ function testArraySingleSerialization() {
* @access public
* @return void
*/
function testArraySerialization() {
function testSerializationArray() {
$input = array(
array(
'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
Expand All @@ -285,7 +284,7 @@ function testArraySerialization() {
* @access public
* @return void
*/
function testNestedArraySerialization() {
function testSerializationNestedArray() {
$input = array(
array(
'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
Expand Down Expand Up @@ -330,9 +329,9 @@ function testNestedArraySerialization() {
*/
function testArraySerializationWithRoot() {
$input = array(
array('Shirt' => array('id' => 1, 'color' => 'green')),
array('Shirt' => array('id' => 2, 'color' => 'blue')),
);
array('Shirt' => array('id' => 1, 'color' => 'green')),
array('Shirt' => array('id' => 2, 'color' => 'blue')),
);
$expected = '<collection><shirt id="1" color="green" />';
$expected .= '<shirt id="2" color="blue" /></collection>';

Expand Down Expand Up @@ -699,6 +698,24 @@ function testSetSerialization() {
$result = $xml->toString(array('header' => false, 'cdata' => false));
$this->assertEqual($expected, $result);
}
/**
* ensure that normalize does not add _name_ elements that come from Set::map sometimes.
*
* @return void
*/
function testNormalizeNotAdding_name_Element() {
$input = array(
'output' => array(
'Vouchers' => array(
array('Voucher' => array('id' => 1)),
array('Voucher' => array('id' => 2)),
),
)
);
$xml = new Xml($input, array('attributes' => false, 'format' => 'tags'));
$this->assertFalse(isset($xml->children[0]->children[0]->children[1]), 'Too many children %s');
$this->assertEqual($xml->children[0]->children[0]->children[0]->name, 'voucher');
}
/**
* testSimpleParsing method
*
Expand Down

0 comments on commit 26aa373

Please sign in to comment.