Merge branch 'hash-fix' from glaforge/patch-1 into master.

Closes #3288
This commit is contained in:
mark_story 2014-04-10 20:37:34 -04:00
commit 3e579571aa
2 changed files with 40 additions and 1 deletions

View file

@ -831,6 +831,39 @@ class HashTest extends CakeTestCase {
$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.
*

View file

@ -192,7 +192,13 @@ class Hash {
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.
if ($op === '=' && $val && $val[0] === '/') {