Skip to content

Commit

Permalink
Adding test case for RequestHandler::beforeRedirect() when request is…
Browse files Browse the repository at this point in the history
… an ajax request. Ensures that requestAction() is properly triggered.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8068 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Mar 1, 2009
1 parent 259ecbe commit d9cbb85
Showing 1 changed file with 36 additions and 0 deletions.
Expand Up @@ -26,6 +26,8 @@
*/
App::import('Core', array('Controller'));
App::import('Component', array('RequestHandler'));

Mock::generatePartial('RequestHandlerComponent', 'NoStopRequestHandler', array('_stop'));
/**
* RequestHandlerTestController class
*
Expand Down Expand Up @@ -53,6 +55,15 @@ function __construct($params = array()) {
}
parent::__construct();
}
/**
* test method for ajax redirection
*
* @return void
**/
function destination() {
$this->viewPath = 'posts';
$this->render('index');
}
}
/**
* RequestHandlerTestDisabledController class
Expand Down Expand Up @@ -444,6 +455,31 @@ function testClientProperties() {
$_SERVER['HTTP_CLIENTADDRESS'] = '10.0.1.2, 10.0.1.1';
$this->assertEqual($this->RequestHandler->getClientIP(), '10.0.1.2');
}
/**
* test that ajax requests involving redirects trigger requestAction instead.
*
* @return void
**/
function testAjaxRedirectAsRequestAction() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->_init();
$_paths = Configure::read('viewPaths');
$testDir = array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS);
Configure::write('viewPaths', array_merge($testDir, $_paths));

$this->Controller->RequestHandler = new NoStopRequestHandler($this);
$this->Controller->RequestHandler->expectOnce('_stop');

ob_start();
$this->Controller->RequestHandler->beforeRedirect(
$this->Controller, array('controller' => 'request_handler_test', 'action' => 'destination')
);
$result = ob_get_clean();
$this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.');

Configure::write('viewPaths', $_paths);
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
}
/**
* tearDown method
*
Expand Down

0 comments on commit d9cbb85

Please sign in to comment.