Fixing XmlHelper::elem() when rendering non-empty content values, fixes #4300

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6520 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-03-08 18:39:00 +00:00
parent 82f4427b8b
commit c096e20350
2 changed files with 8 additions and 3 deletions

View file

@ -126,15 +126,15 @@ class XmlHelper extends AppHelper {
* @return string XML
*/
function elem($name, $attrib = array(), $content = null, $endTag = true) {
$ns = null;
if (isset($attrib['namespace'])) {
$ns = $attrib['namespace'] . ':';
unset($attrib['namespace']);
}
$out = "<{$ns}{$name}" . $this->__composeAttributes($attrib);
if (empty($content) && $endTag) {
if ((empty($content) && $content !== 0) && $endTag) {
$out .= ' />';
} else {
$out .= '>' . $this->__composeContent($content);
@ -142,7 +142,6 @@ class XmlHelper extends AppHelper {
$out .= "</{$name}>";
}
}
return $this->output($out);
}
/**

View file

@ -65,6 +65,12 @@ class XmlHelperTest extends UnitTestCase {
$this->assertEqual($manager->namespaces, $expected);
}
function testRenderZeroElement() {
$result = $this->Xml->elem('count', null, 0);
$expected = '<count>0</count>';
$this->assertEqual($result, $expected);
}
function tearDown() {
unset($this->Xml);
}