/tests/Propel/Tests/Generator/Behavior/NestedSet/NestedSetBehaviorQueryBuilderModifierWithScopeTest.php
https://github.com/vworldat/Propel2 · PHP · 312 lines · 125 code · 19 blank · 168 comment · 0 complexity · 18f73407dc77a31aa00343df14d08b4e MD5 · raw file
- <?php
- /**
- * This file is part of the Propel package.
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- * @license MIT License
- */
- namespace Propel\Tests\Generator\Behavior\NestedSet;
- use Propel\Tests\Helpers\Bookstore\Behavior\BookstoreNestedSetTestBase;
- use Propel\Tests\Bookstore\Behavior\Table10;
- use Propel\Tests\Bookstore\Behavior\Table10Query;
- /**
- * Tests for NestedSetBehaviorQueryBuilderModifier class with scope enabled
- *
- * @author François Zaninotto
- * @version $Revision$
- * @package generator.behavior.nestedset
- */
- class NestedSetBehaviorQueryBuilderModifierWithScopeTest extends BookstoreNestedSetTestBase
- {
- public function testTreeRoots()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $objs = Table10Query::create()
- ->treeRoots()
- ->find();
- $coll = $this->buildCollection(array($t1, $t8));
- $this->assertEquals($coll, $objs, 'treeRoots() filters by roots');
- }
- public function testInTree()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $tree = Table10Query::create()
- ->inTree(1)
- ->orderByBranch()
- ->find();
- $coll = $this->buildCollection(array($t1, $t2, $t3, $t4, $t5, $t6, $t7));
- $this->assertEquals($coll, $tree, 'inTree() filters by node');
- $tree = Table10Query::create()
- ->inTree(2)
- ->orderByBranch()
- ->find();
- $coll = $this->buildCollection(array($t8, $t9, $t10));
- $this->assertEquals($coll, $tree, 'inTree() filters by node');
- }
- public function testDescendantsOf()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $objs = Table10Query::create()
- ->descendantsOf($t1)
- ->orderByBranch()
- ->find();
- $coll = $this->buildCollection(array($t2, $t3, $t4, $t5, $t6, $t7));
- $this->assertEquals($coll, $objs, 'decendantsOf() filters by descendants of the same scope');
- }
- public function testBranchOf()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $objs = Table10Query::create()
- ->branchOf($t1)
- ->orderByBranch()
- ->find();
- $coll = $this->buildCollection(array($t1, $t2, $t3, $t4, $t5, $t6, $t7));
- $this->assertEquals($coll, $objs, 'branchOf() filters by branch of the same scope');
- }
- public function testChildrenOf()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $objs = Table10Query::create()
- ->childrenOf($t1)
- ->orderByBranch()
- ->find();
- $coll = $this->buildCollection(array($t2, $t3));
- $this->assertEquals($coll, $objs, 'childrenOf() filters by children of the same scope');
- }
- public function testSiblingsOf()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $desc = Table10Query::create()
- ->siblingsOf($t3)
- ->orderByBranch()
- ->find();
- $coll = $this->buildCollection(array($t2));
- $this->assertEquals($coll, $desc, 'siblingsOf() returns filters by siblings of the same scope');
- }
- public function testAncestorsOf()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $objs = Table10Query::create()
- ->ancestorsOf($t5)
- ->orderByBranch()
- ->find();
- $coll = $this->buildCollection(array($t1, $t3), 'ancestorsOf() filters by ancestors of the same scope');
- }
- public function testRootsOf()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $objs = Table10Query::create()
- ->rootsOf($t5)
- ->orderByBranch()
- ->find();
- $coll = $this->buildCollection(array($t1, $t3, $t5), 'rootsOf() filters by ancestors of the same scope');
- }
- public function testFindRoot()
- {
- $this->assertTrue(method_exists('Table10Query', 'findRoot'), 'nested_set adds a findRoot() method');
- Table10Query::create()->deleteAll();
- $this->assertNull(Table10Query::create()->findRoot(1), 'findRoot() returns null as long as no root node is defined');
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $this->assertEquals($t1, Table10Query::create()->findRoot(1), 'findRoot() returns a tree root');
- $this->assertEquals($t8, Table10Query::create()->findRoot(2), 'findRoot() returns a tree root');
- }
- public function testFindRoots()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $objs = Table10Query::create()
- ->findRoots();
- $coll = $this->buildCollection(array($t1, $t8));
- $this->assertEquals($coll, $objs, 'findRoots() returns all root objects');
- }
- public function testFindTree()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $tree = Table10Query::create()->findTree(1);
- $coll = $this->buildCollection(array($t1, $t2, $t3, $t4, $t5, $t6, $t7));
- $this->assertEquals($coll, $tree, 'findTree() retrieves the tree of a scope, ordered by branch');
- $tree = Table10Query::create()->findTree(2);
- $coll = $this->buildCollection(array($t8, $t9, $t10));
- $this->assertEquals($coll, $tree, 'findTree() retrieves the tree of a scope, ordered by branch');
- }
- protected function buildCollection($arr)
- {
- $coll = new PropelObjectCollection();
- $coll->setData($arr);
- $coll->setModel('Table10');
- return $coll;
- }
- }