mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
Merge branch 'hash-fix' from glaforge/patch-1 into master.
Closes #3288
This commit is contained in:
commit
3e579571aa
2 changed files with 40 additions and 1 deletions
|
@ -831,6 +831,39 @@ class HashTest extends CakeTestCase {
|
||||||
$this->assertEquals(5, $result[3]['id']);
|
$this->assertEquals(5, $result[3]['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test extracting based on attributes with boolean values.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExtractAttributeBoolean() {
|
||||||
|
$users = array(
|
||||||
|
array(
|
||||||
|
'id' => 2,
|
||||||
|
'username' => 'johndoe',
|
||||||
|
'active' => true
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'id' => 5,
|
||||||
|
'username' => 'kevin',
|
||||||
|
'active' => true
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'id' => 9,
|
||||||
|
'username' => 'samantha',
|
||||||
|
'active' => false
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$result = Hash::extract($users, '{n}[active=false]');
|
||||||
|
$this->assertCount(1, $result);
|
||||||
|
$this->assertEquals($users[2], $result[0]);
|
||||||
|
|
||||||
|
$result = Hash::extract($users, '{n}[active=true]');
|
||||||
|
$this->assertCount(2, $result);
|
||||||
|
$this->assertEquals($users[0], $result[0]);
|
||||||
|
$this->assertEquals($users[1], $result[1]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that attribute matchers don't cause errors on scalar data.
|
* Test that attribute matchers don't cause errors on scalar data.
|
||||||
*
|
*
|
||||||
|
|
|
@ -192,7 +192,13 @@ class Hash {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$prop = isset($data[$attr]) ? $data[$attr] : null;
|
$prop = null;
|
||||||
|
if (isset($data[$attr])) {
|
||||||
|
$prop = $data[$attr];
|
||||||
|
}
|
||||||
|
if ($prop === true || $prop === false) {
|
||||||
|
$prop = $prop ? 'true' : 'false';
|
||||||
|
}
|
||||||
|
|
||||||
// Pattern matches and other operators.
|
// Pattern matches and other operators.
|
||||||
if ($op === '=' && $val && $val[0] === '/') {
|
if ($op === '=' && $val && $val[0] === '/') {
|
||||||
|
|
Loading…
Add table
Reference in a new issue