Skip to content

Commit

Permalink
Fix incorrect formatting in TreeBehavior.
Browse files Browse the repository at this point in the history
Fixes #3045
  • Loading branch information
markstory committed Jul 18, 2012
1 parent 928de97 commit a63dd9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -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'));
Expand Down
20 changes: 20 additions & 0 deletions lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php
Expand Up @@ -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
*
Expand Down

0 comments on commit a63dd9e

Please sign in to comment.