mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Modifying Dispatcher and its test cases to accept a CakeResponse as part of its
arguments.
This commit is contained in:
parent
420a2f56df
commit
9641bcc8df
3 changed files with 117 additions and 95 deletions
|
@ -291,10 +291,11 @@ class Controller extends Object {
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CakeRequest $request Request object for this controller can be null for testing.
|
||||
* But expect that features that use the params will not work.
|
||||
* @param CakeRequest $request Request object for this controller. Can be null for testing,
|
||||
* but expect that features that use the request parameters will not work.
|
||||
* @param CakeResponse $response Response object for this controller.
|
||||
*/
|
||||
public function __construct($request = null) {
|
||||
public function __construct($request = null, $response = null) {
|
||||
if ($this->name === null) {
|
||||
$this->name = substr(get_class($this), 0, strlen(get_class($this)) -10);
|
||||
}
|
||||
|
@ -315,7 +316,9 @@ class Controller extends Object {
|
|||
if ($request instanceof CakeRequest) {
|
||||
$this->setRequest($request);
|
||||
}
|
||||
$this->getResponse();
|
||||
if ($response instanceof CakeResponse) {
|
||||
$this->response = $response;
|
||||
}
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
|
|
@ -72,19 +72,20 @@ class Dispatcher {
|
|||
* If the controller is found, and the action is not found an exception will be thrown.
|
||||
*
|
||||
* @param CakeRequest $request Request object to dispatch.
|
||||
* @param CakeResponse $response Response object to put the results of the dispatch into.
|
||||
* @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
|
||||
* @return boolean Success
|
||||
* @throws MissingControllerException, MissingActionException, PrivateActionException if any of those error states
|
||||
* are encountered.
|
||||
*/
|
||||
public function dispatch(CakeRequest $request, $additionalParams = array()) {
|
||||
if ($this->asset($request->url) || $this->cached($request->here)) {
|
||||
public function dispatch(CakeRequest $request, CakeResponse $response, $additionalParams = array()) {
|
||||
if ($this->asset($request->url, $response) || $this->cached($request->here)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request = $this->parseParams($request, $additionalParams);
|
||||
Router::setRequestInfo($request);
|
||||
$controller = $this->_getController($request);
|
||||
$controller = $this->_getController($request, $response);
|
||||
|
||||
if (!($controller instanceof Controller)) {
|
||||
throw new MissingControllerException(array(
|
||||
|
@ -99,7 +100,7 @@ class Dispatcher {
|
|||
));
|
||||
}
|
||||
|
||||
return $this->_invoke($controller, $request);
|
||||
return $this->_invoke($controller, $request, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,7 +134,7 @@ class Dispatcher {
|
|||
* @return string Output as sent by controller
|
||||
* @throws MissingActionException when the action being called is missing.
|
||||
*/
|
||||
protected function _invoke(Controller $controller, CakeRequest $request) {
|
||||
protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) {
|
||||
$controller->constructClasses();
|
||||
$controller->startupProcess();
|
||||
|
||||
|
@ -149,7 +150,6 @@ class Dispatcher {
|
|||
));
|
||||
}
|
||||
$result = call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']);
|
||||
$response = $controller->getResponse();
|
||||
|
||||
if ($controller->autoRender) {
|
||||
$controller->render();
|
||||
|
@ -192,15 +192,16 @@ class Dispatcher {
|
|||
/**
|
||||
* Get controller to use, either plugin controller or application controller
|
||||
*
|
||||
* @param array $params Array of parameters
|
||||
* @param CakeRequest $request Request object
|
||||
* @param CakeResponse $response Response for the controller.
|
||||
* @return mixed name of controller if not loaded, or object if loaded
|
||||
*/
|
||||
protected function _getController($request) {
|
||||
protected function _getController($request, $response) {
|
||||
$ctrlClass = $this->_loadController($request);
|
||||
if (!$ctrlClass) {
|
||||
return false;
|
||||
}
|
||||
return new $ctrlClass($request);
|
||||
return new $ctrlClass($request, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,10 +271,11 @@ class Dispatcher {
|
|||
/**
|
||||
* Checks if a requested asset exists and sends it to the browser
|
||||
*
|
||||
* @param $url string $url Requested URL
|
||||
* @param string $url Requested URL
|
||||
* @param CakeResponse $response The response object to put the file contents in.
|
||||
* @return boolean True on success if the asset file was found and sent
|
||||
*/
|
||||
public function asset($url) {
|
||||
public function asset($url, CakeResponse $response) {
|
||||
if (strpos($url, '..') !== false || strpos($url, '.') === false) {
|
||||
return false;
|
||||
}
|
||||
|
@ -286,12 +288,9 @@ class Dispatcher {
|
|||
strpos($url, 'cjs/') === 0 ||
|
||||
preg_match('#^/((theme/[^/]+)/cjs/)|(([^/]+)(?<!js)/cjs)/#i', $url)
|
||||
);
|
||||
if (!$this->response) {
|
||||
$this->response = new CakeResponse();
|
||||
}
|
||||
if (($isCss && empty($filters['css'])) || ($isJs && empty($filters['js']))) {
|
||||
$this->response->statusCode(404);
|
||||
$this->response->send();
|
||||
$response->statusCode(404);
|
||||
$response->send();
|
||||
return true;
|
||||
} elseif ($isCss) {
|
||||
include WWW_ROOT . DS . $filters['css'];
|
||||
|
@ -326,7 +325,7 @@ class Dispatcher {
|
|||
}
|
||||
|
||||
if ($assetFile !== null) {
|
||||
$this->_deliverAsset($assetFile, $ext);
|
||||
$this->_deliverAsset($response, $assetFile, $ext);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -335,23 +334,24 @@ class Dispatcher {
|
|||
/**
|
||||
* Sends an asset file to the client
|
||||
*
|
||||
* @param CakeResponse $response The response object to use.
|
||||
* @param string $assetFile Path to the asset file in the file system
|
||||
* @param string $ext The extension of the file to determine its mime type
|
||||
* @return void
|
||||
*/
|
||||
protected function _deliverAsset($assetFile, $ext) {
|
||||
protected function _deliverAsset(CakeResponse $response, $assetFile, $ext) {
|
||||
ob_start();
|
||||
$compressionEnabled = Configure::read('Asset.compress') && $this->response->compress();
|
||||
if ($this->response->type($ext) == $ext) {
|
||||
$compressionEnabled = Configure::read('Asset.compress') && $response->compress();
|
||||
if ($response->type($ext) == $ext) {
|
||||
$contentType = 'application/octet-stream';
|
||||
$agent = env('HTTP_USER_AGENT');
|
||||
if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
|
||||
$contentType = 'application/octetstream';
|
||||
}
|
||||
$this->response->type($contentType);
|
||||
$response->type($contentType);
|
||||
}
|
||||
$this->response->cache(filemtime($assetFile));
|
||||
$this->response->send();
|
||||
$response->cache(filemtime($assetFile));
|
||||
$response->send();
|
||||
ob_clean();
|
||||
if ($ext === 'css' || $ext === 'js') {
|
||||
include($assetFile);
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::uses('Dispatcher', 'Routing');
|
||||
App::uses('CakeResponse', 'Network');
|
||||
|
||||
if (!class_exists('AppController', false)) {
|
||||
require_once CAKE . 'Controller' . DS . 'AppController.php';
|
||||
|
@ -50,8 +49,8 @@ class TestDispatcher extends Dispatcher {
|
|||
* @param mixed $request
|
||||
* @return void
|
||||
*/
|
||||
protected function _invoke(Controller $controller, CakeRequest $request) {
|
||||
if ($result = parent::_invoke($controller, $request)) {
|
||||
protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) {
|
||||
if ($result = parent::_invoke($controller, $request, $response)) {
|
||||
if ($result[0] === 'missingAction') {
|
||||
return $result;
|
||||
}
|
||||
|
@ -695,7 +694,8 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher = new TestDispatcher();
|
||||
Configure::write('App.baseUrl', '/index.php');
|
||||
$url = new CakeRequest('some_controller/home/param:value/param2:value2');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$response = $this->getMock('CakeResponse');
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->fail('No exception thrown');
|
||||
} catch (MissingControllerException $e) {
|
||||
$this->assertEquals('Controller class SomeControllerController could not be found.', $e->getMessage());
|
||||
|
@ -711,9 +711,10 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher = new TestDispatcher();
|
||||
Configure::write('App.baseUrl','/index.php');
|
||||
$url = new CakeRequest('some_pages/_protected/param:value/param2:value2');
|
||||
$response = $this->getMock('CakeResponse');
|
||||
|
||||
try {
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->fail('No exception thrown');
|
||||
} catch (PrivateActionException $e) {
|
||||
$this->assertEquals(
|
||||
|
@ -731,9 +732,10 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher = new TestDispatcher();
|
||||
Configure::write('App.baseUrl', '/index.php');
|
||||
$url = new CakeRequest('some_pages/home/param:value/param2:value2');
|
||||
$response = $this->getMock('CakeResponse');
|
||||
|
||||
try {
|
||||
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
|
||||
$this->fail('No exception thrown');
|
||||
} catch (MissingActionException $e) {
|
||||
$this->assertEquals('Action SomePagesController::home() could not be found.', $e->getMessage());
|
||||
|
@ -749,9 +751,10 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher = new TestDispatcher();
|
||||
Configure::write('App.baseUrl','/index.php');
|
||||
$url = new CakeRequest('some_pages/redirect/param:value/param2:value2');
|
||||
$response = $this->getMock('CakeResponse');
|
||||
|
||||
try {
|
||||
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
|
||||
$this->fail('No exception thrown');
|
||||
} catch (MissingActionException $e) {
|
||||
$this->assertEquals('Action SomePagesController::redirect() could not be found.', $e->getMessage());
|
||||
|
@ -770,8 +773,9 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher = new TestDispatcher();
|
||||
Configure::write('App.baseUrl', '/index.php');
|
||||
$url = new CakeRequest('pages/home/param:value/param2:value2');
|
||||
$response = $this->getMock('CakeResponse');
|
||||
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$expected = 'Pages';
|
||||
$this->assertEqual($expected, $controller->name);
|
||||
|
||||
|
@ -781,13 +785,13 @@ class DispatcherTest extends CakeTestCase {
|
|||
Configure::write('App.baseUrl','/pages/index.php');
|
||||
|
||||
$url = new CakeRequest('pages/home');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
|
||||
$expected = 'Pages';
|
||||
$this->assertEqual($expected, $controller->name);
|
||||
|
||||
$url = new CakeRequest('pages/home/');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->assertNull($controller->plugin);
|
||||
|
||||
$expected = 'Pages';
|
||||
|
@ -799,23 +803,23 @@ class DispatcherTest extends CakeTestCase {
|
|||
Configure::write('App.baseUrl', '/timesheets/index.php');
|
||||
|
||||
$url = new CakeRequest('timesheets');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
|
||||
$expected = 'Timesheets';
|
||||
$this->assertEqual($expected, $controller->name);
|
||||
|
||||
$url = new CakeRequest('timesheets/');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
|
||||
$this->assertEqual('Timesheets', $controller->name);
|
||||
$this->assertEqual('/timesheets/index.php', $url->base);
|
||||
|
||||
$url = new CakeRequest('test_dispatch_pages/camelCased');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->assertEqual('TestDispatchPages', $controller->name);
|
||||
|
||||
$url = new CakeRequest('test_dispatch_pages/camelCased/something. .');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s');
|
||||
}
|
||||
|
||||
|
@ -830,9 +834,10 @@ class DispatcherTest extends CakeTestCase {
|
|||
Configure::write('Routing.prefixes', array('admin'));
|
||||
Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php');
|
||||
$url = new CakeRequest('admin/test_dispatch_pages/index/param:value/param2:value2');
|
||||
$response = $this->getMock('CakeResponse');
|
||||
|
||||
Router::reload();
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
|
||||
$this->assertEqual($controller->name, 'TestDispatchPages');
|
||||
|
||||
|
@ -862,7 +867,8 @@ class DispatcherTest extends CakeTestCase {
|
|||
);
|
||||
|
||||
$url = new CakeRequest('my_plugin/some_pages/home/param:value/param2:value2');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$response = $this->getMock('CakeResponse');
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
|
||||
$result = $Dispatcher->parseParams($url);
|
||||
$expected = array(
|
||||
|
@ -899,7 +905,8 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher->base = false;
|
||||
|
||||
$url = new CakeRequest('my_plugin/other_pages/index/param:value/param2:value2');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$response = $this->getMock('CakeResponse');
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
|
||||
$this->assertIdentical($controller->plugin, 'MyPlugin');
|
||||
$this->assertIdentical($controller->name, 'OtherPages');
|
||||
|
@ -907,10 +914,10 @@ class DispatcherTest extends CakeTestCase {
|
|||
$this->assertIdentical($controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
|
||||
|
||||
$expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2';
|
||||
$this->assertIdentical($expected, $controller->here);
|
||||
$this->assertIdentical($expected, $url->here);
|
||||
|
||||
$expected = '/cake/repo/branches/1.2.x.x';
|
||||
$this->assertIdentical($expected, $controller->base);
|
||||
$this->assertIdentical($expected, $url->base);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -933,8 +940,9 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher->base = false;
|
||||
|
||||
$url = new CakeRequest('my_plugin/my_plugin/add/param:value/param2:value2');
|
||||
$response = $this->getMock('CakeResponse');
|
||||
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
|
||||
$this->assertIdentical($controller->plugin, 'MyPlugin');
|
||||
$this->assertIdentical($controller->name, 'MyPlugin');
|
||||
|
@ -953,7 +961,7 @@ class DispatcherTest extends CakeTestCase {
|
|||
$pluginUrl = Inflector::underscore($plugin);
|
||||
|
||||
$url = new CakeRequest($pluginUrl);
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->assertIdentical($controller->plugin, 'MyPlugin');
|
||||
$this->assertIdentical($controller->name, 'MyPlugin');
|
||||
$this->assertIdentical($controller->action, 'index');
|
||||
|
@ -968,7 +976,9 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher = new TestDispatcher();
|
||||
|
||||
$url = new CakeRequest('admin/my_plugin/my_plugin/add/5/param:value/param2:value2');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$response = $this->getMock('CakeResponse');
|
||||
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
|
||||
$this->assertEqual($controller->params['plugin'], 'my_plugin');
|
||||
$this->assertEqual($controller->params['controller'], 'my_plugin');
|
||||
|
@ -988,7 +998,7 @@ class DispatcherTest extends CakeTestCase {
|
|||
|
||||
$Dispatcher = new TestDispatcher();
|
||||
|
||||
$controller = $Dispatcher->dispatch(new CakeRequest('admin/articles_test'), array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch(new CakeRequest('admin/articles_test'), $response, array('return' => 1));
|
||||
$this->assertIdentical($controller->plugin, 'ArticlesTest');
|
||||
$this->assertIdentical($controller->name, 'ArticlesTest');
|
||||
$this->assertIdentical($controller->action, 'admin_index');
|
||||
|
@ -1022,7 +1032,9 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher->base = false;
|
||||
|
||||
$url = new CakeRequest('my_plugin/');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$response = $this->getMock('CakeResponse');
|
||||
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->assertEqual($controller->params['controller'], 'my_plugin');
|
||||
$this->assertEqual($controller->params['plugin'], 'my_plugin');
|
||||
$this->assertEqual($controller->params['action'], 'index');
|
||||
|
@ -1049,21 +1061,23 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher->base = false;
|
||||
|
||||
$url = new CakeRequest('test_plugin/');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$response = $this->getMock('CakeResponse');
|
||||
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->assertEqual($controller->params['controller'], 'test_plugin');
|
||||
$this->assertEqual($controller->params['plugin'], 'test_plugin');
|
||||
$this->assertEqual($controller->params['action'], 'index');
|
||||
$this->assertFalse(isset($controller->params['pass'][0]));
|
||||
|
||||
$url = new CakeRequest('/test_plugin/tests/index');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->assertEqual($controller->params['controller'], 'tests');
|
||||
$this->assertEqual($controller->params['plugin'], 'test_plugin');
|
||||
$this->assertEqual($controller->params['action'], 'index');
|
||||
$this->assertFalse(isset($controller->params['pass'][0]));
|
||||
|
||||
$url = new CakeRequest('/test_plugin/tests/index/some_param');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->assertEqual($controller->params['controller'], 'tests');
|
||||
$this->assertEqual($controller->params['plugin'], 'test_plugin');
|
||||
$this->assertEqual($controller->params['action'], 'index');
|
||||
|
@ -1086,9 +1100,10 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher->base = false;
|
||||
|
||||
$url = new CakeRequest('my_plugin/not_here/param:value/param2:value2');
|
||||
$response = $this->getMock('CakeResponse');
|
||||
|
||||
try {
|
||||
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
|
||||
$this->fail('No exception.');
|
||||
} catch (MissingActionException $e) {
|
||||
$this->assertEquals('Action MyPluginController::not_here() could not be found.', $e->getMessage());
|
||||
|
@ -1100,7 +1115,7 @@ class DispatcherTest extends CakeTestCase {
|
|||
|
||||
$url = new CakeRequest('my_plugin/param:value/param2:value2');
|
||||
try {
|
||||
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
|
||||
$this->fail('No exception.');
|
||||
} catch (MissingActionException $e) {
|
||||
$this->assertEquals('Action MyPluginController::param:value() could not be found.', $e->getMessage());
|
||||
|
@ -1122,8 +1137,9 @@ class DispatcherTest extends CakeTestCase {
|
|||
$Dispatcher = new TestDispatcher();
|
||||
|
||||
$url = new CakeRequest('test_dispatch_pages/admin_index/param:value/param2:value2');
|
||||
$response = $this->getMock('CakeResponse');
|
||||
try {
|
||||
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
|
||||
$this->fail('No exception.');
|
||||
} catch (PrivateActionException $e) {
|
||||
$this->assertEquals(
|
||||
|
@ -1148,7 +1164,8 @@ class DispatcherTest extends CakeTestCase {
|
|||
Router::parse('/');
|
||||
|
||||
$url = new CakeRequest('/test_plugin/tests/index');
|
||||
$result = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$response = $this->getMock('CakeResponse');
|
||||
$result = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
$this->assertTrue(class_exists('TestsController'));
|
||||
$this->assertTrue(class_exists('TestPluginAppController'));
|
||||
$this->assertTrue(class_exists('PluginsComponentComponent'));
|
||||
|
@ -1168,17 +1185,18 @@ class DispatcherTest extends CakeTestCase {
|
|||
public function testChangingParamsFromBeforeFilter() {
|
||||
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
||||
$Dispatcher = new TestDispatcher();
|
||||
$response = $this->getMock('CakeResponse');
|
||||
$url = new CakeRequest('some_posts/index/param:value/param2:value2');
|
||||
|
||||
try {
|
||||
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return'=> 1));
|
||||
$this->fail('No exception.');
|
||||
} catch (MissingActionException $e) {
|
||||
$this->assertEquals('Action SomePostsController::view() could not be found.', $e->getMessage());
|
||||
}
|
||||
|
||||
$url = new CakeRequest('some_posts/something_else/param:value/param2:value2');
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
|
||||
|
||||
$expected = 'SomePosts';
|
||||
$this->assertEqual($expected, $controller->name);
|
||||
|
@ -1206,24 +1224,24 @@ class DispatcherTest extends CakeTestCase {
|
|||
CakePlugin::loadAll();
|
||||
|
||||
$Dispatcher = new TestDispatcher();
|
||||
$Dispatcher->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
||||
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
||||
|
||||
try {
|
||||
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/../webroot/css/test_asset.css'));
|
||||
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/../webroot/css/test_asset.css'), $response);
|
||||
$this->fail('No exception');
|
||||
} catch (MissingControllerException $e) {
|
||||
$this->assertEquals('Controller class ThemeController could not be found.', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs'));
|
||||
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs'), $response);
|
||||
$this->fail('No exception');
|
||||
} catch (MissingControllerException $e) {
|
||||
$this->assertEquals('Controller class ThemeController could not be found.', $e->getMessage());
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/flash/theme_test.swf'));
|
||||
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/flash/theme_test.swf'), $response);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'flash' . DS . 'theme_test.swf');
|
||||
|
@ -1231,93 +1249,93 @@ class DispatcherTest extends CakeTestCase {
|
|||
$this->assertEqual('this is just a test to load swf file from the theme.', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs/theme_test.pdf'));
|
||||
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs/theme_test.pdf'), $response);
|
||||
$result = ob_get_clean();
|
||||
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'pdfs' . DS . 'theme_test.pdf');
|
||||
$this->assertEqual($file, $result);
|
||||
$this->assertEqual('this is just a test to load pdf file from the theme.', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/img/test.jpg'));
|
||||
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/img/test.jpg'), $response);
|
||||
$result = ob_get_clean();
|
||||
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg');
|
||||
$this->assertEqual($file, $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('theme/test_theme/css/test_asset.css');
|
||||
$Dispatcher->asset('theme/test_theme/css/test_asset.css', $response);
|
||||
$result = ob_get_clean();
|
||||
$this->assertEqual('this is the test asset css file', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('theme/test_theme/js/theme.js');
|
||||
$Dispatcher->asset('theme/test_theme/js/theme.js', $response);
|
||||
$result = ob_get_clean();
|
||||
$this->assertEqual('root theme js file', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('theme/test_theme/js/one/theme_one.js');
|
||||
$Dispatcher->asset('theme/test_theme/js/one/theme_one.js', $response);
|
||||
$result = ob_get_clean();
|
||||
$this->assertEqual('nested theme js file', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('test_plugin/root.js');
|
||||
$Dispatcher->asset('test_plugin/root.js', $response);
|
||||
$result = ob_get_clean();
|
||||
$expected = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot' . DS . 'root.js');
|
||||
$this->assertEqual($expected, $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->dispatch(new CakeRequest('test_plugin/flash/plugin_test.swf'));
|
||||
$Dispatcher->dispatch(new CakeRequest('test_plugin/flash/plugin_test.swf'), $response);
|
||||
$result = ob_get_clean();
|
||||
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot' . DS . 'flash' . DS . 'plugin_test.swf');
|
||||
$this->assertEqual($file, $result);
|
||||
$this->assertEqual('this is just a test to load swf file from the plugin.', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->dispatch(new CakeRequest('test_plugin/pdfs/plugin_test.pdf'));
|
||||
$Dispatcher->dispatch(new CakeRequest('test_plugin/pdfs/plugin_test.pdf'), $response);
|
||||
$result = ob_get_clean();
|
||||
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot' . DS . 'pdfs' . DS . 'plugin_test.pdf');
|
||||
$this->assertEqual($file, $result);
|
||||
$this->assertEqual('this is just a test to load pdf file from the plugin.', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('test_plugin/js/test_plugin/test.js');
|
||||
$Dispatcher->asset('test_plugin/js/test_plugin/test.js', $response);
|
||||
$result = ob_get_clean();
|
||||
$this->assertEqual('alert("Test App");', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('test_plugin/js/test_plugin/test.js');
|
||||
$Dispatcher->asset('test_plugin/js/test_plugin/test.js', $response);
|
||||
$result = ob_get_clean();
|
||||
$this->assertEqual('alert("Test App");', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('test_plugin/css/test_plugin_asset.css');
|
||||
$Dispatcher->asset('test_plugin/css/test_plugin_asset.css', $response);
|
||||
$result = ob_get_clean();
|
||||
$this->assertEqual('this is the test plugin asset css file', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('test_plugin/img/cake.icon.gif');
|
||||
$Dispatcher->asset('test_plugin/img/cake.icon.gif', $response);
|
||||
$result = ob_get_clean();
|
||||
$file = file_get_contents(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' .DS . 'webroot' . DS . 'img' . DS . 'cake.icon.gif');
|
||||
$this->assertEqual($file, $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('plugin_js/js/plugin_js.js');
|
||||
$Dispatcher->asset('plugin_js/js/plugin_js.js', $response);
|
||||
$result = ob_get_clean();
|
||||
$expected = "alert('win sauce');";
|
||||
$this->assertEqual($expected, $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('plugin_js/js/one/plugin_one.js');
|
||||
$Dispatcher->asset('plugin_js/js/one/plugin_one.js', $response);
|
||||
$result = ob_get_clean();
|
||||
$expected = "alert('plugin one nested js file');";
|
||||
$this->assertEqual($expected, $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('test_plugin/css/unknown.extension');
|
||||
$Dispatcher->asset('test_plugin/css/unknown.extension', $response);
|
||||
$result = ob_get_clean();
|
||||
$this->assertEqual('Testing a file with unknown extension to mime mapping.', $result);
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->asset('test_plugin/css/theme_one.htc');
|
||||
$Dispatcher->asset('test_plugin/css/theme_one.htc', $response);
|
||||
$result = ob_get_clean();
|
||||
$this->assertEqual('htc file', $result);
|
||||
|
||||
|
@ -1334,15 +1352,15 @@ class DispatcherTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testMissingAssetProcessor404() {
|
||||
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
||||
$Dispatcher = new TestDispatcher();
|
||||
$Dispatcher->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
||||
Configure::write('Asset.filter', array(
|
||||
'js' => '',
|
||||
'css' => null
|
||||
));
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue($Dispatcher->asset('ccss/cake.generic.css'));
|
||||
$this->assertTrue($Dispatcher->asset('ccss/cake.generic.css', $response));
|
||||
$result = ob_get_clean();
|
||||
}
|
||||
|
||||
|
@ -1353,22 +1371,22 @@ class DispatcherTest extends CakeTestCase {
|
|||
*/
|
||||
public function testAssetFilterForThemeAndPlugins() {
|
||||
$Dispatcher = new TestDispatcher();
|
||||
$Dispatcher->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
||||
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
||||
Configure::write('Asset.filter', array(
|
||||
'js' => '',
|
||||
'css' => ''
|
||||
));
|
||||
$this->assertTrue($Dispatcher->asset('theme/test_theme/ccss/cake.generic.css'));
|
||||
$this->assertTrue($Dispatcher->asset('theme/test_theme/ccss/cake.generic.css', $response));
|
||||
|
||||
$this->assertTrue($Dispatcher->asset('theme/test_theme/cjs/debug_kit.js'));
|
||||
$this->assertTrue($Dispatcher->asset('theme/test_theme/cjs/debug_kit.js', $response));
|
||||
|
||||
$this->assertTrue($Dispatcher->asset('test_plugin/ccss/cake.generic.css'));
|
||||
$this->assertTrue($Dispatcher->asset('test_plugin/ccss/cake.generic.css', $response));
|
||||
|
||||
$this->assertTrue($Dispatcher->asset('test_plugin/cjs/debug_kit.js'));
|
||||
$this->assertTrue($Dispatcher->asset('test_plugin/cjs/debug_kit.js', $response));
|
||||
|
||||
$this->assertFalse($Dispatcher->asset('css/ccss/debug_kit.css'));
|
||||
$this->assertFalse($Dispatcher->asset('css/ccss/debug_kit.css', $response));
|
||||
|
||||
$this->assertFalse($Dispatcher->asset('js/cjs/debug_kit.js'));
|
||||
$this->assertFalse($Dispatcher->asset('js/cjs/debug_kit.js', $response));
|
||||
}
|
||||
/**
|
||||
* testFullPageCachingDispatch method
|
||||
|
@ -1392,9 +1410,10 @@ class DispatcherTest extends CakeTestCase {
|
|||
|
||||
$dispatcher = new TestDispatcher();
|
||||
$request = new CakeRequest('/');
|
||||
$response = new CakeResponse();
|
||||
|
||||
ob_start();
|
||||
$dispatcher->dispatch($request);
|
||||
$dispatcher->dispatch($request, $response);
|
||||
$out = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
|
@ -1416,7 +1435,7 @@ class DispatcherTest extends CakeTestCase {
|
|||
);
|
||||
|
||||
ob_start();
|
||||
$dispatcher->dispatch($request);
|
||||
$dispatcher->dispatch($request, $response);
|
||||
$out = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
|
@ -1434,7 +1453,7 @@ class DispatcherTest extends CakeTestCase {
|
|||
$request = new CakeRequest('TestCachedPages/index');
|
||||
|
||||
ob_start();
|
||||
$dispatcher->dispatch($request);
|
||||
$dispatcher->dispatch($request, $response);
|
||||
$out = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
|
@ -1452,7 +1471,7 @@ class DispatcherTest extends CakeTestCase {
|
|||
$request = new CakeRequest('TestCachedPages/test_nocache_tags');
|
||||
|
||||
ob_start();
|
||||
$dispatcher->dispatch($request);
|
||||
$dispatcher->dispatch($request, $response);
|
||||
$out = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
|
@ -1470,7 +1489,7 @@ class DispatcherTest extends CakeTestCase {
|
|||
$request = new CakeRequest('test_cached_pages/view/param/param');
|
||||
|
||||
ob_start();
|
||||
$dispatcher->dispatch($request);
|
||||
$dispatcher->dispatch($request, $response);
|
||||
$out = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
|
@ -1488,7 +1507,7 @@ class DispatcherTest extends CakeTestCase {
|
|||
$request = new CakeRequest('test_cached_pages/view/foo:bar/value:goo');
|
||||
|
||||
ob_start();
|
||||
$dispatcher->dispatch($request);
|
||||
$dispatcher->dispatch($request, $response);
|
||||
$out = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
|
|
Loading…
Add table
Reference in a new issue