From 2d5aaaec78d0823f0bb80234d7cc28b823ddb26a Mon Sep 17 00:00:00 2001 From: PaulZi Date: Thu, 13 Oct 2016 22:48:01 +0300 Subject: [PATCH] Fix populateTree() wrong secondary using of variable $depth. Close #4 --- NestedSetsBehavior.php | 6 ++-- composer.lock | 67 ++++++++++++++++++------------------ tests/NestedSetsBehaviorTestCase.php | 4 +++ 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/NestedSetsBehavior.php b/NestedSetsBehavior.php index 07b3065..5241952 100644 --- a/NestedSetsBehavior.php +++ b/NestedSetsBehavior.php @@ -226,8 +226,10 @@ class NestedSetsBehavior extends Behavior $nodes = $this->getDescendants($depth)->all(); } + $key = $this->owner->getAttribute($this->leftAttribute); $relates = []; - $parents = [$this->owner->getAttribute($this->leftAttribute)]; + $relates[$key] = []; + $parents = [$key]; $prev = $this->owner->getAttribute($this->depthAttribute); foreach($nodes as $node) { @@ -251,8 +253,6 @@ class NestedSetsBehavior extends Behavior $key = $node->getAttribute($this->leftAttribute); if (isset($relates[$key])) { $node->populateRelation('children', $relates[$key]); - } elseif ($depth === null) { - $node->populateRelation('children', []); } } diff --git a/composer.lock b/composer.lock index 714e334..811419b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "313a11363bcb8d1cc8b43c73b052d404", + "hash": "a4a6cd529883c816c9665d9c3361c66b", "content-hash": "c2618cb72efb684ac68b4e708a48ecb4", "packages": [ { @@ -43,12 +43,12 @@ "version": "3.2.7", "source": { "type": "git", - "url": "https://github.com/RobinHerbots/jquery.inputmask.git", + "url": "https://github.com/RobinHerbots/Inputmask.git", "reference": "5a72c563b502b8e05958a524cdfffafe9987be38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/RobinHerbots/jquery.inputmask/zipball/5a72c563b502b8e05958a524cdfffafe9987be38", + "url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/5a72c563b502b8e05958a524cdfffafe9987be38", "reference": "5a72c563b502b8e05958a524cdfffafe9987be38", "shasum": "" }, @@ -148,16 +148,16 @@ }, { "name": "cebe/markdown", - "version": "1.1.0", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/cebe/markdown.git", - "reference": "54a2c49de31cc44e864ebf0500a35ef21d0010b2" + "reference": "c30eb5e01fe021cc5bba2f9ee0eeef96d4931166" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cebe/markdown/zipball/54a2c49de31cc44e864ebf0500a35ef21d0010b2", - "reference": "54a2c49de31cc44e864ebf0500a35ef21d0010b2", + "url": "https://api.github.com/repos/cebe/markdown/zipball/c30eb5e01fe021cc5bba2f9ee0eeef96d4931166", + "reference": "c30eb5e01fe021cc5bba2f9ee0eeef96d4931166", "shasum": "" }, "require": { @@ -204,7 +204,7 @@ "markdown", "markdown-extra" ], - "time": "2015-03-06 05:28:07" + "time": "2016-09-14 20:40:20" }, { "name": "ezyang/htmlpurifier", @@ -503,16 +503,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.1.0", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "9270140b940ff02e58ec577c237274e92cd40cdd" + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd", - "reference": "9270140b940ff02e58ec577c237274e92cd40cdd", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", "shasum": "" }, "require": { @@ -544,7 +544,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2016-06-10 09:48:41" + "time": "2016-09-30 07:12:33" }, { "name": "phpdocumentor/type-resolver", @@ -1203,23 +1203,23 @@ }, { "name": "sebastian/environment", - "version": "1.3.7", + "version": "1.3.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716" + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4e8f0da10ac5802913afc151413bc8c53b6c2716", - "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^4.8 || ^5.0" }, "type": "library", "extra": { @@ -1249,7 +1249,7 @@ "environment", "hhvm" ], - "time": "2016-05-17 03:18:57" + "time": "2016-08-18 05:49:44" }, { "name": "sebastian/exporter", @@ -1459,16 +1459,16 @@ }, { "name": "symfony/yaml", - "version": "v3.1.2", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "2884c26ce4c1d61aebf423a8b912950fe7c764de" + "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/2884c26ce4c1d61aebf423a8b912950fe7c764de", - "reference": "2884c26ce4c1d61aebf423a8b912950fe7c764de", + "url": "https://api.github.com/repos/symfony/yaml/zipball/368b9738d4033c8b93454cb0dbd45d305135a6d3", + "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3", "shasum": "" }, "require": { @@ -1504,32 +1504,33 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:41:56" + "time": "2016-09-25 08:27:07" }, { "name": "webmozart/assert", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde" + "reference": "bb2d123231c095735130cc8f6d31385a44c7b308" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", - "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", + "url": "https://api.github.com/repos/webmozart/assert/zipball/bb2d123231c095735130cc8f6d31385a44c7b308", + "reference": "bb2d123231c095735130cc8f6d31385a44c7b308", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3|^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.6" + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.2-dev" } }, "autoload": { @@ -1553,7 +1554,7 @@ "check", "validate" ], - "time": "2015-08-24 13:29:44" + "time": "2016-08-09 15:02:57" } ], "aliases": [], diff --git a/tests/NestedSetsBehaviorTestCase.php b/tests/NestedSetsBehaviorTestCase.php index b265e04..4033b0f 100644 --- a/tests/NestedSetsBehaviorTestCase.php +++ b/tests/NestedSetsBehaviorTestCase.php @@ -132,6 +132,10 @@ class NestedSetsBehaviorTestCase extends BaseTestCase $node = Node::findOne(19); $node->populateTree(); $this->assertEquals(true, $node->isRelationPopulated('children')); + + $node = Node::findOne(19); + $node->populateTree(1); + $this->assertEquals(true, $node->isRelationPopulated('children')); } public function testIsRoot()