mirror of
https://github.com/Oreolek/yii2-nested-sets.git
synced 2024-05-19 01:08:17 +03:00
NestedSetsBehavior::ancestors renamed to NestedSetsBehavior::parents, NestedSetsBehavior::parent removed
This commit is contained in:
parent
87ffc3f87d
commit
8e03bd8d70
|
@ -238,7 +238,7 @@ class NestedSetsBehavior extends Behavior
|
|||
* @param integer $depth the depth
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function ancestors($depth = null)
|
||||
public function parents($depth = null)
|
||||
{
|
||||
$query = $this->owner->find();
|
||||
|
||||
|
@ -259,27 +259,6 @@ class NestedSetsBehavior extends Behavior
|
|||
return $query->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent of the node.
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
$query = $this->owner->find();
|
||||
|
||||
$condition = [
|
||||
'and',
|
||||
['<', $this->leftAttribute, $this->owner->getAttribute($this->leftAttribute)],
|
||||
['>', $this->rightAttribute, $this->owner->getAttribute($this->rightAttribute)],
|
||||
];
|
||||
|
||||
if ($this->treeAttribute !== false) {
|
||||
$condition[] = [$this->treeAttribute => $this->owner->getAttribute($this->treeAttribute)];
|
||||
}
|
||||
|
||||
return $query->andWhere($condition)->addOrderBy([$this->rightAttribute => SORT_ASC]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the previous sibling of the node.
|
||||
* @return \yii\db\ActiveQuery
|
||||
|
|
|
@ -872,37 +872,29 @@ class NestedSetsBehaviorTest extends DatabaseTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers \creocoder\nestedsets\NestedSetsBehavior::ancestors
|
||||
* @covers \creocoder\nestedsets\NestedSetsBehavior::parents
|
||||
*/
|
||||
public function testAncestors()
|
||||
public function testParents()
|
||||
{
|
||||
$dataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/tree.xml');
|
||||
$this->getDatabaseTester()->setDataSet($dataSet);
|
||||
$this->getDatabaseTester()->onSetUp();
|
||||
$node = Tree::findOne(11);
|
||||
$models = $node->ancestors()->all();
|
||||
$models = $node->parents()->all();
|
||||
$dataSet = new ArrayDataSet(['tree' => ArrayHelper::toArray($models)]);
|
||||
$expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/tree-after-ancestors.xml');
|
||||
$expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/tree-after-parents.xml');
|
||||
$this->assertDataSetsEqual($expectedDataSet, $dataSet);
|
||||
|
||||
$dataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/multiple-roots-tree.xml');
|
||||
$this->getDatabaseTester()->setDataSet($dataSet);
|
||||
$this->getDatabaseTester()->onSetUp();
|
||||
$node = MultipleRootsTree::findOne(33);
|
||||
$models = $node->ancestors()->all();
|
||||
$models = $node->parents()->all();
|
||||
$dataSet = new ArrayDataSet(['multiple_roots_tree' => ArrayHelper::toArray($models)]);
|
||||
$expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/multiple-roots-tree-after-ancestors.xml');
|
||||
$expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/multiple-roots-tree-after-parents.xml');
|
||||
$this->assertDataSetsEqual($expectedDataSet, $dataSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \creocoder\nestedsets\NestedSetsBehavior::parent
|
||||
*/
|
||||
public function testParent()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \creocoder\nestedsets\NestedSetsBehavior::prev
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue