mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Making CakeRequest::addParams() chainable. Adding CakeRequest::addPaths() to allow easy settings of path variables, its also chainable. Tests added.
This commit is contained in:
parent
bd1365f8ae
commit
4eef2c19f0
2 changed files with 41 additions and 2 deletions
|
@ -503,10 +503,26 @@ class CakeRequest implements ArrayAccess {
|
||||||
* Add parameters to the request's parsed parameter set.
|
* Add parameters to the request's parsed parameter set.
|
||||||
*
|
*
|
||||||
* @param array $params Array of parameters to merge in
|
* @param array $params Array of parameters to merge in
|
||||||
* @return void
|
* @return The current object, you can chain this method.
|
||||||
*/
|
*/
|
||||||
public function addParams($params) {
|
public function addParams($params) {
|
||||||
$this->params = array_merge($this->params, $params);
|
$this->params = array_merge($this->params, $params);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add paths to the requests' paths vars
|
||||||
|
*
|
||||||
|
* @param array $paths Array of paths to merge in
|
||||||
|
* @return the current object, you can chain this method.
|
||||||
|
*/
|
||||||
|
public function addPaths($paths) {
|
||||||
|
foreach (array('webroot', 'here', 'base') as $element) {
|
||||||
|
if (isset($paths[$element])) {
|
||||||
|
$this->{$element} = $paths[$element];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -72,13 +72,36 @@ class CakeRequestTestCase extends CakeTestCase {
|
||||||
function testAddParams() {
|
function testAddParams() {
|
||||||
$request = new CakeRequest('some/path');
|
$request = new CakeRequest('some/path');
|
||||||
$request->params = array('controller' => 'posts', 'action' => 'view');
|
$request->params = array('controller' => 'posts', 'action' => 'view');
|
||||||
$request->addParams(array('plugin' => null, 'action' => 'index'));
|
$result = $request->addParams(array('plugin' => null, 'action' => 'index'));
|
||||||
|
|
||||||
|
$this->assertIdentical($result, $request, 'Method did not return itself. %s');
|
||||||
|
|
||||||
$this->assertEqual($request->controller, 'posts');
|
$this->assertEqual($request->controller, 'posts');
|
||||||
$this->assertEqual($request->action, 'index');
|
$this->assertEqual($request->action, 'index');
|
||||||
$this->assertEqual($request->plugin, null);
|
$this->assertEqual($request->plugin, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test splicing in paths.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testAddPaths() {
|
||||||
|
$request = new CakeRequest('some/path');
|
||||||
|
$request->webroot = '/some/path/going/here/';
|
||||||
|
$result = $request->addPaths(array(
|
||||||
|
'random' => '/something', 'webroot' => '/', 'here' => '/', 'base' => '/base_dir'
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertIdentical($result, $request, 'Method did not return itself. %s');
|
||||||
|
|
||||||
|
$this->assertEqual($request->webroot, '/');
|
||||||
|
$this->assertEqual($request->base, '/base_dir');
|
||||||
|
$this->assertEqual($request->here, '/');
|
||||||
|
$this->assertFalse(isset($request->random));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test parsing POST data into the object.
|
* test parsing POST data into the object.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue