Fixing bug when value is '0', it was generating a blank node.

This commit is contained in:
renan.saddam 2009-09-17 23:08:32 -03:00
parent 20ef932156
commit 317049b736
2 changed files with 17 additions and 4 deletions

View file

@ -227,7 +227,7 @@ class XmlNode extends Object {
$chldObjs = get_object_vars($object); $chldObjs = get_object_vars($object);
} elseif (is_array($object)) { } elseif (is_array($object)) {
$chldObjs = $object; $chldObjs = $object;
} elseif (!empty($object) || $object === 0) { } elseif (!empty($object) || $object === 0 || $object === '0') {
$node->createTextNode($object); $node->createTextNode($object);
} }
$attr = array(); $attr = array();
@ -268,7 +268,7 @@ class XmlNode extends Object {
$node->normalize($val, $n, $options); $node->normalize($val, $n, $options);
} elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) { } elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) {
$tmp =& $node->createElement($key); $tmp =& $node->createElement($key);
if (!empty($val) || $val === 0) { if (!empty($val) || $val === 0 || $val === '0') {
$tmp->createTextNode($val); $tmp->createTextNode($val);
} }
} elseif ($options['format'] == 'attributes') { } elseif ($options['format'] == 'attributes') {

View file

@ -176,6 +176,19 @@ class XmlTest extends CakeTestCase {
$expected = '<hello><![CDATA[world]]></hello>'; $expected = '<hello><![CDATA[world]]></hello>';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
} }
/**
* testSimpleArrayWithZeroValues method
*
* @access public
* @return void
*/
function testSimpleArrayWithZeroValues() {
$xml = new Xml(array('zero_string' => '0', 'zero_integer' => 0), array('format' => 'tags'));
$result = $xml->toString(false);
$expected = '<zero_string>0</zero_string><zero_integer>0</zero_integer>';
$this->assertEqual($expected, $result);
}
/** /**
* testHeader method * testHeader method
* *