mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
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:
parent
8c7883fe3e
commit
fd7cf5e5e6
2 changed files with 35 additions and 0 deletions
|
@ -607,6 +607,9 @@ class XmlNode extends Object {
|
||||||
|
|
||||||
if (is_array($this->attributes) && count($this->attributes) > 0) {
|
if (is_array($this->attributes) && count($this->attributes) > 0) {
|
||||||
foreach ($this->attributes as $key => $val) {
|
foreach ($this->attributes as $key => $val) {
|
||||||
|
if (is_bool($val) && $val === false) {
|
||||||
|
$val = 0;
|
||||||
|
}
|
||||||
$d .= ' ' . $key . '="' . htmlspecialchars($val, ENT_QUOTES, Configure::read('App.encoding')) . '"';
|
$d .= ' ' . $key . '="' . htmlspecialchars($val, ENT_QUOTES, Configure::read('App.encoding')) . '"';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,38 @@ class XmlTest extends CakeTestCase {
|
||||||
$result = preg_replace("/\n/",'', $xml->toString(false));
|
$result = preg_replace("/\n/",'', $xml->toString(false));
|
||||||
$this->assertEqual($result, $expected);
|
$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
|
* testSimpleArray method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue