Skip to content

Commit

Permalink
adding support to write values to param like can be done with data(),…
Browse files Browse the repository at this point in the history
… method returns $this as does ->data() when writing
  • Loading branch information
dogmatic69 committed May 24, 2014
1 parent 9dca564 commit bcdc530
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Cake/Network/CakeRequest.php
Expand Up @@ -874,6 +874,11 @@ public function data($name) {
* 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);
}
Expand Down
25 changes: 25 additions & 0 deletions lib/Cake/Test/Case/Network/CakeRequestTest.php
Expand Up @@ -2114,6 +2114,31 @@ public function paramReadingDataProvider() {
);
}

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
*
Expand Down

0 comments on commit bcdc530

Please sign in to comment.