Fixing XmlHelper overwriting its Xml property when creating an open element with elem()

Fixes #1642
This commit is contained in:
mark_story 2011-04-16 16:56:32 -04:00
parent 4395e8acc1
commit 12c245609e
2 changed files with 19 additions and 5 deletions

View file

@ -38,6 +38,8 @@ class XmlHelper extends AppHelper {
*/
var $encoding = 'UTF-8';
var $Xml;
var $XmlElement;
/**
* Constructor
*
@ -136,7 +138,7 @@ class XmlHelper extends AppHelper {
$out = $elem->toString(array('cdata' => $cdata, 'leaveOpen' => !$endTag));
if (!$endTag) {
$this->Xml =& $elem;
$this->XmlElement =& $elem;
}
return $out;
}
@ -148,9 +150,10 @@ class XmlHelper extends AppHelper {
* @access public
*/
function closeElem() {
$name = $this->Xml->name();
if ($parent =& $this->Xml->parent()) {
$this->Xml =& $parent;
$elem = (empty($this->XmlElement)) ? $this->Xml : $this->XmlElement;
$name = $elem->name();
if ($parent =& $elem->parent()) {
$this->XmlElement =& $parent;
}
return '</' . $name . '>';
}

View file

@ -159,7 +159,8 @@ class XmlHelperTest extends CakeTestCase {
$result .= $this->Xml->closeElem();
$this->assertEqual($result, $expected);
}
/**
/**
* testRenderElementWithComplexContent method
*
* @access public
@ -284,4 +285,14 @@ class XmlHelperTest extends CakeTestCase {
$expected = '<?xml encoding="UTF-8" someOther="value" ?>';
$this->assertIdentical($result, $expected);
}
/**
* test that calling elem() and then header() doesn't break
*
* @return void
*/
function testElemThenHeader() {
$this->Xml->elem('test', array(), 'foo', false);
$this->assertPattern('/<\?xml/', $this->Xml->header());
}
}