From bcdc530391f06844e6725980c7e5eac62a9ba074 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Sun, 25 May 2014 00:52:30 +0100 Subject: [PATCH] adding support to write values to param like can be done with data(), method returns $this as does ->data() when writing --- lib/Cake/Network/CakeRequest.php | 5 ++++ .../Test/Case/Network/CakeRequestTest.php | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 5ee40b0a0..64f16224d 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -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); } diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 2309d2f94..bebc70ea7 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -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 *