2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* RequestHandlerComponentTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5435
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-07-26 01:27:02 +00:00
|
|
|
App::import('Controller', 'Controller', false);
|
2008-05-30 11:40:08 +00:00
|
|
|
App::import('Component', array('RequestHandler'));
|
2010-08-02 23:37:26 +00:00
|
|
|
App::import('Core', array('CakeRequest', 'CakeResponse'));
|
2009-03-01 06:11:03 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* RequestHandlerTestController class
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class RequestHandlerTestController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-14 03:52:06 +00:00
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'RequestHandlerTest';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var mixed null
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-01 06:11:03 +00:00
|
|
|
/**
|
|
|
|
* test method for ajax redirection
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-03-01 06:11:03 +00:00
|
|
|
function destination() {
|
|
|
|
$this->viewPath = 'posts';
|
|
|
|
$this->render('index');
|
|
|
|
}
|
2010-02-03 01:39:05 +00:00
|
|
|
/**
|
|
|
|
* test method for ajax redirection + parameter parsing
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function param_method($one = null, $two = null) {
|
|
|
|
echo "one: $one two: $two";
|
|
|
|
$this->autoRender = false;
|
|
|
|
}
|
2010-06-08 03:43:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test method for testing layout rendering when isAjax()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function ajax2_layout() {
|
|
|
|
if ($this->autoLayout) {
|
|
|
|
$this->layout = 'ajax2';
|
|
|
|
}
|
|
|
|
$this->destination();
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* RequestHandlerTestDisabledController class
|
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
2008-06-10 22:38:05 +00:00
|
|
|
*/
|
|
|
|
class RequestHandlerTestDisabledController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
|
|
|
*
|
|
|
|
* @var mixed null
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* beforeFilter method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function beforeFilter() {
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->RequestHandler->enabled = false;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* RequestHandlerComponentTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class RequestHandlerComponentTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* Controller property
|
|
|
|
*
|
|
|
|
* @var RequestHandlerTestController
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $Controller;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* RequestHandler property
|
|
|
|
*
|
|
|
|
* @var RequestHandlerComponent
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $RequestHandler;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2010-08-02 23:37:26 +00:00
|
|
|
* setUp method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-08-02 23:37:26 +00:00
|
|
|
function setUp() {
|
2010-05-08 04:59:40 +00:00
|
|
|
$this->_server = $_SERVER;
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->_init();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2009-07-14 03:52:06 +00:00
|
|
|
* init method
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function _init() {
|
2010-05-08 04:59:40 +00:00
|
|
|
$request = new CakeRequest('controller_posts/index');
|
2010-08-02 23:37:26 +00:00
|
|
|
$response = new CakeResponse();
|
|
|
|
$this->Controller = new RequestHandlerTestController($request, $response);
|
2010-08-28 04:01:41 +00:00
|
|
|
$this->RequestHandler = new RequestHandlerComponent($this->Controller->Components);
|
2010-05-08 04:59:40 +00:00
|
|
|
$this->RequestHandler->request = $request;
|
2010-08-02 23:37:26 +00:00
|
|
|
$this->RequestHandler->response = $response;
|
2009-07-14 03:52:06 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-14 03:52:06 +00:00
|
|
|
/**
|
|
|
|
* endTest method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @access public
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-08-02 23:37:26 +00:00
|
|
|
function tearDown() {
|
2009-03-18 17:55:58 +00:00
|
|
|
unset($this->RequestHandler);
|
|
|
|
unset($this->Controller);
|
|
|
|
if (!headers_sent()) {
|
|
|
|
header('Content-type: text/html'); //reset content type.
|
|
|
|
}
|
2010-05-08 04:59:40 +00:00
|
|
|
$_SERVER = $this->_server;
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-05 00:31:23 +00:00
|
|
|
/**
|
|
|
|
* Test that the constructor sets the settings.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testConstructorSettings() {
|
|
|
|
$settings = array(
|
|
|
|
'ajaxLayout' => 'test_ajax'
|
|
|
|
);
|
|
|
|
$Collection = new ComponentCollection();
|
|
|
|
$RequestHandler = new RequestHandlerComponent($Collection, $settings);
|
|
|
|
$this->assertEqual($RequestHandler->ajaxLayout, 'test_ajax');
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testInitializeCallback method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testInitializeCallback() {
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
2010-05-08 04:59:40 +00:00
|
|
|
$this->Controller->request->params['url']['ext'] = 'rss';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->assertEqual($this->RequestHandler->ext, 'rss');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-01 16:01:46 +00:00
|
|
|
/**
|
|
|
|
* test that a mapped Accept-type header will set $this->ext correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testInitializeContentTypeSettingExt() {
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
$extensions = Router::extensions();
|
|
|
|
Router::parseExtensions('json');
|
|
|
|
$this->Controller->request = $this->getMock('CakeRequest');
|
|
|
|
$this->Controller->request->expects($this->any())->method('accepts')
|
|
|
|
->will($this->returnValue(array('application/json')));
|
|
|
|
|
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->assertEquals('json', $this->RequestHandler->ext);
|
|
|
|
|
|
|
|
call_user_func_array(array('Router', 'parseExtensions'), $extensions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a type mismatch doesn't incorrectly set the ext
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testInitializeContentTypeAndExtensionMismatch() {
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
$extensions = Router::extensions();
|
|
|
|
Router::parseExtensions('xml');
|
|
|
|
|
|
|
|
$this->Controller->request = $this->getMock('CakeRequest');
|
|
|
|
$this->Controller->request->expects($this->any())->method('accepts')
|
|
|
|
->will($this->returnValue(array('application/json')));
|
|
|
|
|
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
|
|
|
|
call_user_func_array(array('Router', 'parseExtensions'), $extensions);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDisabling method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDisabling() {
|
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->_init();
|
2010-05-08 04:59:40 +00:00
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
2008-06-12 18:36:08 +00:00
|
|
|
$this->Controller->beforeFilter();
|
2010-05-08 04:59:40 +00:00
|
|
|
$this->RequestHandler->startup($this->Controller);
|
|
|
|
$this->assertEqual($this->Controller->params['isAjax'], true);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testAutoResponseType method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAutoResponseType() {
|
|
|
|
$this->Controller->ext = '.thtml';
|
2010-05-08 04:59:40 +00:00
|
|
|
$this->Controller->request->params['url']['ext'] = 'rss';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->RequestHandler->startup($this->Controller);
|
|
|
|
$this->assertEqual($this->Controller->ext, '.ctp');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-20 18:51:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testAutoAjaxLayout method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testAutoAjaxLayout() {
|
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
|
|
|
$this->RequestHandler->startup($this->Controller);
|
2010-09-25 03:27:22 +00:00
|
|
|
$this->assertEquals($this->Controller->layout, $this->RequestHandler->ajaxLayout);
|
2010-09-20 18:51:17 +00:00
|
|
|
|
|
|
|
$this->_init();
|
2010-09-25 03:27:22 +00:00
|
|
|
$this->Controller->request->query['ext'] = 'js';
|
2010-09-20 18:51:17 +00:00
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->RequestHandler->startup($this->Controller);
|
|
|
|
$this->assertNotEqual($this->Controller->layout, 'ajax');
|
|
|
|
|
|
|
|
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testStartupCallback method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testStartupCallback() {
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
|
$_SERVER['CONTENT_TYPE'] = 'application/xml';
|
|
|
|
$this->RequestHandler->startup($this->Controller);
|
2009-12-31 12:06:58 +00:00
|
|
|
$this->assertTrue(is_array($this->Controller->data));
|
|
|
|
$this->assertFalse(is_object($this->Controller->data));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-09 18:32:59 +00:00
|
|
|
/**
|
|
|
|
* testStartupCallback with charset.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2008-08-09 18:32:59 +00:00
|
|
|
function testStartupCallbackCharset() {
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
|
$_SERVER['CONTENT_TYPE'] = 'application/xml; charset=UTF-8';
|
|
|
|
$this->RequestHandler->startup($this->Controller);
|
2009-12-31 12:06:58 +00:00
|
|
|
$this->assertTrue(is_array($this->Controller->data));
|
|
|
|
$this->assertFalse(is_object($this->Controller->data));
|
2008-08-09 18:32:59 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testNonAjaxRedirect method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testNonAjaxRedirect() {
|
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->RequestHandler->startup($this->Controller);
|
|
|
|
$this->assertNull($this->RequestHandler->beforeRedirect($this->Controller, '/'));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRenderAs method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRenderAs() {
|
|
|
|
$this->assertFalse(in_array('Xml', $this->Controller->helpers));
|
|
|
|
$this->RequestHandler->renderAs($this->Controller, 'xml');
|
|
|
|
$this->assertTrue(in_array('Xml', $this->Controller->helpers));
|
2009-10-13 04:01:09 +00:00
|
|
|
|
|
|
|
$this->Controller->viewPath = 'request_handler_test\\xml';
|
|
|
|
$this->RequestHandler->renderAs($this->Controller, 'js');
|
|
|
|
$this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'js');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-10 01:31:34 +00:00
|
|
|
/**
|
|
|
|
* test that attachment headers work with renderAs
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testRenderAsWithAttachment() {
|
|
|
|
$this->RequestHandler->request = $this->getMock('CakeRequest');
|
|
|
|
$this->RequestHandler->request->expects($this->any())
|
|
|
|
->method('accepts')
|
|
|
|
->will($this->returnValue(array('application/xml')));
|
|
|
|
|
|
|
|
$this->RequestHandler->response = $this->getMock('CakeResponse', array('type', 'download', 'charset'));
|
|
|
|
$this->RequestHandler->response->expects($this->at(0))
|
|
|
|
->method('type')
|
|
|
|
->with('application/xml');
|
|
|
|
$this->RequestHandler->response->expects($this->at(1))
|
|
|
|
->method('charset')
|
|
|
|
->with('UTF-8');
|
|
|
|
$this->RequestHandler->response->expects($this->at(2))
|
|
|
|
->method('download')
|
|
|
|
->with('myfile.xml');
|
|
|
|
|
|
|
|
$this->RequestHandler->renderAs($this->Controller, 'xml', array('attachment' => 'myfile.xml'));
|
|
|
|
|
|
|
|
$expected = 'request_handler_test' . DS . 'xml';
|
|
|
|
$this->assertEquals($expected, $this->Controller->viewPath);
|
|
|
|
}
|
|
|
|
|
2010-07-01 02:34:33 +00:00
|
|
|
/**
|
|
|
|
* test that respondAs works as expected.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testRespondAs() {
|
2010-08-02 23:40:01 +00:00
|
|
|
$this->RequestHandler->response = $this->getMock('CakeResponse', array('type'));
|
|
|
|
$this->RequestHandler->response->expects($this->at(0))->method('type')
|
|
|
|
->with('application/json');
|
|
|
|
$this->RequestHandler->response->expects($this->at(1))->method('type')
|
|
|
|
->with('text/xml');
|
2010-07-01 02:47:27 +00:00
|
|
|
|
2010-07-05 00:31:23 +00:00
|
|
|
$RequestHandler = $this->getMock('RequestHandlerComponent', array('_header'), array(&$this->Controller->Components));
|
2010-08-02 23:40:01 +00:00
|
|
|
$result = $this->RequestHandler->respondAs('json');
|
2010-07-01 02:34:33 +00:00
|
|
|
$this->assertTrue($result);
|
2010-08-02 23:40:01 +00:00
|
|
|
$result = $this->RequestHandler->respondAs('text/xml');
|
2010-07-01 02:34:33 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that attachment headers work with respondAs
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testRespondAsWithAttachment() {
|
2010-09-10 01:31:34 +00:00
|
|
|
$this->RequestHandler = $this->getMock(
|
|
|
|
'RequestHandlerComponent',
|
|
|
|
array('_header'),
|
|
|
|
array(&$this->Controller->Components)
|
|
|
|
);
|
2010-08-02 23:40:01 +00:00
|
|
|
$this->RequestHandler->response = $this->getMock('CakeResponse', array('type', 'download'));
|
2010-08-28 04:01:41 +00:00
|
|
|
$this->RequestHandler->request = $this->getMock('CakeRequest');
|
2010-09-10 01:31:34 +00:00
|
|
|
|
|
|
|
$this->RequestHandler->request->expects($this->once())
|
|
|
|
->method('accepts')
|
|
|
|
->will($this->returnValue(array('application/xml')));
|
|
|
|
|
2010-08-02 23:40:01 +00:00
|
|
|
$this->RequestHandler->response->expects($this->once())->method('download')
|
|
|
|
->with('myfile.xml');
|
|
|
|
$this->RequestHandler->response->expects($this->once())->method('type')
|
|
|
|
->with('application/xml');
|
2010-07-01 02:47:27 +00:00
|
|
|
|
2010-08-02 23:40:01 +00:00
|
|
|
$result = $this->RequestHandler->respondAs('xml', array('attachment' => 'myfile.xml'));
|
2010-07-01 02:34:33 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
|
|
|
|
2009-07-14 03:52:06 +00:00
|
|
|
/**
|
|
|
|
* test that calling renderAs() more than once continues to work.
|
|
|
|
*
|
|
|
|
* @link #6466
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-07-14 03:52:06 +00:00
|
|
|
function testRenderAsCalledTwice() {
|
|
|
|
$this->RequestHandler->renderAs($this->Controller, 'xml');
|
2009-10-13 03:55:40 +00:00
|
|
|
$this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'xml');
|
2009-07-14 03:52:06 +00:00
|
|
|
$this->assertEqual($this->Controller->layoutPath, 'xml');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-14 03:52:06 +00:00
|
|
|
$this->assertTrue(in_array('Xml', $this->Controller->helpers));
|
|
|
|
|
|
|
|
$this->RequestHandler->renderAs($this->Controller, 'js');
|
2009-10-13 03:55:40 +00:00
|
|
|
$this->assertEqual($this->Controller->viewPath, 'request_handler_test' . DS . 'js');
|
2009-07-14 03:52:06 +00:00
|
|
|
$this->assertEqual($this->Controller->layoutPath, 'js');
|
|
|
|
$this->assertTrue(in_array('Js', $this->Controller->helpers));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRequestClientTypes method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRequestClientTypes() {
|
|
|
|
$_SERVER['HTTP_X_PROTOTYPE_VERSION'] = '1.5';
|
|
|
|
$this->assertEqual($this->RequestHandler->getAjaxVersion(), '1.5');
|
|
|
|
|
|
|
|
unset($_SERVER['HTTP_X_REQUESTED_WITH'], $_SERVER['HTTP_X_PROTOTYPE_VERSION']);
|
|
|
|
$this->assertFalse($this->RequestHandler->getAjaxVersion());
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-12-10 13:55:58 +00:00
|
|
|
/**
|
|
|
|
* Tests the detection of various Flash versions
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testFlashDetection() {
|
2010-07-01 03:37:54 +00:00
|
|
|
$request = $this->getMock('CakeRequest');
|
|
|
|
$request->expects($this->once())->method('is')
|
|
|
|
->with('flash')
|
|
|
|
->will($this->returnValue(true));
|
2008-12-10 13:55:58 +00:00
|
|
|
|
2010-05-08 04:59:40 +00:00
|
|
|
$this->RequestHandler->request = $request;
|
2008-12-10 13:55:58 +00:00
|
|
|
$this->assertTrue($this->RequestHandler->isFlash());
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRequestContentTypes method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRequestContentTypes() {
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$this->assertNull($this->RequestHandler->requestedWith());
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['CONTENT_TYPE'] = 'application/json';
|
|
|
|
$this->assertEqual($this->RequestHandler->requestedWith(), 'json');
|
|
|
|
|
|
|
|
$result = $this->RequestHandler->requestedWith(array('json', 'xml'));
|
|
|
|
$this->assertEqual($result, 'json');
|
|
|
|
|
|
|
|
$result =$this->RequestHandler->requestedWith(array('rss', 'atom'));
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
|
|
|
|
$this->assertTrue($this->RequestHandler->isXml());
|
|
|
|
$this->assertFalse($this->RequestHandler->isAtom());
|
|
|
|
$this->assertFalse($this->RequestHandler->isRSS());
|
|
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'application/atom+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
|
|
|
|
$this->assertTrue($this->RequestHandler->isAtom());
|
|
|
|
$this->assertFalse($this->RequestHandler->isRSS());
|
|
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'application/rss+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
|
|
|
|
$this->assertFalse($this->RequestHandler->isAtom());
|
|
|
|
$this->assertTrue($this->RequestHandler->isRSS());
|
|
|
|
|
|
|
|
$this->assertFalse($this->RequestHandler->isWap());
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'text/vnd.wap.wml,text/html,text/plain,image/png,*/*';
|
|
|
|
$this->assertTrue($this->RequestHandler->isWap());
|
|
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'application/rss+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testResponseContentType method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testResponseContentType() {
|
2010-08-02 23:51:52 +00:00
|
|
|
$this->assertEquals('html', $this->RequestHandler->responseType());
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($this->RequestHandler->respondAs('atom'));
|
|
|
|
$this->assertEqual($this->RequestHandler->responseType(), 'atom');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMobileDeviceDetection method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMobileDeviceDetection() {
|
2010-07-01 03:37:54 +00:00
|
|
|
$request = $this->getMock('CakeRequest');
|
|
|
|
$request->expects($this->once())->method('is')
|
|
|
|
->with('mobile')
|
|
|
|
->will($this->returnValue(true));
|
2010-05-08 04:59:40 +00:00
|
|
|
|
|
|
|
$this->RequestHandler->request = $request;
|
2010-03-14 20:28:38 +00:00
|
|
|
$this->assertTrue($this->RequestHandler->isMobile());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRequestProperties method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRequestProperties() {
|
2010-07-01 03:37:54 +00:00
|
|
|
$request = $this->getMock('CakeRequest');
|
|
|
|
$request->expects($this->once())->method('is')
|
|
|
|
->with('ssl')
|
|
|
|
->will($this->returnValue(true));
|
2010-05-08 04:59:40 +00:00
|
|
|
|
|
|
|
$this->RequestHandler->request = $request;
|
|
|
|
$this->assertTrue($this->RequestHandler->isSsl());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRequestMethod method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRequestMethod() {
|
2010-07-01 03:37:54 +00:00
|
|
|
$request = $this->getMock('CakeRequest');
|
|
|
|
$request->expects($this->at(0))->method('is')
|
|
|
|
->with('get')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$request->expects($this->at(1))->method('is')
|
|
|
|
->with('post')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$request->expects($this->at(2))->method('is')
|
|
|
|
->with('delete')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$request->expects($this->at(3))->method('is')
|
|
|
|
->with('put')
|
|
|
|
->will($this->returnValue(false));
|
2010-05-08 04:59:40 +00:00
|
|
|
|
|
|
|
$this->RequestHandler->request = $request;
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($this->RequestHandler->isGet());
|
|
|
|
$this->assertFalse($this->RequestHandler->isPost());
|
|
|
|
$this->assertTrue($this->RequestHandler->isDelete());
|
|
|
|
$this->assertFalse($this->RequestHandler->isPut());
|
|
|
|
}
|
|
|
|
|
2010-07-01 04:13:13 +00:00
|
|
|
/**
|
|
|
|
* test that map alias converts aliases to content types.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testMapAlias() {
|
|
|
|
$result = $this->RequestHandler->mapAlias('xml');
|
|
|
|
$this->assertEquals('application/xml', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-01 04:13:13 +00:00
|
|
|
$result = $this->RequestHandler->mapAlias('text/html');
|
|
|
|
$this->assertNull($result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-01 04:13:13 +00:00
|
|
|
$result = $this->RequestHandler->mapAlias('wap');
|
|
|
|
$this->assertEquals('text/vnd.wap.wml', $result);
|
|
|
|
|
|
|
|
$result = $this->RequestHandler->mapAlias(array('xml', 'js', 'json'));
|
|
|
|
$expected = array('application/xml', 'text/javascript', 'application/json');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test accepts() on the component
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testAccepts() {
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
|
|
|
|
$this->assertEqual($this->RequestHandler->accepts(array('js', 'xml', 'html')), 'xml');
|
|
|
|
$this->assertFalse($this->RequestHandler->accepts(array('gif', 'jpeg', 'foo')));
|
|
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = '*/*;q=0.5';
|
|
|
|
$this->assertFalse($this->RequestHandler->accepts('rss'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2010-07-01 03:37:54 +00:00
|
|
|
* test accepts and prefers methods.
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-07-01 04:13:13 +00:00
|
|
|
function testPrefers() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*';
|
|
|
|
$this->assertNotEqual($this->RequestHandler->prefers(), 'rss');
|
|
|
|
$this->RequestHandler->ext = 'rss';
|
|
|
|
$this->assertEqual($this->RequestHandler->prefers(), 'rss');
|
2008-09-19 19:48:22 +00:00
|
|
|
$this->assertFalse($this->RequestHandler->prefers('xml'));
|
2009-04-14 13:16:25 +00:00
|
|
|
$this->assertEqual($this->RequestHandler->prefers(array('js', 'xml', 'xhtml')), 'xml');
|
2010-07-01 04:46:28 +00:00
|
|
|
$this->assertFalse($this->RequestHandler->prefers(array('red', 'blue')));
|
|
|
|
$this->assertEqual($this->RequestHandler->prefers(array('js', 'json', 'xhtml')), 'xhtml');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
|
|
|
|
$this->_init();
|
|
|
|
$this->assertEqual($this->RequestHandler->prefers(), 'xml');
|
|
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = '*/*;q=0.5';
|
|
|
|
$this->assertEqual($this->RequestHandler->prefers(), 'html');
|
2008-09-19 19:48:22 +00:00
|
|
|
$this->assertFalse($this->RequestHandler->prefers('rss'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testCustomContent method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testCustomContent() {
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'text/x-mobile,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5';
|
|
|
|
$this->RequestHandler->setContent('mobile', 'text/x-mobile');
|
|
|
|
$this->RequestHandler->startup($this->Controller);
|
|
|
|
$this->assertEqual($this->RequestHandler->prefers(), 'mobile');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testClientProperties method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testClientProperties() {
|
2010-07-01 03:37:54 +00:00
|
|
|
$request = $this->getMock('CakeRequest');
|
|
|
|
$request->expects($this->once())->method('referer');
|
|
|
|
$request->expects($this->once())->method('clientIp')->will($this->returnValue(false));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-08 04:59:40 +00:00
|
|
|
$this->RequestHandler->request = $request;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-08 04:59:40 +00:00
|
|
|
$this->RequestHandler->getReferer();
|
|
|
|
$this->RequestHandler->getClientIP(false);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-01 06:11:03 +00:00
|
|
|
/**
|
|
|
|
* test that ajax requests involving redirects trigger requestAction instead.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-03-01 06:11:03 +00:00
|
|
|
function testAjaxRedirectAsRequestAction() {
|
2009-11-03 22:19:02 +00:00
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
|
|
|
), true);
|
2009-03-01 06:11:03 +00:00
|
|
|
|
2010-07-05 00:31:23 +00:00
|
|
|
$this->Controller->RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'), array(&$this->Controller->Components));
|
2010-07-01 03:37:54 +00:00
|
|
|
$this->Controller->request = $this->getMock('CakeRequest');
|
2010-08-02 23:40:01 +00:00
|
|
|
$this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2010-05-08 04:59:40 +00:00
|
|
|
$this->Controller->RequestHandler->request = $this->Controller->request;
|
2010-08-02 23:40:01 +00:00
|
|
|
$this->Controller->RequestHandler->response = $this->Controller->response;
|
2010-07-01 03:37:54 +00:00
|
|
|
$this->Controller->request->expects($this->any())->method('is')->will($this->returnValue(true));
|
2010-06-09 04:02:49 +00:00
|
|
|
$this->Controller->RequestHandler->expects($this->once())->method('_stop');
|
2009-03-01 06:11:03 +00:00
|
|
|
|
|
|
|
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.');
|
|
|
|
|
2009-11-03 22:19:02 +00:00
|
|
|
App::build();
|
2009-03-01 06:11:03 +00:00
|
|
|
}
|
2010-02-03 01:39:05 +00:00
|
|
|
|
2010-06-08 03:43:35 +00:00
|
|
|
/**
|
|
|
|
* test that ajax requests involving redirects don't force no layout
|
|
|
|
* this would cause the ajax layout to not be rendered.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testAjaxRedirectAsRequestActionStillRenderingLayout() {
|
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
|
|
|
), true);
|
|
|
|
|
2010-07-05 00:31:23 +00:00
|
|
|
$this->Controller->RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'), array(&$this->Controller->Components));
|
2010-07-01 03:37:54 +00:00
|
|
|
$this->Controller->request = $this->getMock('CakeRequest');
|
2010-08-02 23:40:01 +00:00
|
|
|
$this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2010-07-01 03:37:54 +00:00
|
|
|
$this->Controller->RequestHandler->request = $this->Controller->request;
|
2010-08-02 23:40:01 +00:00
|
|
|
$this->Controller->RequestHandler->response = $this->Controller->response;
|
2010-07-01 03:37:54 +00:00
|
|
|
$this->Controller->request->expects($this->any())->method('is')->will($this->returnValue(true));
|
2010-07-01 02:47:27 +00:00
|
|
|
$this->Controller->RequestHandler->expects($this->once())->method('_stop');
|
2010-06-08 03:43:35 +00:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$this->Controller->RequestHandler->beforeRedirect(
|
|
|
|
$this->Controller, array('controller' => 'request_handler_test', 'action' => 'ajax2_layout')
|
|
|
|
);
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.');
|
|
|
|
$this->assertPattern('/Ajax!/', $result, 'Layout was not rendered.');
|
|
|
|
|
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
2010-02-20 06:32:04 +00:00
|
|
|
/**
|
|
|
|
* test that the beforeRedirect callback properly converts
|
|
|
|
* array urls into their correct string ones, and adds base => false so
|
|
|
|
* the correct urls are generated.
|
|
|
|
*
|
|
|
|
* @link http://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/276
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testBeforeRedirectCallbackWithArrayUrl() {
|
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
2010-05-04 02:07:13 +00:00
|
|
|
|
2010-02-20 06:32:04 +00:00
|
|
|
Router::setRequestInfo(array(
|
2010-06-08 03:43:35 +00:00
|
|
|
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')),
|
2010-02-20 06:32:04 +00:00
|
|
|
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
|
|
|
|
));
|
|
|
|
|
2010-07-05 00:31:23 +00:00
|
|
|
$RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'), array(&$this->Controller->Components));
|
2010-08-02 23:40:01 +00:00
|
|
|
$RequestHandler->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2010-05-08 04:59:40 +00:00
|
|
|
$RequestHandler->request = new CakeRequest('posts/index');
|
2010-08-28 04:01:41 +00:00
|
|
|
$RequestHandler->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2010-02-20 06:32:04 +00:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$RequestHandler->beforeRedirect(
|
|
|
|
$this->Controller,
|
|
|
|
array('controller' => 'request_handler_test', 'action' => 'param_method', 'first', 'second')
|
|
|
|
);
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertEqual($result, 'one: first two: second');
|
2010-05-04 02:07:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-01 02:47:27 +00:00
|
|
|
* assure that beforeRedirect with a status code will correctly set the status header
|
2010-05-04 02:07:13 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testBeforeRedirectCallingHeader() {
|
2010-06-09 04:02:49 +00:00
|
|
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
|
|
|
|
|
|
|
$controller = $this->getMock('Controller', array('header'));
|
2010-07-05 00:31:23 +00:00
|
|
|
$RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'), array(&$this->Controller->Components));
|
2010-08-02 23:40:01 +00:00
|
|
|
$RequestHandler->response = $this->getMock('CakeResponse', array('_sendHeader','statusCode'));
|
2010-06-29 03:41:48 +00:00
|
|
|
$RequestHandler->request = $this->getMock('CakeRequest');
|
|
|
|
$RequestHandler->request->expects($this->once())->method('is')
|
|
|
|
->with('ajax')
|
|
|
|
->will($this->returnValue(true));
|
2010-05-04 02:07:13 +00:00
|
|
|
|
2010-08-02 23:40:01 +00:00
|
|
|
$RequestHandler->response->expects($this->once())->method('statusCode')->with(403);
|
2010-05-04 02:07:13 +00:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$RequestHandler->beforeRedirect($controller, 'request_handler_test/param_method/first/second', 403);
|
|
|
|
$result = ob_get_clean();
|
2009-03-01 06:11:03 +00:00
|
|
|
}
|
2010-02-03 01:39:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|