mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
fixes #5285, requestAction with array params
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7565 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
e632f79c49
commit
1f2ffe2b75
2 changed files with 146 additions and 80 deletions
|
@ -94,7 +94,7 @@ class Object {
|
|||
if (in_array('return', $extra, true)) {
|
||||
$extra = array_merge($extra, array('return' => 0, 'autoRender' => 1));
|
||||
}
|
||||
$params = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
|
||||
$params = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1, 'url' => array()), $extra);
|
||||
$dispatcher = new Dispatcher;
|
||||
return $dispatcher->dispatch($url, $params);
|
||||
}
|
||||
|
|
|
@ -27,75 +27,113 @@
|
|||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
App::import('Core', array('Object', 'Controller', 'Model'));
|
||||
|
||||
if (!class_exists('RequestActionController')) {
|
||||
/**
|
||||
* RequestActionPost class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.object
|
||||
*/
|
||||
class RequestActionPost extends CakeTestModel {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'ControllerPost'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'RequestActionPost';
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'posts'
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'posts';
|
||||
}
|
||||
/**
|
||||
* RequestActionController class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class RequestActionController extends Controller {
|
||||
class RequestActionController extends Controller {
|
||||
/**
|
||||
* uses property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uses = array();
|
||||
* uses property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uses = array('RequestActionPost');
|
||||
/**
|
||||
* test_request_action method
|
||||
*
|
||||
* test_request_action method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function test_request_action() {
|
||||
return 'This is a test';
|
||||
}
|
||||
/**
|
||||
* another_ra_test method
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param mixed $other
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function another_ra_test($id, $other) {
|
||||
return $id + $other;
|
||||
}
|
||||
/**
|
||||
* normal_request_action method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function test_request_action() {
|
||||
return 'This is a test';
|
||||
}
|
||||
function normal_request_action() {
|
||||
return 'Hello World';
|
||||
}
|
||||
/**
|
||||
* another_ra_test method
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param mixed $other
|
||||
* paginate_request_action method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function another_ra_test($id, $other) {
|
||||
return $id + $other;
|
||||
}
|
||||
function paginate_request_action() {
|
||||
$data = $this->paginate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* TestObject class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class TestObject extends Object {
|
||||
/**
|
||||
* firstName property
|
||||
*
|
||||
*
|
||||
* @var string 'Joel'
|
||||
* @access public
|
||||
*/
|
||||
var $firstName = 'Joel';
|
||||
/**
|
||||
* lastName property
|
||||
*
|
||||
*
|
||||
* @var string 'Moss'
|
||||
* @access public
|
||||
*/
|
||||
var $lastName = 'Moss';
|
||||
/**
|
||||
* methodCalls property
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $methodCalls = array();
|
||||
/**
|
||||
* emptyMethod method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -104,8 +142,8 @@ class TestObject extends Object {
|
|||
}
|
||||
/**
|
||||
* oneParamMethod method
|
||||
*
|
||||
* @param mixed $param
|
||||
*
|
||||
* @param mixed $param
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -114,9 +152,9 @@ class TestObject extends Object {
|
|||
}
|
||||
/**
|
||||
* twoParamMethod method
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param2
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param2
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -125,10 +163,10 @@ class TestObject extends Object {
|
|||
}
|
||||
/**
|
||||
* threeParamMethod method
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param2
|
||||
* @param mixed $param3
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param2
|
||||
* @param mixed $param3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -137,11 +175,11 @@ class TestObject extends Object {
|
|||
}
|
||||
/**
|
||||
* fourParamMethod method
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param2
|
||||
* @param mixed $param3
|
||||
* @param mixed $param4
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param2
|
||||
* @param mixed $param3
|
||||
* @param mixed $param4
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -150,12 +188,12 @@ class TestObject extends Object {
|
|||
}
|
||||
/**
|
||||
* fiveParamMethod method
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param2
|
||||
* @param mixed $param3
|
||||
* @param mixed $param4
|
||||
* @param mixed $param5
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param2
|
||||
* @param mixed $param3
|
||||
* @param mixed $param4
|
||||
* @param mixed $param5
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -164,14 +202,14 @@ class TestObject extends Object {
|
|||
}
|
||||
/**
|
||||
* crazyMethod method
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param2
|
||||
* @param mixed $param3
|
||||
* @param mixed $param4
|
||||
* @param mixed $param5
|
||||
* @param mixed $param6
|
||||
* @param mixed $param7
|
||||
*
|
||||
* @param mixed $param
|
||||
* @param mixed $param2
|
||||
* @param mixed $param3
|
||||
* @param mixed $param4
|
||||
* @param mixed $param5
|
||||
* @param mixed $param6
|
||||
* @param mixed $param7
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -180,15 +218,15 @@ class TestObject extends Object {
|
|||
}
|
||||
/**
|
||||
* methodWithOptionalParam method
|
||||
*
|
||||
* @param mixed $param
|
||||
*
|
||||
* @param mixed $param
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function methodWithOptionalParam($param = null) {
|
||||
$this->methodCalls[] = array('methodWithOptionalParam' => array($param));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* testPersist
|
||||
*
|
||||
|
@ -219,9 +257,15 @@ class ObjectTestModel extends CakeTestModel {
|
|||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class ObjectTest extends CakeTestCase {
|
||||
/**
|
||||
* fixtures
|
||||
*
|
||||
* @var string
|
||||
**/
|
||||
var $fixtures = array('core.post');
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -230,7 +274,7 @@ class ObjectTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testLog method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -259,7 +303,7 @@ class ObjectTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testSet method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -279,41 +323,49 @@ class ObjectTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testPersist method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testPersist() {
|
||||
@unlink(CACHE . 'persistent' . DS . 'testmodel.php');
|
||||
ClassRegistry::flush();
|
||||
|
||||
$cacheDisable = Configure::read('Cache.disable');
|
||||
Configure::write('Cache.disable', false);
|
||||
@unlink(CACHE . 'persistent' . DS . 'testmodel.php');
|
||||
$test = new stdClass;
|
||||
$this->assertFalse($this->object->testPersist('TestModel', null, $test));
|
||||
$this->assertFalse($this->object->testPersist('TestModel', true, $test));
|
||||
$this->assertTrue($this->object->testPersist('TestModel', null, $test));
|
||||
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'testmodel.php'));
|
||||
$this->assertTrue($this->object->testPersist('TestModel', true, $test));
|
||||
$this->assertNull($this->object->TestModel);
|
||||
$this->assertEqual($this->object->TestModel, $test);
|
||||
|
||||
@unlink(CACHE . 'persistent' . DS . 'testmodel.php');
|
||||
|
||||
|
||||
$model =& new ObjectTestModel();
|
||||
$expected = ClassRegistry::keys();
|
||||
|
||||
ClassRegistry::flush();
|
||||
$data = array('object_test_model' => $model);
|
||||
$this->assertFalse($this->object->testPersist('ObjectTestModel', true, $data));
|
||||
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'objecttestmodel.php'));
|
||||
|
||||
|
||||
$this->object->testPersist('ObjectTestModel', true, $model, 'registry');
|
||||
|
||||
$result = ClassRegistry::keys();
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$newModel = ClassRegistry::getObject('object_test_model');
|
||||
$this->assertEqual('ObjectTestModel', $newModel->name);
|
||||
|
||||
|
||||
@unlink(CACHE . 'persistent' . DS . 'objecttestmodel.php');
|
||||
|
||||
Configure::write('Cache.disable', $cacheDisable);
|
||||
}
|
||||
/**
|
||||
* testToString method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -323,7 +375,7 @@ class ObjectTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testMethodDispatching method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -366,11 +418,11 @@ class ObjectTest extends CakeTestCase {
|
|||
$this->object->dispatchMethod('threeParamMethod', array(true, false, null));
|
||||
$expected[] = array('threeParamMethod' => array(true, false, null));
|
||||
$this->assertIdentical($this->object->methodCalls, $expected);
|
||||
|
||||
|
||||
$this->object->dispatchMethod('fourParamMethod', array(1, 2, 3, 4));
|
||||
$expected[] = array('fourParamMethod' => array(1, 2, 3, 4));
|
||||
$this->assertIdentical($this->object->methodCalls, $expected);
|
||||
|
||||
|
||||
$this->object->dispatchMethod('fiveParamMethod', array(1, 2, 3, 4, 5));
|
||||
$expected[] = array('fiveParamMethod' => array(1, 2, 3, 4, 5));
|
||||
$this->assertIdentical($this->object->methodCalls, $expected);
|
||||
|
@ -389,14 +441,14 @@ class ObjectTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testRequestAction method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testRequestAction() {
|
||||
$result = $this->object->requestAction('');
|
||||
$this->assertFalse($result);
|
||||
|
||||
|
||||
$result = $this->object->requestAction('/request_action/test_request_action');
|
||||
$expected = 'This is a test';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
@ -412,7 +464,7 @@ class ObjectTest extends CakeTestCase {
|
|||
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'another_ra_test'), array('pass' => array('5', '7')));
|
||||
$expected = 12;
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
||||
$_back = array(
|
||||
'controller' => Configure::read('controllerPaths'),
|
||||
'view' => Configure::read('viewPaths'),
|
||||
|
@ -457,12 +509,26 @@ class ObjectTest extends CakeTestCase {
|
|||
$result = $this->object->requestAction(array('controller' => 'tests', 'action' => 'some_method', 'plugin' => 'test_plugin'));
|
||||
$expected = 25;
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
||||
$result = $this->object->requestAction('/request_action/paginate_request_action');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->object->requestAction('/request_action/normal_request_action');
|
||||
$expected = 'Hello World';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->object->requestAction(array('controller'=>'request_action', 'action'=>'normal_request_action'));
|
||||
$expected = 'Hello World';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->object->requestAction(array('controller'=>'request_action', 'action'=>'paginate_request_action'));
|
||||
$this->assertTrue($result);
|
||||
|
||||
Configure::write('controllerPaths', $_back['controller']);
|
||||
Configure::write('viewPaths', $_back['view']);
|
||||
Configure::write('pluginPaths', $_back['plugin']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* testCakeError
|
||||
*
|
||||
|
@ -473,7 +539,7 @@ class ObjectTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue