Skip to content
This repository
Browse code

Adding tests for calling RequestHandlerComponent::renderAs() twice.

Fixing issue where viewPath was not updated.
Fixes #6466

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8230 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 02ed77ab202b2f71a3f19395c034d4287fff25a4 1 parent f712d84
Mark Story authored July 14, 2009
2  cake/libs/controller/components/request_handler.php
@@ -585,7 +585,7 @@ function renderAs(&$controller, $type) {
585 585
 		if (empty($this->__renderType)) {
586 586
 			$controller->viewPath .= '/' . $type;
587 587
 		} else {
588  
-			$remove = preg_replace("/(?:\/{$type})$/", '/' . $type, $controller->viewPath);
  588
+			$remove = preg_replace("/(?:\/{$this->__renderType})$/", '/' . $type, $controller->viewPath);
589 589
 			$controller->viewPath = $remove;
590 590
 		}
591 591
 		$this->__renderType = $type;
55  cake/tests/cases/libs/controller/components/request_handler.test.php
@@ -36,6 +36,13 @@
36 36
  */
37 37
 class RequestHandlerTestController extends Controller {
38 38
 /**
  39
+ * name property
  40
+ *
  41
+ * @var string
  42
+ * @access public
  43
+ **/
  44
+	var $name = 'RequestHandlerTest';
  45
+/**
39 46
  * uses property
40 47
  *
41 48
  * @var mixed null
@@ -124,21 +131,32 @@ class RequestHandlerComponentTest extends CakeTestCase {
124 131
  */
125 132
 	var $RequestHandler;
126 133
 /**
127  
- * setUp method
  134
+ * startTest method
128 135
  *
129 136
  * @access public
130 137
  * @return void
131 138
  */
132  
-	function setUp() {
  139
+	function startTest() {
133 140
 		$this->_init();
134 141
 	}
135 142
 /**
136  
- * tearDown method
  143
+ * init method
  144
+ *
  145
+ * @access protected
  146
+ * @return void
  147
+ */
  148
+	function _init() {
  149
+		$this->Controller = new RequestHandlerTestController(array('components' => array('RequestHandler')));
  150
+		$this->Controller->constructClasses();
  151
+		$this->RequestHandler =& $this->Controller->RequestHandler;
  152
+	}
  153
+/**
  154
+ * endTest method
137 155
  *
138 156
  * @access public
139 157
  * @return void
140 158
  */
141  
-	function tearDown() {
  159
+	function endTest() {
142 160
 		unset($this->RequestHandler);
143 161
 		unset($this->Controller);
144 162
 		if (!headers_sent()) {
@@ -242,6 +260,24 @@ function testRenderAs() {
242 260
 		$this->assertTrue(in_array('Xml', $this->Controller->helpers));
243 261
 	}
244 262
 /**
  263
+ * test that calling renderAs() more than once continues to work.
  264
+ *
  265
+ * @link #6466
  266
+ * @return void
  267
+ **/
  268
+	function testRenderAsCalledTwice() {
  269
+		$this->RequestHandler->renderAs($this->Controller, 'xml');
  270
+		$this->assertEqual($this->Controller->viewPath, 'request_handler_test/xml');
  271
+		$this->assertEqual($this->Controller->layoutPath, 'xml');
  272
+		
  273
+		$this->assertTrue(in_array('Xml', $this->Controller->helpers));
  274
+
  275
+		$this->RequestHandler->renderAs($this->Controller, 'js');
  276
+		$this->assertEqual($this->Controller->viewPath, 'request_handler_test/js');
  277
+		$this->assertEqual($this->Controller->layoutPath, 'js');
  278
+		$this->assertTrue(in_array('Js', $this->Controller->helpers));
  279
+	}
  280
+/**
245 281
  * testRequestClientTypes method
246 282
  *
247 283
  * @access public
@@ -502,16 +538,5 @@ function testAjaxRedirectAsRequestAction() {
502 538
 		Configure::write('viewPaths', $_paths);
503 539
 		unset($_SERVER['HTTP_X_REQUESTED_WITH']);
504 540
 	}
505  
-/**
506  
- * init method
507  
- *
508  
- * @access protected
509  
- * @return void
510  
- */
511  
-	function _init() {
512  
-		$this->Controller = new RequestHandlerTestController(array('components' => array('RequestHandler')));
513  
-		$this->Controller->constructClasses();
514  
-		$this->RequestHandler =& $this->Controller->RequestHandler;
515  
-	}
516 541
 }
517 542
 ?>

0 notes on commit 02ed77a

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