Permalink
Browse files

Fixing XmlHelper overwriting its Xml property when creating an open e…

…lement with elem()

Fixes #1642
  • Loading branch information...
1 parent 561b8e2 commit f0b70669448757b8f5615a42ab9930fb9eebbed6 @markstory markstory committed Apr 16, 2011
Showing with 22 additions and 7 deletions.
  1. +9 −5 cake/libs/view/helpers/xml.php
  2. +13 −2 cake/tests/cases/libs/view/helpers/xml.test.php
@@ -39,6 +39,9 @@ class XmlHelper extends AppHelper {
* @var string
*/
var $encoding = 'UTF-8';
+
+ var $Xml;
+ var $XmlElement;
/**
* Constructor
* @return void
@@ -127,7 +130,7 @@ function elem($name, $attrib = array(), $content = null, $endTag = true) {
$out = $elem->toString(array('cdata' => $cdata, 'leaveOpen' => !$endTag));
if (!$endTag) {
- $this->Xml =& $elem;
+ $this->XmlElement =& $elem;
}
return $this->output($out);
}
@@ -137,9 +140,10 @@ function elem($name, $attrib = array(), $content = null, $endTag = true) {
* @return string
*/
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 $this->output('</' . $name . '>');
}
@@ -159,4 +163,4 @@ function serialize($data, $options = array()) {
}
}
-?>
+?>
@@ -154,7 +154,8 @@ function testRenderElementWithNamespace() {
$result .= $this->Xml->closeElem();
$this->assertEqual($result, $expected);
}
- /**
+
+/**
* testRenderElementWithComplexContent method
*
* @access public
@@ -269,5 +270,15 @@ function testHeader() {
$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());
+ }
}
-?>
+?>

0 comments on commit f0b7066

Please sign in to comment.