Skip to content

Commit

Permalink
Adding tests for calling RequestHandlerComponent::renderAs() twice.
Browse files Browse the repository at this point in the history
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
markstory committed Jul 14, 2009
1 parent f712d84 commit 02ed77a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cake/libs/controller/components/request_handler.php
Expand Up @@ -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;
Expand Down
Expand Up @@ -35,6 +35,13 @@
* @subpackage cake.tests.cases.libs.controller.components
*/
class RequestHandlerTestController extends Controller {
/**
* name property
*
* @var string
* @access public
**/
var $name = 'RequestHandlerTest';
/**
* uses property
*
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -241,6 +259,24 @@ function testRenderAs() {
$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
*
Expand Down Expand Up @@ -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;
}
}
?>

0 comments on commit 02ed77a

Please sign in to comment.