Skip to content

Commit

Permalink
Add test case for formatTreeList().
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Scherer committed Jun 1, 2015
1 parent f64dfb9 commit 673889f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ORM/Behavior/TreeBehavior.php
Expand Up @@ -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',
Expand Down
30 changes: 30 additions & 0 deletions tests/TestCase/ORM/Behavior/TreeBehaviorTest.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 673889f

Please sign in to comment.