adding support to write values to param like can be done with data(), method returns $this as does ->data() when writing

This commit is contained in:
dogmatic69 2014-05-25 00:52:30 +01:00
parent 9dca564519
commit bcdc530391
2 changed files with 30 additions and 0 deletions

View file

@ -874,6 +874,11 @@ class CakeRequest implements ArrayAccess {
* return false if the parameter doesn't exist or is falsey.
*/
public function param($name) {
$args = func_get_args();
if (count($args) === 2) {
$this->params = Hash::insert($this->params, $name, $args[1]);
return $this;
}
if (!isset($this->params[$name])) {
return Hash::get($this->params, $name, false);
}

View file

@ -2114,6 +2114,31 @@ class CakeRequestTest extends CakeTestCase {
);
}
public function testParamWriting() {
$request = new CakeRequest('/');
$request->addParams(array(
'action' => 'index',
));
$this->assertInstanceOf('CakeRequest', $request->param('some', 'thing'), 'Method has not returned $this');
$request->param('Post.null', null);
$this->assertNull($request->params['Post']['null']);
$request->param('Post.false', false);
$this->assertFalse($request->params['Post']['false']);
$request->param('Post.zero', 0);
$this->assertSame(0, $request->params['Post']['zero']);
$request->param('Post.empty', '');
$this->assertSame('', $request->params['Post']['empty']);
$this->assertSame('index', $request->action);
$request->param('action', 'edit');
$this->assertSame('edit', $request->action);
}
/**
* Test accept language
*