mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Removing $request->params['form'], all POST data is available at $request->data, there is no point for it to be in two
places. Updating tests as well.
This commit is contained in:
parent
47176bffc5
commit
0be0b0ede0
4 changed files with 25 additions and 21 deletions
|
@ -133,27 +133,26 @@ class CakeRequest implements ArrayAccess {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* process the post data and set what is there into the object.
|
* process the post data and set what is there into the object.
|
||||||
* The raw post is available at $this->params['form'], while a lightly processed
|
* processed data is available at $this->data
|
||||||
* version is available at $this->data
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function _processPost() {
|
protected function _processPost() {
|
||||||
$this->params['form'] = $_POST;
|
$this->data = $_POST;
|
||||||
if (ini_get('magic_quotes_gpc') === '1') {
|
if (ini_get('magic_quotes_gpc') === '1') {
|
||||||
$this->params['form'] = stripslashes_deep($this->params['form']);
|
$this->data = stripslashes_deep($this->data);
|
||||||
}
|
}
|
||||||
if (env('HTTP_X_HTTP_METHOD_OVERRIDE')) {
|
if (env('HTTP_X_HTTP_METHOD_OVERRIDE')) {
|
||||||
$this->params['form']['_method'] = env('HTTP_X_HTTP_METHOD_OVERRIDE');
|
$this->data['_method'] = env('HTTP_X_HTTP_METHOD_OVERRIDE');
|
||||||
}
|
}
|
||||||
if (isset($this->params['form']['_method'])) {
|
if (isset($this->data['_method'])) {
|
||||||
if (!empty($_SERVER)) {
|
if (!empty($_SERVER)) {
|
||||||
$_SERVER['REQUEST_METHOD'] = $this->params['form']['_method'];
|
$_SERVER['REQUEST_METHOD'] = $this->data['_method'];
|
||||||
} else {
|
} else {
|
||||||
$_ENV['REQUEST_METHOD'] = $this->params['form']['_method'];
|
$_ENV['REQUEST_METHOD'] = $this->data['_method'];
|
||||||
}
|
}
|
||||||
|
unset($this->data['_method']);
|
||||||
}
|
}
|
||||||
$this->data = $this->params['form'];
|
|
||||||
if (isset($this->data['data'])) {
|
if (isset($this->data['data'])) {
|
||||||
$data = $this->data['data'];
|
$data = $this->data['data'];
|
||||||
unset($this->data['data']);
|
unset($this->data['data']);
|
||||||
|
|
|
@ -161,7 +161,6 @@ class CakeRequestTestCase extends CakeTestCase {
|
||||||
|
|
||||||
$_POST = array('one' => 1, 'two' => 'three');
|
$_POST = array('one' => 1, 'two' => 'three');
|
||||||
$request = new CakeRequest('some/path');
|
$request = new CakeRequest('some/path');
|
||||||
$this->assertEquals($_POST, $request->params['form']);
|
|
||||||
$this->assertEquals($_POST, $request->data);
|
$this->assertEquals($_POST, $request->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -585,8 +585,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$Dispatcher = new Dispatcher();
|
$Dispatcher = new Dispatcher();
|
||||||
|
|
||||||
$test = $Dispatcher->parseParams(new CakeRequest("/"));
|
$test = $Dispatcher->parseParams(new CakeRequest("/"));
|
||||||
$this->assertFalse(empty($test['form']), "Parsed URL not returning post data");
|
$this->assertEquals($test['data']['testdata'], "My Posted Content");
|
||||||
$this->assertEquals($test['form']['testdata'], "My Posted Content");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -868,7 +867,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'pass' => array('home'),
|
'pass' => array('home'),
|
||||||
'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
|
'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
|
||||||
'controller'=> 'some_pages', 'action'=> 'display', 'form'=> array(),
|
'controller'=> 'some_pages', 'action'=> 'display'
|
||||||
);
|
);
|
||||||
foreach ($expected as $key => $value) {
|
foreach ($expected as $key => $value) {
|
||||||
$this->assertEqual($result[$key], $value, 'Value mismatch ' . $key . ' %');
|
$this->assertEqual($result[$key], $value, 'Value mismatch ' . $key . ' %');
|
||||||
|
@ -1000,7 +999,6 @@ class DispatcherTest extends CakeTestCase {
|
||||||
'action' => 'admin_index',
|
'action' => 'admin_index',
|
||||||
'prefix' => 'admin',
|
'prefix' => 'admin',
|
||||||
'admin' => true,
|
'admin' => true,
|
||||||
'form' => array(),
|
|
||||||
'return' => 1
|
'return' => 1
|
||||||
);
|
);
|
||||||
foreach ($expected as $key => $value) {
|
foreach ($expected as $key => $value) {
|
||||||
|
@ -1524,7 +1522,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$dispatcher = new Dispatcher();
|
$dispatcher = new Dispatcher();
|
||||||
|
|
||||||
$result = $dispatcher->parseParams(new CakeRequest('/posts'));
|
$result = $dispatcher->parseParams(new CakeRequest('/posts'));
|
||||||
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'form' => array());
|
$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST');
|
||||||
foreach ($expected as $key => $value) {
|
foreach ($expected as $key => $value) {
|
||||||
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
||||||
}
|
}
|
||||||
|
@ -1533,7 +1531,15 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
|
$_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
|
||||||
|
|
||||||
$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
|
$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
|
||||||
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array());
|
$expected = array(
|
||||||
|
'pass' => array('5'),
|
||||||
|
'named' => array(),
|
||||||
|
'id' => '5',
|
||||||
|
'plugin' => null,
|
||||||
|
'controller' => 'posts',
|
||||||
|
'action' => 'edit',
|
||||||
|
'[method]' => 'PUT'
|
||||||
|
);
|
||||||
foreach ($expected as $key => $value) {
|
foreach ($expected as $key => $value) {
|
||||||
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
||||||
}
|
}
|
||||||
|
@ -1542,7 +1548,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
|
|
||||||
$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
|
$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
|
||||||
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'form' => array());
|
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET');
|
||||||
foreach ($expected as $key => $value) {
|
foreach ($expected as $key => $value) {
|
||||||
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
||||||
}
|
}
|
||||||
|
@ -1550,7 +1556,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$_POST['_method'] = 'PUT';
|
$_POST['_method'] = 'PUT';
|
||||||
|
|
||||||
$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
|
$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
|
||||||
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'form' => array());
|
$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT');
|
||||||
foreach ($expected as $key => $value) {
|
foreach ($expected as $key => $value) {
|
||||||
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
||||||
}
|
}
|
||||||
|
@ -1563,7 +1569,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$result = $dispatcher->parseParams(new CakeRequest('/posts'));
|
$result = $dispatcher->parseParams(new CakeRequest('/posts'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add',
|
'pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add',
|
||||||
'[method]' => 'POST', 'form' => array('extra' => 'data'), 'data' => array('Post' => array('title' => 'New Post')),
|
'[method]' => 'POST', 'data' => array('extra' => 'data', 'Post' => array('title' => 'New Post')),
|
||||||
);
|
);
|
||||||
foreach ($expected as $key => $value) {
|
foreach ($expected as $key => $value) {
|
||||||
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
$this->assertEqual($result[$key], $value, 'Value mismatch for ' . $key . ' %s');
|
||||||
|
|
|
@ -2164,7 +2164,7 @@ class RouterTest extends CakeTestCase {
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'plugin' => null, 'controller' => false, 'action' => false,
|
'plugin' => null, 'controller' => false, 'action' => false,
|
||||||
'param1' => '1', 'param2' => '2', 'form' => array()
|
'param1' => '1', 'param2' => '2'
|
||||||
);
|
);
|
||||||
$this->assertEqual(Router::getParams(), $expected);
|
$this->assertEqual(Router::getParams(), $expected);
|
||||||
$this->assertEqual(Router::getParam('controller'), false);
|
$this->assertEqual(Router::getParam('controller'), false);
|
||||||
|
@ -2175,7 +2175,7 @@ class RouterTest extends CakeTestCase {
|
||||||
|
|
||||||
$params = array('controller' => 'pages', 'action' => 'display');
|
$params = array('controller' => 'pages', 'action' => 'display');
|
||||||
Router::setRequestInfo(array($params, $paths));
|
Router::setRequestInfo(array($params, $paths));
|
||||||
$expected = array('plugin' => null, 'controller' => 'pages', 'action' => 'display', 'form' => array());
|
$expected = array('plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
||||||
$this->assertEqual(Router::getParams(), $expected);
|
$this->assertEqual(Router::getParams(), $expected);
|
||||||
$this->assertEqual(Router::getParams(true), $expected);
|
$this->assertEqual(Router::getParams(true), $expected);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue