Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add a test for what happens when you nest on a field that doesn't exist
  • Loading branch information
AD7six committed Jan 10, 2012
1 parent 3b1dd82 commit d5fdf45
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions lib/Cake/Test/Case/Utility/SetTest.php
Expand Up @@ -3138,6 +3138,12 @@ public function testNormalizeArrays() {
$this->assertEquals($expected, $result);
}

/**
* test Set nest with a normal model result set. For kicks rely on Set nest detecting the key names
* automatically
*
* @return void
*/
public function testNestModel() {
$input = array(
array(
Expand Down Expand Up @@ -3280,6 +3286,11 @@ public function testNestModel() {
$this->assertEquals($expected, $result);
}

/**
* test Set nest with a 1d array - this method should be able to handle any type of array input
*
* @return void
*/
public function testNest1Dimensional() {
$input = array(
array(
Expand Down Expand Up @@ -3381,4 +3392,54 @@ public function testNest1Dimensional() {
$result = Set::nest($input, array('idPath' => '/id', 'parentPath' => '/parent_id'));
$this->assertEquals($expected, $result);
}

/**
* test Set nest with no specified parent data.
*
* For an easier comparison, unset all the empty children arrays from the result
*
* @return void
*/
public function testMissingParent() {
$input = array(
array(
'id' => 1,
),
array(
'id' => 2,
),
array(
'id' => 3,
),
array(
'id' => 4,
),
array(
'id' => 5,
),
array(
'id' => 6,
),
array(
'id' => 7,
),
array(
'id' => 8,
),
array(
'id' => 9,
),
array(
'id' => 10,
)
);

$result = Set::nest($input, array('idPath' => '/id', 'parentPath' => '/parent_id'));
foreach($result as &$row) {
if (empty($row['children'])) {
unset($row['children']);
}
}
$this->assertEquals($input, $result);
}
}

0 comments on commit d5fdf45

Please sign in to comment.