Adding test cases for boolean and boolean-ish values. Fixes false being converted to '' when using Xml::toString().

Fixes #6478

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8206 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2009-06-30 01:14:20 +00:00
parent 8c7883fe3e
commit fd7cf5e5e6
2 changed files with 35 additions and 0 deletions

View file

@ -607,6 +607,9 @@ class XmlNode extends Object {
if (is_array($this->attributes) && count($this->attributes) > 0) {
foreach ($this->attributes as $key => $val) {
if (is_bool($val) && $val === false) {
$val = 0;
}
$d .= ' ' . $key . '="' . htmlspecialchars($val, ENT_QUOTES, Configure::read('App.encoding')) . '"';
}
}

View file

@ -97,6 +97,38 @@ class XmlTest extends CakeTestCase {
$result = preg_replace("/\n/",'', $xml->toString(false));
$this->assertEqual($result, $expected);
}
/**
* test serialization of boolean and null values. false = 0, true = 1, null = ''
*
* @return void
**/
function testSerializationOfBooleanAndBooleanishValues() {
$xml =& new Xml(array('data' => array('example' => false)));
$result = $xml->toString(false);
$expected = '<data example="0" />';
$this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s');
$xml =& new Xml(array('data' => array('example' => true)));
$result = $xml->toString(false);
$expected = '<data example="1" />';
$this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s');
$xml =& new Xml(array('data' => array('example' => null)));
$result = $xml->toString(false);
$expected = '<data example="" />';
$this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s');
$xml =& new Xml(array('data' => array('example' => 0)));
$result = $xml->toString(false);
$expected = '<data example="0" />';
$this->assertEqual($result, $expected, 'Boolean-ish values incorrectly handled. %s');
$xml =& new Xml(array('data' => array('example' => 1)));
$result = $xml->toString(false);
$expected = '<data example="1" />';
$this->assertEqual($result, $expected, 'Boolean-ish values incorrectly handled. %s');
}
/**
* testSimpleArray method
*