mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
make the default return false so it matches previous use, improve tests for new method
This commit is contained in:
parent
a657e410b2
commit
9dca564519
2 changed files with 58 additions and 21 deletions
|
@ -875,7 +875,7 @@ class CakeRequest implements ArrayAccess {
|
|||
*/
|
||||
public function param($name) {
|
||||
if (!isset($this->params[$name])) {
|
||||
return Hash::get($this->params, $name);
|
||||
return Hash::get($this->params, $name, false);
|
||||
}
|
||||
return $this->params[$name];
|
||||
}
|
||||
|
|
|
@ -1995,26 +1995,6 @@ class CakeRequestTest extends CakeTestCase {
|
|||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test using param()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadingParams() {
|
||||
$request = new CakeRequest();
|
||||
$request->addParams(array(
|
||||
'controller' => 'posts',
|
||||
'admin' => true,
|
||||
'truthy' => 1,
|
||||
'zero' => '0',
|
||||
));
|
||||
$this->assertFalse($request->param('not_set'));
|
||||
$this->assertTrue($request->param('admin'));
|
||||
$this->assertEquals(1, $request->param('truthy'));
|
||||
$this->assertEquals('posts', $request->param('controller'));
|
||||
$this->assertEquals('0', $request->param('zero'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the data() method reading
|
||||
*
|
||||
|
@ -2077,6 +2057,63 @@ class CakeRequestTest extends CakeTestCase {
|
|||
$this->assertSame('', $request->data['Post']['empty']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider paramReadingDataProvider
|
||||
*/
|
||||
public function testParamReading($toRead, $expected) {
|
||||
$request = new CakeRequest('/');
|
||||
$request->addParams(array(
|
||||
'action' => 'index',
|
||||
'foo' => 'bar',
|
||||
'baz' => array(
|
||||
'a' => array(
|
||||
'b' => 'c',
|
||||
),
|
||||
),
|
||||
'admin' => true,
|
||||
'truthy' => 1,
|
||||
'zero' => '0',
|
||||
));
|
||||
$this->assertEquals($expected, $request->param($toRead));
|
||||
}
|
||||
|
||||
public function paramReadingDataProvider() {
|
||||
return array(
|
||||
array(
|
||||
'action',
|
||||
'index',
|
||||
),
|
||||
array(
|
||||
'baz',
|
||||
array(
|
||||
'a' => array(
|
||||
'b' => 'c',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'baz.a.b',
|
||||
'c',
|
||||
),
|
||||
array(
|
||||
'does_not_exist',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'admin',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'truthy',
|
||||
1,
|
||||
),
|
||||
array(
|
||||
'zero',
|
||||
'0',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test accept language
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue