diff --git a/tests/NestedSetsQueryBehaviorTest.php b/tests/NestedSetsQueryBehaviorTest.php index dedfc56..6c0341e 100644 --- a/tests/NestedSetsQueryBehaviorTest.php +++ b/tests/NestedSetsQueryBehaviorTest.php @@ -7,6 +7,10 @@ namespace tests; +use tests\models\MultipleRootsTree; +use tests\models\Tree; +use yii\helpers\ArrayHelper; + /** * NestedSetsQueryBehaviorTest */ @@ -17,7 +21,21 @@ class NestedSetsQueryBehaviorTest extends DatabaseTestCase */ public function testRoots() { - $this->markTestSkipped(); + $dataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/tree.xml'); + $this->getDatabaseTester()->setDataSet($dataSet); + $this->getDatabaseTester()->onSetUp(); + $models = Tree::find()->roots()->all(); + $dataSet = new ArrayDataSet(['tree' => ArrayHelper::toArray($models)]); + $expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/tree-query-roots.xml'); + $this->assertDataSetsEqual($expectedDataSet, $dataSet); + + $dataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/multiple-roots-tree.xml'); + $this->getDatabaseTester()->setDataSet($dataSet); + $this->getDatabaseTester()->onSetUp(); + $models = MultipleRootsTree::find()->roots()->all(); + $dataSet = new ArrayDataSet(['multiple_roots_tree' => ArrayHelper::toArray($models)]); + $expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/multiple-roots-tree-query-roots.xml'); + $this->assertDataSetsEqual($expectedDataSet, $dataSet); } /** @@ -25,6 +43,20 @@ class NestedSetsQueryBehaviorTest extends DatabaseTestCase */ public function testLeaf() { - $this->markTestSkipped(); + $dataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/tree.xml'); + $this->getDatabaseTester()->setDataSet($dataSet); + $this->getDatabaseTester()->onSetUp(); + $models = Tree::find()->leaf()->all(); + $dataSet = new ArrayDataSet(['tree' => ArrayHelper::toArray($models)]); + $expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/tree-query-leaf.xml'); + $this->assertDataSetsEqual($expectedDataSet, $dataSet); + + $dataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/multiple-roots-tree.xml'); + $this->getDatabaseTester()->setDataSet($dataSet); + $this->getDatabaseTester()->onSetUp(); + $models = MultipleRootsTree::find()->leaf()->all(); + $dataSet = new ArrayDataSet(['multiple_roots_tree' => ArrayHelper::toArray($models)]); + $expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/datasets/multiple-roots-tree-query-leaf.xml'); + $this->assertDataSetsEqual($expectedDataSet, $dataSet); } }