From d5fdf45e5183ec7da731ca191081f2c7fa3bc368 Mon Sep 17 00:00:00 2001 From: AD7six Date: Tue, 10 Jan 2012 10:49:17 +0100 Subject: [PATCH] add a test for what happens when you nest on a field that doesn't exist --- lib/Cake/Test/Case/Utility/SetTest.php | 61 ++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/lib/Cake/Test/Case/Utility/SetTest.php b/lib/Cake/Test/Case/Utility/SetTest.php index faa08601c..2ad6455a1 100644 --- a/lib/Cake/Test/Case/Utility/SetTest.php +++ b/lib/Cake/Test/Case/Utility/SetTest.php @@ -3138,6 +3138,12 @@ class SetTest extends CakeTestCase { $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 @@ class SetTest extends CakeTestCase { $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 @@ class SetTest extends CakeTestCase { $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); + } }