diff --git a/src/ORM/Behavior/TreeBehavior.php b/src/ORM/Behavior/TreeBehavior.php index ecba71c6f11..2971bb21905 100644 --- a/src/ORM/Behavior/TreeBehavior.php +++ b/src/ORM/Behavior/TreeBehavior.php @@ -64,7 +64,8 @@ class TreeBehavior extends Behavior 'moveDown' => 'moveDown', 'recover' => 'recover', 'removeFromTree' => 'removeFromTree', - 'getLevel' => 'getLevel' + 'getLevel' => 'getLevel', + 'formatTreeList' => 'formatTreeList' ], 'parent' => 'parent_id', 'left' => 'lft', diff --git a/tests/TestCase/ORM/Behavior/TreeBehaviorTest.php b/tests/TestCase/ORM/Behavior/TreeBehaviorTest.php index 6a52448f911..fb789a37b33 100644 --- a/tests/TestCase/ORM/Behavior/TreeBehaviorTest.php +++ b/tests/TestCase/ORM/Behavior/TreeBehaviorTest.php @@ -326,6 +326,36 @@ public function testFindTreeListCustom() $this->assertEquals($expected, $result); } + /** + * Tests the testFormatTreeListCustom() method. + * + * @return void + */ + public function testFormatTreeListCustom() + { + $table = TableRegistry::get('MenuLinkTrees'); + $table->addBehavior('Tree'); + + $query = $table + ->find('threaded') + ->where(['menu' => 'main-menu']); + + $options = ['keyPath' => 'url', 'valuePath' => 'id', 'spacer' => ' ']; + $result = $table->formatTreeList($query, $options)->toArray(); + + $expected = [ + '/link1.html' => '1', + 'http://example.com' => ' 2', + '/what/even-more-links.html' => ' 3', + '/lorem/ipsum.html' => ' 4', + '/what/the.html' => ' 5', + '/yeah/another-link.html' => '6', + 'http://cakephp.org' => ' 7', + '/page/who-we-are.html' => '8' + ]; + $this->assertEquals($expected, $result); + } + /** * Tests the moveUp() method *