Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@markstory markstory authored
View
2  cake/libs/controller/components/request_handler.php
@@ -585,7 +585,7 @@ function renderAs(&$controller, $type) {
if (empty($this->__renderType)) {
$controller->viewPath .= '/' . $type;
} else {
- $remove = preg_replace("/(?:\/{$type})$/", '/' . $type, $controller->viewPath);
+ $remove = preg_replace("/(?:\/{$this->__renderType})$/", '/' . $type, $controller->viewPath);
$controller->viewPath = $remove;
}
$this->__renderType = $type;
View
55 cake/tests/cases/libs/controller/components/request_handler.test.php
@@ -36,6 +36,13 @@
*/
class RequestHandlerTestController extends Controller {
/**
+ * name property
+ *
+ * @var string
+ * @access public
+ **/
+ var $name = 'RequestHandlerTest';
+/**
* uses property
*
* @var mixed null
@@ -124,21 +131,32 @@ class RequestHandlerComponentTest extends CakeTestCase {
*/
var $RequestHandler;
/**
- * setUp method
+ * startTest method
*
* @access public
* @return void
*/
- function setUp() {
+ function startTest() {
$this->_init();
}
/**
- * tearDown method
+ * init method
+ *
+ * @access protected
+ * @return void
+ */
+ function _init() {
+ $this->Controller = new RequestHandlerTestController(array('components' => array('RequestHandler')));
+ $this->Controller->constructClasses();
+ $this->RequestHandler =& $this->Controller->RequestHandler;
+ }
+/**
+ * endTest method
*
* @access public
* @return void
*/
- function tearDown() {
+ function endTest() {
unset($this->RequestHandler);
unset($this->Controller);
if (!headers_sent()) {
@@ -242,6 +260,24 @@ function testRenderAs() {
$this->assertTrue(in_array('Xml', $this->Controller->helpers));
}
/**
+ * test that calling renderAs() more than once continues to work.
+ *
+ * @link #6466
+ * @return void
+ **/
+ function testRenderAsCalledTwice() {
+ $this->RequestHandler->renderAs($this->Controller, 'xml');
+ $this->assertEqual($this->Controller->viewPath, 'request_handler_test/xml');
+ $this->assertEqual($this->Controller->layoutPath, 'xml');
+
+ $this->assertTrue(in_array('Xml', $this->Controller->helpers));
+
+ $this->RequestHandler->renderAs($this->Controller, 'js');
+ $this->assertEqual($this->Controller->viewPath, 'request_handler_test/js');
+ $this->assertEqual($this->Controller->layoutPath, 'js');
+ $this->assertTrue(in_array('Js', $this->Controller->helpers));
+ }
+/**
* testRequestClientTypes method
*
* @access public
@@ -502,16 +538,5 @@ function testAjaxRedirectAsRequestAction() {
Configure::write('viewPaths', $_paths);
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
}
-/**
- * init method
- *
- * @access protected
- * @return void
- */
- function _init() {
- $this->Controller = new RequestHandlerTestController(array('components' => array('RequestHandler')));
- $this->Controller->constructClasses();
- $this->RequestHandler =& $this->Controller->RequestHandler;
- }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.