Skip to content
Permalink
Browse files

Allow Set::extract() to match null.

Fixes #2926
  • Loading branch information...
markstory committed May 31, 2012
1 parent 25c7a27 commit fb0cc50700f90df4a7f92c0d7fe15d03ed444aaf
Showing with 28 additions and 1 deletion.
  1. +27 −0 lib/Cake/Test/Case/Utility/SetTest.php
  2. +1 −1 lib/Cake/Utility/Set.php
@@ -1387,6 +1387,33 @@ public function testExtractWithNonArrayElements() {
$this->assertEquals($expected, $result);
}
/**
* Test that extract() + matching can hit null things.
*/
public function testExtractMatchesNull() {
$data = array(
'Country' => array(
array('name' => 'Canada'),
array('name' => 'Australia'),
array('name' => null),
)
);
$result = Set::extract('/Country[name=/Canada|^$/]', $data);
$expected = array(
array(
'Country' => array(
'name' => 'Canada',
),
),
array(
'Country' => array(
'name' => null,
),
),
);
$this->assertEquals($expected, $result);
}
/**
* testMatches method
*
@@ -536,7 +536,7 @@ public static function matches($conditions, $data = array(), $i = null, $length
continue;
}
list(, $key, $op, $expected) = $match;
if (!isset($data[$key])) {
if (!(isset($data[$key]) || array_key_exists($key, $data))) {
return false;
}

0 comments on commit fb0cc50

Please sign in to comment.
You can’t perform that action at this time.