Skip to content
Permalink
Browse files

Adding test case from 'mradosta'.

Fixing issue with non-zero indexed arrays and Set::extract()
Fixes #6
  • Loading branch information...
markstory committed Aug 22, 2009
1 parent 98ad480 commit 47d91813136f7dc8fe651fd9a2d5f63d21f19cb7
Showing with 29 additions and 3 deletions.
  1. +4 −1 cake/libs/set.php
  2. +25 −2 cake/tests/cases/libs/set.test.php
@@ -386,7 +386,10 @@ function extract($path, $data = null, $options = array()) {
$contexts = $data;
$options = array_merge(array('flatten' => true), $options);
if (!isset($contexts[0])) {
$contexts = array($data);
$current = current($data);
if ((is_array($current) && count($data) <= 1) || !is_array($current)) {
$contexts = array($data);
}
}
$tokens = array_slice(preg_split('/(?<!=)\/(?![a-z-]*\])/', $path), 1);
@@ -535,6 +535,30 @@ function testExtract() {
$r = Set::extract('/User/@*', $tricky);
$this->assertEqual($r, $expected);
$nonZero = array(
1 => array(
'User' => array(
'id' => 1,
'name' => 'John',
)
),
2 => array(
'User' => array(
'id' => 2,
'name' => 'Bob',
)
),
3 => array(
'User' => array(
'id' => 3,
'name' => 'Tony',
)
)
);
$expected = array(1, 2, 3);
$r = Set::extract('/User/id', $nonZero);
$this->assertEqual($r, $expected);
$common = array(
array(
'Article' => array(
@@ -969,7 +993,6 @@ function testExtract() {
$expected = array(array('name' => 'zipfile.zip','type' => 'application/zip','tmp_name' => '/tmp/php178.tmp','error' => 0,'size' => '564647'));
$r = Set::extract('/file/.[type=application/zip]', $f);
$this->assertEqual($r, $expected);
}
/**
* testMatches method
@@ -2396,7 +2419,7 @@ function testXmlSetReverse() {
array(
'Item' => array(
'title' => 'An example of a correctly reversed XMLNode',
'Desc' => array(),
'desc' => array(),
)
)
);

0 comments on commit 47d9181

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