mirror of
https://github.com/Oreolek/yii2-nested-sets.git
synced 2024-06-26 11:40:47 +03:00
Unit tests base extended and new case added
This commit is contained in:
parent
4d38749a81
commit
673a2c734e
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace tests;
|
||||
|
||||
use tests\models\MultipleRootsTree;
|
||||
use tests\models\Tree;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +28,14 @@ class NestedSetsBehaviorTest extends DatabaseTestCase
|
|||
$dataSet = $this->getConnection()->createDataSet(['tree']);
|
||||
$expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/tree-after-make-new-root.xml');
|
||||
$this->assertDataSetsEqual($expectedDataSet, $dataSet);
|
||||
|
||||
$node = new MultipleRootsTree();
|
||||
$node->id = 1;
|
||||
$node->name = 'Root';
|
||||
$this->assertTrue($node->makeRoot());
|
||||
$dataSet = $this->getConnection()->createDataSet(['multiple_roots_tree']);
|
||||
$expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/multiple-roots-tree-after-make-new-root.xml');
|
||||
$this->assertDataSetsEqual($expectedDataSet, $dataSet);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<dataset>
|
||||
<multiple_roots_tree id="1" tree="1" lft="1" rgt="2" depth="0" name="Root"/>
|
||||
</dataset>
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<dataset>
|
||||
<tree id="1" tree="1" lft="1" rgt="2" depth="0" name="Root 1"/>
|
||||
<multiple_roots_tree id="1" tree="1" lft="1" rgt="2" depth="0" name="Root 1"/>
|
||||
</dataset>
|
||||
|
|
72
tests/models/MultipleRootsTree.php
Normal file
72
tests/models/MultipleRootsTree.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/**
|
||||
* @link https://github.com/creocoder/yii2-nested-sets-behavior
|
||||
* @copyright Copyright (c) 2015 Alexander Kochetov
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
|
||||
namespace tests\models;
|
||||
|
||||
use creocoder\nestedsets\NestedSetsBehavior;
|
||||
|
||||
/**
|
||||
* MultipleRootsTree
|
||||
*
|
||||
* @property integer $id
|
||||
* @property integer $tree
|
||||
* @property integer $lft
|
||||
* @property integer $rgt
|
||||
* @property integer $depth
|
||||
* @property string $name
|
||||
*/
|
||||
class MultipleRootsTree extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'multiple_roots_tree';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'class' => NestedSetsBehavior::className(),
|
||||
'treeAttribute' => 'tree',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['name', 'required'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function transactions()
|
||||
{
|
||||
return [
|
||||
self::SCENARIO_DEFAULT => self::OP_ALL,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function find()
|
||||
{
|
||||
return new MultipleRootsTreeQuery(get_called_class());
|
||||
}
|
||||
}
|
26
tests/models/MultipleRootsTreeQuery.php
Normal file
26
tests/models/MultipleRootsTreeQuery.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* @link https://github.com/creocoder/yii2-nested-sets-behavior
|
||||
* @copyright Copyright (c) 2015 Alexander Kochetov
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
|
||||
namespace tests\models;
|
||||
|
||||
use creocoder\nestedsets\NestedSetsQueryBehavior;
|
||||
|
||||
/**
|
||||
* MultipleRootsTreeQuery
|
||||
*/
|
||||
class MultipleRootsTreeQuery extends \yii\db\ActiveQuery
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
NestedSetsQueryBehavior::className(),
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue