Browse Source

Fix incorrect formatting in TreeBehavior.

Fixes #3045
mark_story 13 years ago
parent
commit
a63dd9ee9d

+ 1 - 2
lib/Cake/Model/Behavior/TreeBehavior.php

@@ -371,8 +371,7 @@ class TreeBehavior extends ModelBehavior {
 			$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'));

+ 20 - 0
lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php

@@ -1282,6 +1282,26 @@ class TreeBehaviorNumberTest extends CakeTestCase {
 	}
 
 /**
+ * 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
  *
  * @return void