Permalink
Browse files

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

…lement with elem()

Fixes #1642
  • Loading branch information...
1 parent 4395e8a commit 12c245609ead0a4c8b839d9e0db06a56d949a6d5 @markstory markstory committed Apr 16, 2011
Showing with 19 additions and 5 deletions.
  1. +7 −4 cake/libs/view/helpers/xml.php
  2. +12 −1 cake/tests/cases/libs/view/helpers/xml.test.php
@@ -38,6 +38,8 @@ class XmlHelper extends AppHelper {
*/
var $encoding = 'UTF-8';
+ var $Xml;
+ var $XmlElement;
/**
* Constructor
*
@@ -136,7 +138,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 $out;
}
@@ -148,9 +150,10 @@ function elem($name, $attrib = array(), $content = null, $endTag = true) {
* @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 . '>';
}
@@ -159,7 +159,8 @@ function testRenderElementWithNamespace() {
$result .= $this->Xml->closeElem();
$this->assertEqual($result, $expected);
}
- /**
+
+/**
* testRenderElementWithComplexContent method
*
* @access public
@@ -284,4 +285,14 @@ 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 12c2456

Please sign in to comment.