Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,21 +2,22 @@
/**
* DispatcherTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Routing
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Dispatcher', 'Routing');
App::uses('DispatcherFilter', 'Routing');
if (!class_exists('AppController', false)) {
require_once CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS . 'AppController.php';
@ -56,12 +57,11 @@ class TestDispatcher extends Dispatcher {
*
* @param Controller $controller
* @param CakeRequest $request
* @param CakeResponse $response
* @return void
* @return CakeResponse
*/
protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) {
protected function _invoke(Controller $controller, CakeRequest $request) {
$this->controller = $controller;
return parent::_invoke($controller, $request, $response);
return parent::_invoke($controller, $request);
}
/**
@ -95,12 +95,18 @@ class TestDispatcher extends Dispatcher {
class MyPluginAppController extends AppController {
}
/**
* Abstract Class DispatcherTestAbstractController
*/
abstract class DispatcherTestAbstractController extends Controller {
abstract public function index();
}
/**
* Interface DispatcherTestInterfaceController
*/
interface DispatcherTestInterfaceController {
public function index();
@ -114,13 +120,6 @@ interface DispatcherTestInterfaceController {
*/
class MyPluginController extends MyPluginAppController {
/**
* name property
*
* @var string 'MyPlugin'
*/
public $name = 'MyPlugin';
/**
* uses property
*
@ -165,13 +164,6 @@ class MyPluginController extends MyPluginAppController {
*/
class SomePagesController extends AppController {
/**
* name property
*
* @var string 'SomePages'
*/
public $name = 'SomePages';
/**
* uses property
*
@ -207,6 +199,16 @@ class SomePagesController extends AppController {
return new CakeResponse(array('body' => 'new response'));
}
/**
* Test file sending
*
* @return CakeResponse
*/
public function sendfile() {
$this->response->file(CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS . 'test_asset.css');
return $this->response;
}
}
/**
@ -216,13 +218,6 @@ class SomePagesController extends AppController {
*/
class OtherPagesController extends MyPluginAppController {
/**
* name property
*
* @var string 'OtherPages'
*/
public $name = 'OtherPages';
/**
* uses property
*
@ -258,13 +253,6 @@ class OtherPagesController extends MyPluginAppController {
*/
class TestDispatchPagesController extends AppController {
/**
* name property
*
* @var string 'TestDispatchPages'
*/
public $name = 'TestDispatchPages';
/**
* uses property
*
@ -307,13 +295,6 @@ class ArticlesTestAppController extends AppController {
*/
class ArticlesTestController extends ArticlesTestAppController {
/**
* name property
*
* @var string 'ArticlesTest'
*/
public $name = 'ArticlesTest';
/**
* uses property
*
@ -348,13 +329,6 @@ class ArticlesTestController extends ArticlesTestAppController {
*/
class SomePostsController extends AppController {
/**
* name property
*
* @var string 'SomePosts'
*/
public $name = 'SomePosts';
/**
* uses property
*
@ -365,7 +339,7 @@ class SomePostsController extends AppController {
/**
* autoRender property
*
* @var bool false
* @var bool
*/
public $autoRender = false;
@ -375,7 +349,7 @@ class SomePostsController extends AppController {
* @return void
*/
public function beforeFilter() {
if ($this->params['action'] == 'index') {
if ($this->params['action'] === 'index') {
$this->params['action'] = 'view';
} else {
$this->params['action'] = 'change';
@ -410,13 +384,6 @@ class SomePostsController extends AppController {
*/
class TestCachedPagesController extends Controller {
/**
* name property
*
* @var string 'TestCachedPages'
*/
public $name = 'TestCachedPages';
/**
* uses property
*
@ -452,7 +419,7 @@ class TestCachedPagesController extends Controller {
/**
* viewPath property
*
* @var string 'posts'
* @var string
*/
public $viewPath = 'Posts';
@ -495,6 +462,8 @@ class TestCachedPagesController extends Controller {
/**
* Test cached views with themes.
*
* @return void
*/
public function themed() {
$this->cacheAction = 10;
@ -511,13 +480,6 @@ class TestCachedPagesController extends Controller {
*/
class TimesheetsController extends Controller {
/**
* name property
*
* @var string 'Timesheets'
*/
public $name = 'Timesheets';
/**
* uses property
*
@ -536,6 +498,39 @@ class TimesheetsController extends Controller {
}
/**
* TestFilterDispatcher class
*
* @package Cake.Test.Case.Routing
*/
class TestFilterDispatcher extends DispatcherFilter {
public $priority = 10;
/**
* TestFilterDispatcher::beforeDispatch()
*
* @param mixed $event
* @return CakeResponse|bool
*/
public function beforeDispatch(CakeEvent $event) {
$event->stopPropagation();
$response = $event->data['request'];
$response->addParams(array('settings' => $this->settings));
return null;
}
/**
* TestFilterDispatcher::afterDispatch()
*
* @param mixed $event
* @return mixed boolean to stop the event dispatching or null to continue
*/
public function afterDispatch(CakeEvent $event) {
}
}
/**
* DispatcherTest class
*
@ -549,6 +544,7 @@ class DispatcherTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
$this->_get = $_GET;
$_GET = array();
$this->_post = $_POST;
@ -576,6 +572,7 @@ class DispatcherTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
$_GET = $this->_get;
$_POST = $this->_post;
$_FILES = $this->_files;
@ -592,6 +589,7 @@ class DispatcherTest extends CakeTestCase {
* testParseParamsWithoutZerosAndEmptyPost method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $request)
*/
public function testParseParamsWithoutZerosAndEmptyPost() {
$Dispatcher = new Dispatcher();
@ -610,6 +608,7 @@ class DispatcherTest extends CakeTestCase {
* testParseParamsReturnsPostedData method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $request)
*/
public function testParseParamsReturnsPostedData() {
$_POST['testdata'] = "My Posted Content";
@ -617,7 +616,7 @@ class DispatcherTest extends CakeTestCase {
$request = new CakeRequest("/");
$event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $request));
$Dispatcher->parseParams($event);
$test = $Dispatcher->parseParams($event);
$Dispatcher->parseParams($event);
$this->assertEquals("My Posted Content", $request['data']['testdata']);
}
@ -625,6 +624,7 @@ class DispatcherTest extends CakeTestCase {
* testParseParamsWithSingleZero method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $test)
*/
public function testParseParamsWithSingleZero() {
$Dispatcher = new Dispatcher();
@ -643,6 +643,7 @@ class DispatcherTest extends CakeTestCase {
* testParseParamsWithManySingleZeros method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $test)
*/
public function testParseParamsWithManySingleZeros() {
$Dispatcher = new Dispatcher();
@ -662,6 +663,7 @@ class DispatcherTest extends CakeTestCase {
* testParseParamsWithManyZerosInEachSectionOfUrl method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $test)
*/
public function testParseParamsWithManyZerosInEachSectionOfUrl() {
$Dispatcher = new Dispatcher();
@ -681,6 +683,7 @@ class DispatcherTest extends CakeTestCase {
* testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $test)
*/
public function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
$Dispatcher = new Dispatcher();
@ -700,6 +703,8 @@ class DispatcherTest extends CakeTestCase {
* testQueryStringOnRoot method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $request)
* @triggers DispatcherTest $Dispatcher, array('request' => $request)
*/
public function testQueryStringOnRoot() {
Router::reload();
@ -865,6 +870,40 @@ class DispatcherTest extends CakeTestCase {
$this->assertEquals('new response', $result);
}
/**
* testDispatchActionSendsFile
*
* @return void
*/
public function testDispatchActionSendsFile() {
Router::connect('/:controller/:action');
$Dispatcher = new Dispatcher();
$request = new CakeRequest('some_pages/sendfile');
$response = $this->getMock('CakeResponse', array(
'header',
'type',
'download',
'_sendHeader',
'_setContentType',
'_isActive',
'_clearBuffer',
'_flushBuffer'
));
$response->expects($this->never())
->method('body');
$response->expects($this->exactly(1))
->method('_isActive')
->will($this->returnValue(true));
ob_start();
$Dispatcher->dispatch($request, $response);
$result = ob_get_clean();
$this->assertEquals("/* this is the test asset css file */\n", $result);
}
/**
* testAdminDispatch method
*
@ -874,7 +913,7 @@ class DispatcherTest extends CakeTestCase {
$_POST = array();
$Dispatcher = new TestDispatcher();
Configure::write('Routing.prefixes', array('admin'));
Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php');
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');
@ -897,6 +936,7 @@ class DispatcherTest extends CakeTestCase {
* testPluginDispatch method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $url)
*/
public function testPluginDispatch() {
$_POST = array();
@ -1083,7 +1123,7 @@ class DispatcherTest extends CakeTestCase {
}
/**
* test plugin shortcut urls with controllers that need to be loaded,
* test plugin shortcut URLs with controllers that need to be loaded,
* the above test uses a controller that has already been included.
*
* @return void
@ -1195,7 +1235,7 @@ class DispatcherTest extends CakeTestCase {
*
* @return void
*/
public function testDispatcherFilterSuscriber() {
public function testDispatcherFilterSubscriber() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
@ -1229,6 +1269,23 @@ class DispatcherTest extends CakeTestCase {
$this->assertNull($dispatcher->controller);
}
/**
* Tests that it is possible to attach filter with config classes to the dispatch cycle
*
* @return void
*/
public function testDispatcherFilterSettings() {
Configure::write('Dispatcher.filters', array(
'TestFilterDispatcher' => array('service' => 'google.com')
));
$Dispatcher = new Dispatcher();
$url = new CakeRequest('some_pages/index');
$response = $this->getMock('CakeResponse');
$Dispatcher->dispatch($url, $response, array('return' => 1));
$settings = $url->param('settings');
$this->assertEquals($settings, array('service' => 'google.com'));
}
/**
* Tests that attaching an inexistent class as filter will throw an exception
*
@ -1280,6 +1337,16 @@ class DispatcherTest extends CakeTestCase {
$dispatcher->dispatch($request, $response);
$this->assertEquals('Dispatcher.afterDispatch', $request->params['eventName']);
$dispatcher = new TestDispatcher();
Configure::write('Dispatcher.filters', array(
'filterTest' => array('callable' => array($dispatcher, 'filterTest'), 'on' => 'before')
));
$request = new CakeRequest('/');
$response = $this->getMock('CakeResponse', array('send'));
$dispatcher->dispatch($request, $response);
$this->assertEquals('Dispatcher.beforeDispatch', $request->params['eventName']);
// Test that it is possible to skip the route connection process
$dispatcher = new TestDispatcher();
Configure::write('Dispatcher.filters', array(
@ -1582,6 +1649,11 @@ class DispatcherTest extends CakeTestCase {
* testHttpMethodOverrides method
*
* @return void
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
*/
public function testHttpMethodOverrides() {
Router::reload();
@ -1665,7 +1737,7 @@ class DispatcherTest extends CakeTestCase {
*/
protected function _cachePath($here) {
$path = $here;
if ($here == '/') {
if ($here === '/') {
$path = 'home';
}
$path = strtolower(Inflector::slug($path));