Browse Source

Add test case for formatTreeList().

Mark Scherer 10 years ago
parent
commit
673889f416

+ 2 - 1
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',

+ 30 - 0
tests/TestCase/ORM/Behavior/TreeBehaviorTest.php

@@ -327,6 +327,36 @@ class TreeBehaviorTest extends TestCase
     }
 
     /**
+     * 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
      *
      * @return void