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
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, 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
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller.Component
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5435
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('RequestHandlerComponent', 'Controller/Component');
|
|
|
|
App::uses('CakeRequest', 'Network');
|
|
|
|
App::uses('CakeResponse', 'Network');
|
2011-01-28 06:36:30 +00:00
|
|
|
App::uses('Router', 'Routing');
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller.Component
|
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
|
|
|
|
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
|
|
|
|
*/
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function destination() {
|
2011-05-16 21:32:59 +00:00
|
|
|
$this->viewPath = 'Posts';
|
2009-03-01 06:11:03 +00:00
|
|
|
$this->render('index');
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-02-03 01:39:05 +00:00
|
|
|
/**
|
|
|
|
* test method for ajax redirection + parameter parsing
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function param_method($one = null, $two = null) {
|
2010-02-03 01:39:05 +00:00
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function ajax2_layout() {
|
2010-06-08 03:43:35 +00:00
|
|
|
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-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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller.Component
|
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
|
|
|
|
*/
|
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
|
|
|
|
*/
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2011-10-13 03:07:02 +00:00
|
|
|
parent::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
|
|
|
|
*
|
|
|
|
* @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);
|
2011-11-01 02:41:43 +00:00
|
|
|
$this->Controller->constructClasses();
|
2010-08-28 04:01:41 +00:00
|
|
|
$this->RequestHandler = new RequestHandlerComponent($this->Controller->Components);
|
2011-10-13 03:07:02 +00:00
|
|
|
$this->_extensions = Router::extensions();
|
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
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2011-10-13 03:07:02 +00:00
|
|
|
parent::tearDown();
|
|
|
|
unset($this->RequestHandler, $this->Controller);
|
2009-03-18 17:55:58 +00:00
|
|
|
if (!headers_sent()) {
|
|
|
|
header('Content-type: text/html'); //reset content type.
|
|
|
|
}
|
2010-05-08 04:59:40 +00:00
|
|
|
$_SERVER = $this->_server;
|
2011-10-13 03:07:02 +00:00
|
|
|
call_user_func_array('Router::parseExtensions', $this->_extensions);
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testConstructorSettings() {
|
2010-07-05 00:31:23 +00:00
|
|
|
$settings = array(
|
|
|
|
'ajaxLayout' => 'test_ajax'
|
|
|
|
);
|
|
|
|
$Collection = new ComponentCollection();
|
2011-11-01 02:41:43 +00:00
|
|
|
$Collection->init($this->Controller);
|
2010-07-05 00:31:23 +00:00
|
|
|
$RequestHandler = new RequestHandlerComponent($Collection, $settings);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($RequestHandler->ajaxLayout, 'test_ajax');
|
2010-07-05 00:31:23 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInitializeCallback() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
2011-08-27 14:36:11 +00:00
|
|
|
$this->Controller->request->params['ext'] = 'rss';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->RequestHandler->ext, 'rss');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInitializeContentTypeSettingExt() {
|
2010-07-01 16:01:46 +00:00
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
2011-10-13 03:07:02 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'application/json';
|
2010-07-01 16:01:46 +00:00
|
|
|
Router::parseExtensions('json');
|
|
|
|
|
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->assertEquals('json', $this->RequestHandler->ext);
|
2011-10-13 03:07:02 +00:00
|
|
|
}
|
2010-07-01 16:01:46 +00:00
|
|
|
|
2011-10-13 03:07:02 +00:00
|
|
|
/**
|
|
|
|
* Test that RequestHandler sets $this->ext when jQuery sends its wonky-ish headers.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInitializeContentTypeWithjQueryAccept() {
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01';
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
Router::parseExtensions('json');
|
|
|
|
|
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->assertEquals('json', $this->RequestHandler->ext);
|
|
|
|
}
|
|
|
|
|
2011-10-19 13:36:00 +00:00
|
|
|
/**
|
|
|
|
* Test that RequestHandler sets $this->ext when jQuery sends its wonky-ish headers
|
|
|
|
* and the application is configured to handle multiplate extensions
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInitializeContentTypeWithjQueryAcceptAndMultiplesExtensions() {
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01';
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
Router::parseExtensions('rss', 'json');
|
|
|
|
|
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->assertEquals('json', $this->RequestHandler->ext);
|
|
|
|
}
|
|
|
|
|
2011-10-13 03:07:02 +00:00
|
|
|
/**
|
|
|
|
* Test that RequestHandler does not set $this->ext when multple accepts are sent.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInitializeNoContentTypeWithSingleAccept() {
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/html, */*; q=0.01';
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
Router::parseExtensions('json');
|
|
|
|
|
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
}
|
2011-11-16 03:48:54 +00:00
|
|
|
|
2011-10-13 03:07:02 +00:00
|
|
|
/**
|
|
|
|
* Test that ext is not set with multiple accepted content types.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInitializeNoContentTypeWithMultipleAcceptedTypes() {
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, application/xml, */*; q=0.01';
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
Router::parseExtensions('xml', 'json');
|
|
|
|
|
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
2010-07-01 16:01:46 +00:00
|
|
|
}
|
2011-11-16 03:48:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that ext is not set with confusing android accepts headers.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInitializeAmbiguousAndroidAccepts() {
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
Router::parseExtensions('html', 'xml');
|
|
|
|
|
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
}
|
2010-07-01 16:01:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a type mismatch doesn't incorrectly set the ext
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInitializeContentTypeAndExtensionMismatch() {
|
2010-07-01 16:01:46 +00:00
|
|
|
$this->assertNull($this->RequestHandler->ext);
|
|
|
|
$extensions = Router::extensions();
|
|
|
|
Router::parseExtensions('xml');
|
|
|
|
|
|
|
|
$this->Controller->request = $this->getMock('CakeRequest');
|
2011-10-13 03:07:02 +00:00
|
|
|
$this->Controller->request->expects($this->any())
|
|
|
|
->method('accepts')
|
2010-07-01 16:01:46 +00:00
|
|
|
->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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDisabling() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$_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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAutoResponseType() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->ext = '.thtml';
|
2011-08-27 14:36:11 +00:00
|
|
|
$this->Controller->request->params['ext'] = 'rss';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->RequestHandler->startup($this->Controller);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Controller->ext, '.ctp');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-20 18:51:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testAutoAjaxLayout method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAutoAjaxLayout() {
|
2010-09-20 18:51:17 +00:00
|
|
|
$_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();
|
2011-08-27 14:36:11 +00:00
|
|
|
$this->Controller->request->params['ext'] = 'js';
|
2010-09-20 18:51:17 +00:00
|
|
|
$this->RequestHandler->initialize($this->Controller);
|
|
|
|
$this->RequestHandler->startup($this->Controller);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotEquals($this->Controller->layout, 'ajax');
|
2010-09-20 18:51:17 +00:00
|
|
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testStartupCallback() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
|
$_SERVER['CONTENT_TYPE'] = 'application/xml';
|
2011-09-25 01:56:37 +00:00
|
|
|
$this->Controller->request = $this->getMock('CakeRequest', array('_readInput'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testStartupCallbackCharset() {
|
2008-08-09 18:32:59 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'PUT';
|
|
|
|
$_SERVER['CONTENT_TYPE'] = 'application/xml; charset=UTF-8';
|
2011-09-25 01:56:37 +00:00
|
|
|
$this->Controller->request = $this->getMock('CakeRequest', array('_readInput'));
|
2008-08-09 18:32:59 +00:00
|
|
|
$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
|
|
|
|
2011-05-01 13:59:47 +00:00
|
|
|
/**
|
|
|
|
* Test mapping a new type and having startup process it.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testStartupCustomTypeProcess() {
|
2011-05-01 13:59:47 +00:00
|
|
|
if (!function_exists('str_getcsv')) {
|
|
|
|
$this->markTestSkipped('Need "str_getcsv" for this test.');
|
|
|
|
}
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['CONTENT_TYPE'] = 'text/csv';
|
2011-09-25 01:56:37 +00:00
|
|
|
$this->Controller->request = $this->getMock('CakeRequest', array('_readInput'));
|
2011-05-01 13:59:47 +00:00
|
|
|
$this->Controller->request->expects($this->once())
|
2011-09-25 01:56:37 +00:00
|
|
|
->method('_readInput')
|
2011-05-01 13:59:47 +00:00
|
|
|
->will($this->returnValue('"A","csv","string"'));
|
|
|
|
$this->RequestHandler->addInputType('csv', array('str_getcsv'));
|
|
|
|
$this->RequestHandler->startup($this->Controller);
|
|
|
|
$expected = array(
|
|
|
|
'A', 'csv', 'string'
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->Controller->request->data);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNonAjaxRedirect() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRenderAs() {
|
2010-10-14 03:09:55 +00:00
|
|
|
$this->assertFalse(in_array('Rss', $this->Controller->helpers));
|
|
|
|
$this->RequestHandler->renderAs($this->Controller, 'rss');
|
|
|
|
$this->assertTrue(in_array('Rss', $this->Controller->helpers));
|
2009-10-13 04:01:09 +00:00
|
|
|
|
2010-10-14 03:09:55 +00:00
|
|
|
$this->Controller->viewPath = 'request_handler_test\\rss';
|
2009-10-13 04:01:09 +00:00
|
|
|
$this->RequestHandler->renderAs($this->Controller, 'js');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRenderAsWithAttachment() {
|
2010-09-10 01:31:34 +00:00
|
|
|
$this->RequestHandler->request = $this->getMock('CakeRequest');
|
|
|
|
$this->RequestHandler->request->expects($this->any())
|
2011-08-31 23:19:54 +00:00
|
|
|
->method('parseAccept')
|
|
|
|
->will($this->returnValue(array('1.0' => array('application/xml'))));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-09-10 01:31:34 +00:00
|
|
|
$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');
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-09-10 01:31:34 +00:00
|
|
|
$this->RequestHandler->renderAs($this->Controller, 'xml', array('attachment' => 'myfile.xml'));
|
|
|
|
|
2011-11-08 04:03:36 +00:00
|
|
|
$this->assertEquals('Xml', $this->Controller->viewClass);
|
2010-09-10 01:31:34 +00:00
|
|
|
}
|
|
|
|
|
2010-07-01 02:34:33 +00:00
|
|
|
/**
|
|
|
|
* test that respondAs works as expected.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRespondAsWithAttachment() {
|
2010-09-10 01:31:34 +00:00
|
|
|
$this->RequestHandler = $this->getMock(
|
2011-04-17 10:35:21 +00:00
|
|
|
'RequestHandlerComponent',
|
|
|
|
array('_header'),
|
2010-09-10 01:31:34 +00:00
|
|
|
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');
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-09-10 01:31:34 +00:00
|
|
|
$this->RequestHandler->request->expects($this->once())
|
2011-08-31 23:19:54 +00:00
|
|
|
->method('parseAccept')
|
|
|
|
->will($this->returnValue(array('1.0' => array('application/xml'))));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRenderAsCalledTwice() {
|
2011-11-29 02:36:44 +00:00
|
|
|
$this->RequestHandler->renderAs($this->Controller, 'print');
|
|
|
|
$this->assertEquals('RequestHandlerTest' . DS . 'print', $this->Controller->viewPath);
|
|
|
|
$this->assertEquals('print', $this->Controller->layoutPath);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-14 03:52:06 +00:00
|
|
|
$this->RequestHandler->renderAs($this->Controller, 'js');
|
2011-11-29 02:36:44 +00:00
|
|
|
$this->assertEquals('RequestHandlerTest' . DS . 'js', $this->Controller->viewPath);
|
|
|
|
$this->assertEquals('js', $this->Controller->layoutPath);
|
2009-07-14 03:52:06 +00:00
|
|
|
$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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRequestClientTypes() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$_SERVER['HTTP_X_PROTOTYPE_VERSION'] = '1.5';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->RequestHandler->getAjaxVersion(), '1.5');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRequestContentTypes() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
|
|
$this->assertNull($this->RequestHandler->requestedWith());
|
|
|
|
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
|
|
$_SERVER['CONTENT_TYPE'] = 'application/json';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->RequestHandler->requestedWith(), 'json');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->RequestHandler->requestedWith(array('json', 'xml'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($result, 'json');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->RequestHandler->responseType(), 'atom');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-07-01 03:37:54 +00:00
|
|
|
$request->expects($this->at(2))->method('is')
|
|
|
|
->with('delete')
|
|
|
|
->will($this->returnValue(true));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-07-01 03:37:54 +00:00
|
|
|
$request->expects($this->at(3))->method('is')
|
|
|
|
->with('put')
|
|
|
|
->will($this->returnValue(false));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMapAlias() {
|
2010-07-01 04:13:13 +00:00
|
|
|
$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);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-07-01 04:13:13 +00:00
|
|
|
$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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAccepts() {
|
2010-07-01 04:13:13 +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';
|
2011-11-04 01:16:29 +00:00
|
|
|
$this->assertTrue($this->RequestHandler->accepts(array('js', 'xml', 'html')));
|
2010-07-01 04:13:13 +00:00
|
|
|
$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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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,*/*';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotEquals($this->RequestHandler->prefers(), 'rss');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->RequestHandler->ext = 'rss';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->RequestHandler->prefers(), 'rss');
|
2008-09-19 19:48:22 +00:00
|
|
|
$this->assertFalse($this->RequestHandler->prefers('xml'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->RequestHandler->prefers(array('js', 'xml', 'xhtml')), 'xml');
|
2010-07-01 04:46:28 +00:00
|
|
|
$this->assertFalse($this->RequestHandler->prefers(array('red', 'blue')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->RequestHandler->prefers(array('js', 'json', 'xhtml')), 'xhtml');
|
2011-10-13 03:07:02 +00:00
|
|
|
$this->assertTrue($this->RequestHandler->prefers(array('rss')), 'Should return true if input matches ext.');
|
|
|
|
$this->assertFalse($this->RequestHandler->prefers(array('html')), 'No match with ext, return false.');
|
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();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->RequestHandler->prefers(), 'xml');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT'] = '*/*;q=0.5';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCustomContent() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$_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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->RequestHandler->prefers(), 'mobile');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAjaxRedirectAsRequestAction() {
|
2009-11-03 22:19:02 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
|
2009-11-03 22:19:02 +00:00
|
|
|
), 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();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/posts index/', $result, 'RequestAction redirect failed.');
|
2009-03-01 06:11:03 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAjaxRedirectAsRequestActionStillRenderingLayout() {
|
2010-06-08 03:43:35 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
|
2010-06-08 03:43:35 +00:00
|
|
|
), 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();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/posts index/', $result, 'RequestAction redirect failed.');
|
|
|
|
$this->assertRegExp('/Ajax!/', $result, 'Layout was not rendered.');
|
2010-06-08 03:43:35 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBeforeRedirectCallbackWithArrayUrl() {
|
2010-02-20 06:32:04 +00:00
|
|
|
$_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();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
2011-05-01 13:59:47 +00:00
|
|
|
/**
|
|
|
|
* @expectedException CakeException
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAddInputTypeException() {
|
2011-05-01 13:59:47 +00:00
|
|
|
$this->RequestHandler->addInputType('csv', array('I am not callable'));
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|