Skip to content

Commit

Permalink
Moving Non-Zero tests for Set::extract() into a separate method.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 25, 2010
1 parent 6c8ce98 commit 9d3f2fb
Showing 1 changed file with 62 additions and 52 deletions.
114 changes: 62 additions & 52 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -417,43 +417,15 @@ function testExtract() {
array('a' => array('II' => array('a' => 3, 'III' => array('a' => array('foo' => 4))))),
);

$nonSequential = array(
'User' => array(
0 => array('id' => 1),
2 => array('id' => 2),
6 => array('id' => 3),
9 => array('id' => 4),
3 => array('id' => 5),
),
);

$nonZero = array(
'User' => array(
2 => array('id' => 1),
4 => array('id' => 2),
6 => array('id' => 3),
9 => array('id' => 4),
3 => array('id' => 5),
),
);

$expected = array(array('a' => $c[2]['a']));
$r = Set::extract('/a/II[a=3]/..', $c);
$this->assertEqual($r, $expected);

$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $a), $expected);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);

$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($result, $expected, 'Failed non zero array key extract');

$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $a), $expected);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);

$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($result, $expected, 'Failed non zero array key extract');

$expected = array(
array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 4), array('id' => 5)
Expand Down Expand Up @@ -549,30 +521,6 @@ 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(
Expand Down Expand Up @@ -1026,6 +974,68 @@ function testExtract() {
$expected = array('Second');
$this->assertEqual($result, $expected);
}
/**
* test that extract() still works when arrays don't contain a 0 index.
*
* @return void
*/
function testExtractWithNonZeroArrays() {
$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);

$nonSequential = array(
'User' => array(
0 => array('id' => 1),
2 => array('id' => 2),
6 => array('id' => 3),
9 => array('id' => 4),
3 => array('id' => 5),
),
);

$nonZero = array(
'User' => array(
2 => array('id' => 1),
4 => array('id' => 2),
6 => array('id' => 3),
9 => array('id' => 4),
3 => array('id' => 5),
),
);

$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);

$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($result, $expected, 'Failed non zero array key extract');

$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);

$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($result, $expected, 'Failed non zero array key extract');
}
/**
* testExtractWithArrays method
*
Expand Down

0 comments on commit 9d3f2fb

Please sign in to comment.