Browse Source

Merge pull request #11621 from cakephp/issue-11565

Fix notice errors when scope is unset.
Mark Story 8 years ago
parent
commit
d27de2953d

+ 5 - 5
src/ORM/Behavior/TreeBehavior.php

@@ -932,13 +932,13 @@ class TreeBehavior extends Behavior
      */
     protected function _scope($query)
     {
-        $config = $this->getConfig();
+        $scope = $this->getConfig('scope');
 
-        if (is_array($config['scope'])) {
-            return $query->where($config['scope']);
+        if (is_array($scope)) {
+            return $query->where($scope);
         }
-        if (is_callable($config['scope'])) {
-            return $config['scope']($query);
+        if (is_callable($scope)) {
+            return $scope($query);
         }
 
         return $query;

+ 16 - 2
tests/TestCase/ORM/Behavior/TreeBehaviorTest.php

@@ -197,7 +197,7 @@ class TreeBehaviorTest extends TestCase
      *
      * @return void
      */
-    public function testCallableScoping()
+    public function testScopeCallable()
     {
         $table = TableRegistry::get('MenuLinkTrees');
         $table->addBehavior('Tree', [
@@ -208,7 +208,6 @@ class TreeBehaviorTest extends TestCase
         $count = $table->childCount($table->get(1), false);
         $this->assertEquals(4, $count);
     }
-
     /**
      * Tests the find('children') method
      *
@@ -235,6 +234,21 @@ class TreeBehaviorTest extends TestCase
     }
 
     /**
+     * Tests the find('children') plus scope=null
+     *
+     * @return void
+     */
+    public function testScopeNull()
+    {
+        $table = TableRegistry::get('MenuLinkTrees');
+        $table->addBehavior('Tree');
+        $table->behaviors()->get('Tree')->setConfig('scope', null);
+
+        $nodes = $table->find('children', ['for' => 1, 'direct' => true])->all();
+        $this->assertEquals([2, 3], $nodes->extract('id')->toArray());
+    }
+
+    /**
      * Tests that find('children') will throw an exception if the node was not found
      *
      * @return void