From a63dd9ee9d7e58b9df6fe4110120e9f1b40f5275 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 17 Jul 2012 21:06:41 -0400 Subject: [PATCH] Fix incorrect formatting in TreeBehavior. Fixes #3045 --- lib/Cake/Model/Behavior/TreeBehavior.php | 3 +-- .../Model/Behavior/TreeBehaviorNumberTest.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index a92c367fdf2..365d26002c0 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -371,8 +371,7 @@ public function generateTreeList(Model $Model, $conditions = null, $keyPath = nu $valuePath = array('%s%s', '{n}.tree_prefix', $valuePath); } else { - $valuePath[0] = '{' . (count($valuePath) - 1) . '}' . $valuePath[0]; - $valuePath[] = '{n}.tree_prefix'; + array_unshift($valuePath, '%s' . $valuePath[0], '{n}.tree_prefix'); } $order = $Model->alias . '.' . $left . ' asc'; $results = $Model->find('all', compact('conditions', 'fields', 'order', 'recursive')); diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php index 10782865e10..d93c6334e45 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php @@ -1281,6 +1281,26 @@ public function testGenerateTreeListWithSelfJoin() { $this->assertSame($expected, $result); } +/** + * Test the formatting options of generateTreeList() + * + * @return void + */ + public function testGenerateTreeListFormatting() { + extract($this->settings); + $this->Tree = new $modelClass(); + $this->Tree->initialize(2, 2); + + $result = $this->Tree->generateTreeList( + null, + "{n}.$modelClass.id", + array('%s - %s', "{n}.$modelClass.id", "{n}.$modelClass.name") + ); + $this->assertEquals('1 - 1. Root', $result[1]); + $this->assertEquals('_2 - 1.1', $result[2]); + $this->assertEquals('__3 - 1.1.1', $result[3]); + } + /** * testArraySyntax method *