From 02ed77ab202b2f71a3f19395c034d4287fff25a4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 14 Jul 2009 03:52:06 +0000 Subject: [PATCH] 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 --- .../controller/components/request_handler.php | 2 +- .../components/request_handler.test.php | 55 ++++++++++++++----- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index 8887ff443..efca6b2c5 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -585,7 +585,7 @@ class RequestHandlerComponent extends Object { 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; diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index 0af25da9c..f0e638d4d 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -35,6 +35,13 @@ Mock::generatePartial('RequestHandlerComponent', 'NoStopRequestHandler', array(' * @subpackage cake.tests.cases.libs.controller.components */ class RequestHandlerTestController extends Controller { +/** + * name property + * + * @var string + * @access public + **/ + var $name = 'RequestHandlerTest'; /** * uses property * @@ -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()) { @@ -241,6 +259,24 @@ class RequestHandlerComponentTest extends CakeTestCase { $this->RequestHandler->renderAs($this->Controller, 'xml'); $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 * @@ -502,16 +538,5 @@ class RequestHandlerComponentTest extends CakeTestCase { 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; - } } ?> \ No newline at end of file