mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-10-30 07:43:59 +01:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* ControllerTestCase 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.TestSuite
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @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');
|
||||
|
|
@ -42,13 +41,15 @@ class ControllerTestDispatcher extends Dispatcher {
|
|||
/**
|
||||
* Use custom routes during tests
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $loadRoutes = true;
|
||||
|
||||
/**
|
||||
* Returns the test controller
|
||||
*
|
||||
* @param CakeRequest $request The request instance.
|
||||
* @param CakeResponse $response The response instance.
|
||||
* @return Controller
|
||||
*/
|
||||
protected function _getController($request, $response) {
|
||||
|
|
@ -58,7 +59,7 @@ class ControllerTestDispatcher extends Dispatcher {
|
|||
$this->testController->helpers = array_merge(array('InterceptContent'), $this->testController->helpers);
|
||||
$this->testController->setRequest($request);
|
||||
$this->testController->response = $this->response;
|
||||
foreach ($this->testController->Components->attached() as $component) {
|
||||
foreach ($this->testController->Components->loaded() as $component) {
|
||||
$object = $this->testController->Components->{$component};
|
||||
if (isset($object->response)) {
|
||||
$object->response = $response;
|
||||
|
|
@ -95,6 +96,7 @@ class InterceptContentHelper extends Helper {
|
|||
* Intercepts and stores the contents of the view before the layout is rendered
|
||||
*
|
||||
* @param string $viewFile The view file
|
||||
* @return void
|
||||
*/
|
||||
public function afterRender($viewFile) {
|
||||
$this->_View->assign('__view_no_layout__', $this->_View->fetch('content'));
|
||||
|
|
@ -107,6 +109,7 @@ class InterceptContentHelper extends Helper {
|
|||
* ControllerTestCase class
|
||||
*
|
||||
* @package Cake.TestSuite
|
||||
* @method mixed testAction() testAction($url, $options = array()) Lets you do functional tests of a controller action.
|
||||
*/
|
||||
abstract class ControllerTestCase extends CakeTestCase {
|
||||
|
||||
|
|
@ -120,14 +123,14 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
/**
|
||||
* Automatically mock controllers that aren't mocked
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $autoMock = true;
|
||||
|
||||
/**
|
||||
* Use custom routes during tests
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $loadRoutes = true;
|
||||
|
||||
|
|
@ -171,21 +174,28 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
* Once a test has been run on a controller it should be rebuilt
|
||||
* to clean up properties.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_dirtyController = false;
|
||||
|
||||
/**
|
||||
* The class name to use for mocking the response object.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_responseClass = 'CakeResponse';
|
||||
|
||||
/**
|
||||
* Used to enable calling ControllerTestCase::testAction() without the testing
|
||||
* framework thinking that it's a test case
|
||||
*
|
||||
* @param string $name The name of the function
|
||||
* @param array $arguments Array of arguments
|
||||
* @return the return of _testAction
|
||||
* @return mixed The return of _testAction.
|
||||
* @throws BadMethodCallException when you call methods that don't exist.
|
||||
*/
|
||||
public function __call($name, $arguments) {
|
||||
if ($name == 'testAction') {
|
||||
if ($name === 'testAction') {
|
||||
return call_user_func_array(array($this, '_testAction'), $arguments);
|
||||
}
|
||||
throw new BadMethodCallException("Method '{$name}' does not exist.");
|
||||
|
|
@ -196,35 +206,41 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `data` Will be used as the request data. If the `method` is GET,
|
||||
* data will be used a GET params. If the `method` is POST, it will be used
|
||||
* - `data` Will be used as the request data. If the `method` is GET,
|
||||
* data will be used a GET params. If the `method` is POST, it will be used
|
||||
* as POST data. By setting `$options['data']` to a string, you can simulate XML or JSON
|
||||
* payloads to your controllers allowing you to test REST webservices.
|
||||
* - `method` POST or GET. Defaults to POST.
|
||||
* - `return` Specify the return type you want. Choose from:
|
||||
* - `return` Specify the return type you want. Choose from:
|
||||
* - `vars` Get the set view variables.
|
||||
* - `view` Get the rendered view, without a layout.
|
||||
* - `contents` Get the rendered view including the layout.
|
||||
* - `result` Get the return value of the controller action. Useful
|
||||
* - `result` Get the return value of the controller action. Useful
|
||||
* for testing requestAction methods.
|
||||
*
|
||||
* @param string $url The url to test
|
||||
* @param string|array $url The URL to test.
|
||||
* @param array $options See options
|
||||
* @return mixed The specified return type.
|
||||
* @triggers ControllerTestCase $Dispatch, array('request' => $request)
|
||||
*/
|
||||
protected function _testAction($url = '', $options = array()) {
|
||||
protected function _testAction($url, $options = array()) {
|
||||
$this->vars = $this->result = $this->view = $this->contents = $this->headers = null;
|
||||
|
||||
$options = array_merge(array(
|
||||
$options += array(
|
||||
'data' => array(),
|
||||
'method' => 'POST',
|
||||
'return' => 'result'
|
||||
), $options);
|
||||
);
|
||||
|
||||
if (is_array($url)) {
|
||||
$url = Router::url($url);
|
||||
}
|
||||
|
||||
$restore = array('get' => $_GET, 'post' => $_POST);
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = strtoupper($options['method']);
|
||||
if (is_array($options['data'])) {
|
||||
if (strtoupper($options['method']) == 'GET') {
|
||||
if (strtoupper($options['method']) === 'GET') {
|
||||
$_GET = $options['data'];
|
||||
$_POST = array();
|
||||
} else {
|
||||
|
|
@ -250,7 +266,7 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
$Dispatch->parseParams(new CakeEvent('ControllerTestCase', $Dispatch, array('request' => $request)));
|
||||
if (!isset($request->params['controller']) && Router::currentRoute()) {
|
||||
$this->headers = Router::currentRoute()->response->header();
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if ($this->_dirtyController) {
|
||||
$this->controller = null;
|
||||
|
|
@ -261,14 +277,20 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
$this->generate($plugin . Inflector::camelize($request->params['controller']));
|
||||
}
|
||||
$params = array();
|
||||
if ($options['return'] == 'result') {
|
||||
if ($options['return'] === 'result') {
|
||||
$params['return'] = 1;
|
||||
$params['bare'] = 1;
|
||||
$params['requested'] = 1;
|
||||
}
|
||||
$Dispatch->testController = $this->controller;
|
||||
$Dispatch->response = $this->getMock('CakeResponse', array('send'));
|
||||
$Dispatch->response = $this->getMock($this->_responseClass, array('send', '_clearBuffer'));
|
||||
$this->result = $Dispatch->dispatch($request, $Dispatch->response, $params);
|
||||
|
||||
// Clear out any stored requests.
|
||||
while (Router::getRequest()) {
|
||||
Router::popRequest();
|
||||
}
|
||||
|
||||
$this->controller = $Dispatch->testController;
|
||||
$this->vars = $this->controller->viewVars;
|
||||
$this->contents = $this->controller->response->body();
|
||||
|
|
@ -292,7 +314,7 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
* ### Mocks:
|
||||
*
|
||||
* - `methods` Methods to mock on the controller. `_stop()` is mocked by default
|
||||
* - `models` Models to mock. Models are added to the ClassRegistry so they any
|
||||
* - `models` Models to mock. Models are added to the ClassRegistry so any
|
||||
* time they are instantiated the mock will be created. Pass as key value pairs
|
||||
* with the value being specific methods on the model to mock. If `true` or
|
||||
* no value is passed, the entire model will be mocked.
|
||||
|
|
@ -327,11 +349,12 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
), (array)$mocks);
|
||||
|
||||
list($plugin, $name) = pluginSplit($controller);
|
||||
$_controller = $this->getMock($name . 'Controller', $mocks['methods'], array(), '', false);
|
||||
$_controller->name = $name;
|
||||
$controllerObj = $this->getMock($name . 'Controller', $mocks['methods'], array(), '', false);
|
||||
$controllerObj->name = $name;
|
||||
$request = $this->getMock('CakeRequest');
|
||||
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
||||
$_controller->__construct($request, $response);
|
||||
$response = $this->getMock($this->_responseClass, array('_sendHeader'));
|
||||
$controllerObj->__construct($request, $response);
|
||||
$controllerObj->Components->setController($controllerObj);
|
||||
|
||||
$config = ClassRegistry::config('Model');
|
||||
foreach ($mocks['models'] as $model => $methods) {
|
||||
|
|
@ -342,12 +365,7 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
if ($methods === true) {
|
||||
$methods = array();
|
||||
}
|
||||
ClassRegistry::init($model);
|
||||
list($plugin, $name) = pluginSplit($model);
|
||||
$config = array_merge((array)$config, array('name' => $model));
|
||||
$_model = $this->getMock($name, $methods, array($config));
|
||||
ClassRegistry::removeObject($name);
|
||||
ClassRegistry::addObject($name, $_model);
|
||||
$this->getMockForModel($model, $methods, $config);
|
||||
}
|
||||
|
||||
foreach ($mocks['components'] as $component => $methods) {
|
||||
|
|
@ -366,14 +384,16 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
'class' => $componentClass
|
||||
));
|
||||
}
|
||||
$_component = $this->getMock($componentClass, $methods, array(), '', false);
|
||||
$_controller->Components->set($name, $_component);
|
||||
$config = isset($controllerObj->components[$component]) ? $controllerObj->components[$component] : array();
|
||||
$componentObj = $this->getMock($componentClass, $methods, array($controllerObj->Components, $config));
|
||||
$controllerObj->Components->set($name, $componentObj);
|
||||
$controllerObj->Components->enable($name);
|
||||
}
|
||||
|
||||
$_controller->constructClasses();
|
||||
$controllerObj->constructClasses();
|
||||
$this->_dirtyController = false;
|
||||
|
||||
$this->controller = $_controller;
|
||||
$this->controller = $controllerObj;
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue