1
0
Fork 0
mirror of https://github.com/Oreolek/yii2-nested-sets.git synced 2024-06-26 11:40:47 +03:00
yii2-nested-sets/tests/NestedSetsQueryBehaviorTest.php

41 lines
1.2 KiB
PHP
Raw Normal View History

<?php
/**
2015-01-05 10:03:13 +02:00
* @link https://github.com/creocoder/yii2-nested-sets
* @copyright Copyright (c) 2015 Alexander Kochetov
* @license http://opensource.org/licenses/BSD-3-Clause
*/
namespace tests;
2015-01-03 19:09:41 +02:00
use tests\models\MultipleRootsTree;
use tests\models\Tree;
use yii\helpers\ArrayHelper;
/**
* NestedSetsQueryBehaviorTest
*/
class NestedSetsQueryBehaviorTest extends DatabaseTestCase
{
public function testRoots()
{
2015-01-04 13:26:18 +02:00
$dataSet = new ArrayDataSet([
'tree' => ArrayHelper::toArray(Tree::find()->roots()->all()),
'multiple_roots_tree' => ArrayHelper::toArray(MultipleRootsTree::find()->roots()->all()),
]);
2015-01-03 19:09:41 +02:00
2015-01-04 13:26:18 +02:00
$expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/data/test-roots-query.xml');
2015-01-03 19:09:41 +02:00
$this->assertDataSetsEqual($expectedDataSet, $dataSet);
}
public function testLeaves()
{
2015-01-04 13:26:18 +02:00
$dataSet = new ArrayDataSet([
'tree' => ArrayHelper::toArray(Tree::find()->leaves()->all()),
'multiple_roots_tree' => ArrayHelper::toArray(MultipleRootsTree::find()->leaves()->all()),
]);
2015-01-03 19:09:41 +02:00
2015-01-04 13:26:18 +02:00
$expectedDataSet = $this->createFlatXMLDataSet(__DIR__ . '/data/test-leaves-query.xml');
2015-01-03 19:09:41 +02:00
$this->assertDataSetsEqual($expectedDataSet, $dataSet);
}
}