Permalink
Browse files

Fixing _name_ elements being inserted into serialized xml from Xml li…

…b. Test case added. Fixes #367
  • Loading branch information...
1 parent ad20e43 commit 26aa3731e033e9a3c22e0d558f77d75ebfc1e23c @markstory markstory committed Nov 27, 2009
Showing with 24 additions and 7 deletions.
  1. +1 −1 cake/libs/xml.php
  2. +23 −6 cake/tests/cases/libs/xml.test.php
View
2 cake/libs/xml.php
@@ -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_']);
}
View
29 cake/tests/cases/libs/xml.test.php
@@ -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);
-
}
/**
@@ -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),
@@ -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),
@@ -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>';
@@ -700,6 +699,24 @@ function testSetSerialization() {
$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
*
* @access public

0 comments on commit 26aa373

Please sign in to comment.