Browse Source

root no change when update with makeRoot. Close #11

tags/v1.0.8 v1.0.8
PaulZi 7 years ago
parent
commit
59342c6bd7
  1. 2
      NestedSetsBehavior.php
  2. 128
      composer.lock
  3. 10
      tests/NestedSetsBehaviorTestCase.php
  4. 72
      tests/data/test-make-root-no-change.php

2
NestedSetsBehavior.php

@ -492,7 +492,9 @@ class NestedSetsBehavior extends Behavior
{ {
switch ($this->operation) { switch ($this->operation) {
case self::OPERATION_MAKE_ROOT: case self::OPERATION_MAKE_ROOT:
if ($this->treeChange || !$this->isRoot() || $this->owner->getIsNewRecord()) {
$this->moveNodeAsRoot(); $this->moveNodeAsRoot();
}
break; break;
case self::OPERATION_PREPEND_TO: case self::OPERATION_PREPEND_TO:

128
composer.lock generated

@ -52,7 +52,7 @@
"version": "v1.3.2", "version": "v1.3.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/bestiejs/punycode.js.git", "url": "git@github.com:bestiejs/punycode.js.git",
"reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3" "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3"
}, },
"dist": { "dist": {
@ -294,16 +294,16 @@
}, },
{ {
"name": "yiisoft/yii2-composer", "name": "yiisoft/yii2-composer",
"version": "2.0.6", "version": "2.0.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/yiisoft/yii2-composer.git", "url": "https://github.com/yiisoft/yii2-composer.git",
"reference": "163419f1f197e02f015713b0d4f85598d8f8aa80" "reference": "1439e78be1218c492e6cde251ed87d3f128b9534"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/163419f1f197e02f015713b0d4f85598d8f8aa80", "url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/1439e78be1218c492e6cde251ed87d3f128b9534",
"reference": "163419f1f197e02f015713b0d4f85598d8f8aa80", "reference": "1439e78be1218c492e6cde251ed87d3f128b9534",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -344,7 +344,7 @@
"extension installer", "extension installer",
"yii2" "yii2"
], ],
"time": "2018-03-21T16:15:55+00:00" "time": "2018-07-05T15:44:47+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [
@ -458,35 +458,29 @@
}, },
{ {
"name": "phpdocumentor/reflection-docblock", "name": "phpdocumentor/reflection-docblock",
"version": "4.3.0", "version": "3.2.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "94fd0001232e47129dd3504189fa1c7225010d08" "reference": "4aada1f93c72c35e22fb1383b47fee43b8f1d157"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/4aada1f93c72c35e22fb1383b47fee43b8f1d157",
"reference": "94fd0001232e47129dd3504189fa1c7225010d08", "reference": "4aada1f93c72c35e22fb1383b47fee43b8f1d157",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.0", "php": ">=5.5",
"phpdocumentor/reflection-common": "^1.0.0", "phpdocumentor/reflection-common": "^1.0@dev",
"phpdocumentor/type-resolver": "^0.4.0", "phpdocumentor/type-resolver": "^0.3.0",
"webmozart/assert": "^1.0" "webmozart/assert": "^1.0"
}, },
"require-dev": { "require-dev": {
"doctrine/instantiator": "~1.0.5", "mockery/mockery": "^0.9.4",
"mockery/mockery": "^1.0", "phpunit/phpunit": "^4.4"
"phpunit/phpunit": "^6.4"
}, },
"type": "library", "type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
}
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"phpDocumentor\\Reflection\\": [ "phpDocumentor\\Reflection\\": [
@ -505,20 +499,20 @@
} }
], ],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2017-11-30T07:14:17+00:00" "time": "2017-08-08T06:39:58+00:00"
}, },
{ {
"name": "phpdocumentor/type-resolver", "name": "phpdocumentor/type-resolver",
"version": "0.4.0", "version": "0.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git", "url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fb3933512008d8162b3cdf9e18dba9309b7c3773",
"reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -552,27 +546,27 @@
"email": "me@mikevanriel.com" "email": "me@mikevanriel.com"
} }
], ],
"time": "2017-07-14T14:27:02+00:00" "time": "2017-06-03T08:32:36+00:00"
}, },
{ {
"name": "phpspec/prophecy", "name": "phpspec/prophecy",
"version": "1.7.5", "version": "1.7.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpspec/prophecy.git", "url": "https://github.com/phpspec/prophecy.git",
"reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401" "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/dfd6be44111a7c41c2e884a336cc4f461b3b2401", "url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712",
"reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401", "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"doctrine/instantiator": "^1.0.2", "doctrine/instantiator": "^1.0.2",
"php": "^5.3|^7.0", "php": "^5.3|^7.0",
"phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0",
"sebastian/comparator": "^1.1|^2.0", "sebastian/comparator": "^1.1|^2.0|^3.0",
"sebastian/recursion-context": "^1.0|^2.0|^3.0" "sebastian/recursion-context": "^1.0|^2.0|^3.0"
}, },
"require-dev": { "require-dev": {
@ -615,7 +609,7 @@
"spy", "spy",
"stub" "stub"
], ],
"time": "2018-02-19T10:16:54+00:00" "time": "2018-04-18T13:57:24+00:00"
}, },
{ {
"name": "phpunit/dbunit", "name": "phpunit/dbunit",
@ -1425,21 +1419,77 @@
"time": "2015-06-21T13:59:46+00:00" "time": "2015-06-21T13:59:46+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype",
"version": "v1.8.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae",
"reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.8-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Ctype\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
},
{
"name": "Gert de Pagter",
"email": "BackEndTea@gmail.com"
}
],
"description": "Symfony polyfill for ctype functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"ctype",
"polyfill",
"portable"
],
"time": "2018-04-30T19:57:29+00:00"
},
{
"name": "symfony/yaml", "name": "symfony/yaml",
"version": "v3.4.6", "version": "v3.4.12",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/yaml.git", "url": "https://github.com/symfony/yaml.git",
"reference": "6af42631dcf89e9c616242c900d6c52bd53bd1bb" "reference": "c5010cc1692ce1fa328b1fb666961eb3d4a85bb0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/6af42631dcf89e9c616242c900d6c52bd53bd1bb", "url": "https://api.github.com/repos/symfony/yaml/zipball/c5010cc1692ce1fa328b1fb666961eb3d4a85bb0",
"reference": "6af42631dcf89e9c616242c900d6c52bd53bd1bb", "reference": "c5010cc1692ce1fa328b1fb666961eb3d4a85bb0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^5.5.9|>=7.0.8" "php": "^5.5.9|>=7.0.8",
"symfony/polyfill-ctype": "~1.8"
}, },
"conflict": { "conflict": {
"symfony/console": "<3.4" "symfony/console": "<3.4"
@ -1480,7 +1530,7 @@
], ],
"description": "Symfony Yaml Component", "description": "Symfony Yaml Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-02-16T09:50:28+00:00" "time": "2018-05-03T23:18:14+00:00"
}, },
{ {
"name": "webmozart/assert", "name": "webmozart/assert",

10
tests/NestedSetsBehaviorTestCase.php

@ -233,6 +233,16 @@ class NestedSetsBehaviorTestCase extends BaseTestCase
$node->makeRoot()->save(); $node->makeRoot()->save();
} }
public function testMakeRootNoChange()
{
$node = MultipleTreeNode::findOne(1);
$node->slug = 'root';
$this->assertTrue($node->makeRoot()->save());
$dataSet = $this->getConnection()->createDataSet(['tree', 'multiple_tree']);
$expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-make-root-no-change.php'));
$this->assertDataSetsEqual($expectedDataSet, $dataSet);
}
public function testPrependToInsertInNoEmpty() public function testPrependToInsertInNoEmpty()
{ {
$node = new Node(['slug' => 'new']); $node = new Node(['slug' => 'new']);

72
tests/data/test-make-root-no-change.php

@ -0,0 +1,72 @@
<?php
return array(
'tree' => array(
array('id' => '1','lft' => '1','rgt' => '50','depth' => '0','slug' => 'r1'),
array('id' => '2','lft' => '2','rgt' => '27','depth' => '1','slug' => 'n1'),
array('id' => '3','lft' => '28','rgt' => '29','depth' => '1','slug' => 'n2'),
array('id' => '4','lft' => '30','rgt' => '49','depth' => '1','slug' => 'n3'),
array('id' => '5','lft' => '3','rgt' => '10','depth' => '2','slug' => 'n11'),
array('id' => '6','lft' => '11','rgt' => '18','depth' => '2','slug' => 'n12'),
array('id' => '7','lft' => '19','rgt' => '26','depth' => '2','slug' => 'n13'),
array('id' => '8','lft' => '31','rgt' => '32','depth' => '2','slug' => 'n31'),
array('id' => '9','lft' => '33','rgt' => '40','depth' => '2','slug' => 'n32'),
array('id' => '10','lft' => '41','rgt' => '48','depth' => '2','slug' => 'n33'),
array('id' => '11','lft' => '4','rgt' => '5','depth' => '3','slug' => 'n111'),
array('id' => '12','lft' => '6','rgt' => '7','depth' => '3','slug' => 'n112'),
array('id' => '13','lft' => '8','rgt' => '9','depth' => '3','slug' => 'n113'),
array('id' => '14','lft' => '12','rgt' => '13','depth' => '3','slug' => 'n121'),
array('id' => '15','lft' => '14','rgt' => '15','depth' => '3','slug' => 'n122'),
array('id' => '16','lft' => '16','rgt' => '17','depth' => '3','slug' => 'n123'),
array('id' => '17','lft' => '20','rgt' => '21','depth' => '3','slug' => 'n131'),
array('id' => '18','lft' => '22','rgt' => '23','depth' => '3','slug' => 'n132'),
array('id' => '19','lft' => '24','rgt' => '25','depth' => '3','slug' => 'n133'),
array('id' => '20','lft' => '34','rgt' => '35','depth' => '3','slug' => 'n321'),
array('id' => '21','lft' => '36','rgt' => '37','depth' => '3','slug' => 'n322'),
array('id' => '22','lft' => '38','rgt' => '39','depth' => '3','slug' => 'n323'),
array('id' => '23','lft' => '42','rgt' => '43','depth' => '3','slug' => 'n331'),
array('id' => '24','lft' => '44','rgt' => '45','depth' => '3','slug' => 'n332'),
array('id' => '25','lft' => '46','rgt' => '47','depth' => '3','slug' => 'n333'),
),
'multiple_tree' => array(
array('id' => '1','tree' => '1','lft' => '1','rgt' => '50','depth' => '0','slug' => 'root'),
array('id' => '2','tree' => '1','lft' => '2','rgt' => '27','depth' => '1','slug' => 'n1'),
array('id' => '3','tree' => '1','lft' => '28','rgt' => '29','depth' => '1','slug' => 'n2'),
array('id' => '4','tree' => '1','lft' => '30','rgt' => '49','depth' => '1','slug' => 'n3'),
array('id' => '5','tree' => '1','lft' => '3','rgt' => '10','depth' => '2','slug' => 'n11'),
array('id' => '6','tree' => '1','lft' => '11','rgt' => '18','depth' => '2','slug' => 'n12'),
array('id' => '7','tree' => '1','lft' => '19','rgt' => '26','depth' => '2','slug' => 'n13'),
array('id' => '8','tree' => '1','lft' => '31','rgt' => '32','depth' => '2','slug' => 'n31'),
array('id' => '9','tree' => '1','lft' => '33','rgt' => '40','depth' => '2','slug' => 'n32'),
array('id' => '10','tree' => '1','lft' => '41','rgt' => '48','depth' => '2','slug' => 'n33'),
array('id' => '11','tree' => '1','lft' => '4','rgt' => '5','depth' => '3','slug' => 'n111'),
array('id' => '12','tree' => '1','lft' => '6','rgt' => '7','depth' => '3','slug' => 'n112'),
array('id' => '13','tree' => '1','lft' => '8','rgt' => '9','depth' => '3','slug' => 'n113'),
array('id' => '14','tree' => '1','lft' => '12','rgt' => '13','depth' => '3','slug' => 'n121'),
array('id' => '15','tree' => '1','lft' => '14','rgt' => '15','depth' => '3','slug' => 'n122'),
array('id' => '16','tree' => '1','lft' => '16','rgt' => '17','depth' => '3','slug' => 'n123'),
array('id' => '17','tree' => '1','lft' => '20','rgt' => '21','depth' => '3','slug' => 'n131'),
array('id' => '18','tree' => '1','lft' => '22','rgt' => '23','depth' => '3','slug' => 'n132'),
array('id' => '19','tree' => '1','lft' => '24','rgt' => '25','depth' => '3','slug' => 'n133'),
array('id' => '20','tree' => '1','lft' => '34','rgt' => '35','depth' => '3','slug' => 'n321'),
array('id' => '21','tree' => '1','lft' => '36','rgt' => '37','depth' => '3','slug' => 'n322'),
array('id' => '22','tree' => '1','lft' => '38','rgt' => '39','depth' => '3','slug' => 'n323'),
array('id' => '23','tree' => '1','lft' => '42','rgt' => '43','depth' => '3','slug' => 'n331'),
array('id' => '24','tree' => '1','lft' => '44','rgt' => '45','depth' => '3','slug' => 'n332'),
array('id' => '25','tree' => '1','lft' => '46','rgt' => '47','depth' => '3','slug' => 'n333'),
array('id' => '26','tree' => '26','lft' => '1','rgt' => '28','depth' => '0','slug' => 'r2'),
array('id' => '27','tree' => '26','lft' => '2','rgt' => '11','depth' => '1','slug' => 'n1'),
array('id' => '28','tree' => '26','lft' => '12','rgt' => '13','depth' => '1','slug' => 'n2'),
array('id' => '29','tree' => '26','lft' => '14','rgt' => '17','depth' => '1','slug' => 'n3'),
array('id' => '30','tree' => '26','lft' => '18','rgt' => '27','depth' => '1','slug' => 'n4'),
array('id' => '31','tree' => '26','lft' => '3','rgt' => '4','depth' => '2','slug' => 'n11'),
array('id' => '32','tree' => '26','lft' => '5','rgt' => '6','depth' => '2','slug' => 'n12'),
array('id' => '33','tree' => '26','lft' => '7','rgt' => '8','depth' => '2','slug' => 'n13'),
array('id' => '34','tree' => '26','lft' => '9','rgt' => '10','depth' => '2','slug' => 'n14'),
array('id' => '35','tree' => '26','lft' => '15','rgt' => '16','depth' => '2','slug' => 'n31'),
array('id' => '36','tree' => '26','lft' => '19','rgt' => '20','depth' => '2','slug' => 'n41'),
array('id' => '37','tree' => '26','lft' => '21','rgt' => '22','depth' => '2','slug' => 'n42'),
array('id' => '38','tree' => '26','lft' => '23','rgt' => '24','depth' => '2','slug' => 'n43'),
array('id' => '39','tree' => '26','lft' => '25','rgt' => '26','depth' => '2','slug' => 'n44'),
)
);
Loading…
Cancel
Save