Skip to content
This repository
Browse code

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

…lement with elem()

Fixes #1642
  • Loading branch information...
commit 12c245609ead0a4c8b839d9e0db06a56d949a6d5 1 parent 4395e8a
Mark Story authored
11  cake/libs/view/helpers/xml.php
@@ -38,6 +38,8 @@ class XmlHelper extends AppHelper {
38 38
  */
39 39
 	var $encoding = 'UTF-8';
40 40
 
  41
+	var $Xml;
  42
+	var $XmlElement;
41 43
 /**
42 44
  * Constructor
43 45
  *
@@ -136,7 +138,7 @@ function elem($name, $attrib = array(), $content = null, $endTag = true) {
136 138
 		$out = $elem->toString(array('cdata' => $cdata, 'leaveOpen' => !$endTag));
137 139
 
138 140
 		if (!$endTag) {
139  
-			$this->Xml =& $elem;
  141
+			$this->XmlElement =& $elem;
140 142
 		}
141 143
 		return $out;
142 144
 	}
@@ -148,9 +150,10 @@ function elem($name, $attrib = array(), $content = null, $endTag = true) {
148 150
  * @access public
149 151
  */
150 152
 	function closeElem() {
151  
-		$name = $this->Xml->name();
152  
-		if ($parent =& $this->Xml->parent()) {
153  
-			$this->Xml =& $parent;
  153
+		$elem = (empty($this->XmlElement)) ? $this->Xml : $this->XmlElement;
  154
+		$name = $elem->name();
  155
+		if ($parent =& $elem->parent()) {
  156
+			$this->XmlElement =& $parent;
154 157
 		}
155 158
 		return '</' . $name . '>';
156 159
 	}
13  cake/tests/cases/libs/view/helpers/xml.test.php
@@ -159,7 +159,8 @@ function testRenderElementWithNamespace() {
159 159
 		$result .= $this->Xml->closeElem();
160 160
 		$this->assertEqual($result, $expected);
161 161
 	}
162  
-	/**
  162
+
  163
+/**
163 164
  * testRenderElementWithComplexContent method
164 165
  *
165 166
  * @access public
@@ -284,4 +285,14 @@ function testHeader() {
284 285
 		$expected = '<?xml encoding="UTF-8" someOther="value" ?>';
285 286
 		$this->assertIdentical($result, $expected);
286 287
 	}
  288
+
  289
+/**
  290
+ * test that calling elem() and then header() doesn't break
  291
+ *
  292
+ * @return void
  293
+ */
  294
+	function testElemThenHeader() {
  295
+		$this->Xml->elem('test', array(), 'foo', false);
  296
+		$this->assertPattern('/<\?xml/', $this->Xml->header());
  297
+	}
287 298
 }

0 notes on commit 12c2456

Please sign in to comment.
Something went wrong with that request. Please try again.