From fd7cf5e5e601b17bedf7e74b30905cd286fa3671 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 30 Jun 2009 01:14:20 +0000 Subject: [PATCH] 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 --- cake/libs/xml.php | 3 +++ cake/tests/cases/libs/xml.test.php | 32 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 845068514..509d916b0 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -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')) . '"'; } } diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index eec558641..9cbf5e87b 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -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 = ''; + $this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => true))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => null))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => 0))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean-ish values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => 1))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean-ish values incorrectly handled. %s'); + } /** * testSimpleArray method *