1
0
Fork 0
mirror of https://github.com/Oreolek/yii2-nested-sets.git synced 2024-06-16 23:00:48 +03:00

Unit tests base extended and new case added

This commit is contained in:
Alexander Kochetov 2015-01-02 11:49:35 +03:00
parent 4d38749a81
commit 673a2c734e
5 changed files with 112 additions and 1 deletions

View file

@ -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);
}
/**

View file

@ -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>

View file

@ -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>

View 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());
}
}

View 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(),
];
}
}