Permalink
Browse files

Moving Non-Zero tests for Set::extract() into a separate method.

  • Loading branch information...
1 parent 6c8ce98 commit 9d3f2fb4a757e0cccbb590a5062dc4a29dff13e4 @markstory markstory committed Mar 25, 2010
Showing with 62 additions and 52 deletions.
  1. +62 −52 cake/tests/cases/libs/set.test.php
@@ -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)
@@ -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(
@@ -1027,6 +975,68 @@ function testExtract() {
$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
*
* @access public

0 comments on commit 9d3f2fb

Please sign in to comment.