Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding test cases for boolean and boolean-ish values. Fixes false bei…

…ng 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
  • Loading branch information...
commit fd7cf5e5e601b17bedf7e74b30905cd286fa3671 1 parent 8c7883f
@markstory markstory authored
Showing with 35 additions and 0 deletions.
  1. +3 −0  cake/libs/xml.php
  2. +32 −0 cake/tests/cases/libs/xml.test.php
View
3  cake/libs/xml.php
@@ -607,6 +607,9 @@ function toString($options = array(), $depth = 0) {
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
32 cake/tests/cases/libs/xml.test.php
@@ -97,6 +97,38 @@ function testSerialization() {
$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
*

0 comments on commit fd7cf5e

Please sign in to comment.
Something went wrong with that request. Please try again.