Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add a test for what happens when you nest on a field that doesn't exist

  • Loading branch information...
commit d5fdf45e5183ec7da731ca191081f2c7fa3bc368 1 parent 3b1dd82
@AD7six AD7six authored
Showing with 61 additions and 0 deletions.
  1. +61 −0 lib/Cake/Test/Case/Utility/SetTest.php
View
61 lib/Cake/Test/Case/Utility/SetTest.php
@@ -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(
@@ -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(
@@ -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);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.