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
This commit is contained in:
mark_story 2009-07-14 03:52:06 +00:00
parent f712d84d33
commit 02ed77ab20
2 changed files with 41 additions and 16 deletions

View file

@ -585,7 +585,7 @@ class RequestHandlerComponent extends Object {
if (empty($this->__renderType)) { if (empty($this->__renderType)) {
$controller->viewPath .= '/' . $type; $controller->viewPath .= '/' . $type;
} else { } else {
$remove = preg_replace("/(?:\/{$type})$/", '/' . $type, $controller->viewPath); $remove = preg_replace("/(?:\/{$this->__renderType})$/", '/' . $type, $controller->viewPath);
$controller->viewPath = $remove; $controller->viewPath = $remove;
} }
$this->__renderType = $type; $this->__renderType = $type;

View file

@ -35,6 +35,13 @@ Mock::generatePartial('RequestHandlerComponent', 'NoStopRequestHandler', array('
* @subpackage cake.tests.cases.libs.controller.components * @subpackage cake.tests.cases.libs.controller.components
*/ */
class RequestHandlerTestController extends Controller { class RequestHandlerTestController extends Controller {
/**
* name property
*
* @var string
* @access public
**/
var $name = 'RequestHandlerTest';
/** /**
* uses property * uses property
* *
@ -124,21 +131,32 @@ class RequestHandlerComponentTest extends CakeTestCase {
*/ */
var $RequestHandler; var $RequestHandler;
/** /**
* setUp method * startTest method
* *
* @access public * @access public
* @return void * @return void
*/ */
function setUp() { function startTest() {
$this->_init(); $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 * @access public
* @return void * @return void
*/ */
function tearDown() { function endTest() {
unset($this->RequestHandler); unset($this->RequestHandler);
unset($this->Controller); unset($this->Controller);
if (!headers_sent()) { if (!headers_sent()) {
@ -241,6 +259,24 @@ class RequestHandlerComponentTest extends CakeTestCase {
$this->RequestHandler->renderAs($this->Controller, 'xml'); $this->RequestHandler->renderAs($this->Controller, 'xml');
$this->assertTrue(in_array('Xml', $this->Controller->helpers)); $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 * testRequestClientTypes method
* *
@ -502,16 +538,5 @@ class RequestHandlerComponentTest extends CakeTestCase {
Configure::write('viewPaths', $_paths); Configure::write('viewPaths', $_paths);
unset($_SERVER['HTTP_X_REQUESTED_WITH']); 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;
}
} }
?> ?>