Skip to content
Browse files

[Generator] [NestedSet] Fix almost all tests

  • Loading branch information...
1 parent 8c086c6 commit 090db6af95b5304802be58a86e191630f37885a9 @willdurand willdurand committed Jan 13, 2013
View
17 src/Propel/Generator/Behavior/NestedSet/NestedSetBehaviorObjectBuilderModifier.php
@@ -477,10 +477,9 @@ protected function addHasParent(&$script)
/**
* Tests if object has an ancestor
*
- * @param ConnectionInterface \$con Connection to use.
- * @return bool
+ * @return boolean
*/
-public function hasParent(ConnectionInterface \$con = null)
+public function hasParent()
{
return \$this->getLevel() > 0;
}
@@ -518,8 +517,8 @@ protected function addGetParent(&$script)
* Gets parent node for the current object if it exists
* The result is cached so further calls to the same method don't issue any queries
*
- * @param ConnectionInterface \$con Connection to use.
- * @return mixed Propel object if exists else false
+ * @param ConnectionInterface \$con Connection to use.
+ * @return mixed Propel object if exists else false
*/
public function getParent(ConnectionInterface \$con = null)
{
@@ -847,11 +846,11 @@ protected function addGetSiblings(&$script)
/**
* Gets the siblings of the given node
*
- * @param bool \$includeNode Whether to include the current node or not
- * @param Criteria \$query Criteria to filter results.
- * @param ConnectionInterface \$con Connection to use.
+ * @param boolean \$includeNode Whether to include the current node or not
+ * @param Criteria \$query Criteria to filter results.
+ * @param ConnectionInterface \$con Connection to use.
*
- * @return array List of $objectClassName objects
+ * @return array List of $objectClassName objects
*/
public function getSiblings(\$includeNode = false, \$query = null, ConnectionInterface \$con = null)
{
View
13 .../Propel/Tests/Generator/Behavior/NestedSet/NestedSetBehaviorObjectBuilderModifierTest.php
@@ -509,11 +509,13 @@ public function testCountChildrenCache()
| \
t6 t7
*/
- $con = Propel::getServiceContainer()->getReadConnection(\Map\NestedSetTable9TableMap::DATABASE_NAME);
+ $con = Propel::getServiceContainer()->getReadConnection(\Map\NestedSetTable9TableMap::DATABASE_NAME);
$count = $con->getQueryCount();
- $children = $t3->getChildren(null, $con);
+
+ $children = $t3->getChildren(null, $con);
$nbChildren = $t3->countChildren(null, $con);
$this->assertEquals($count + 1, $con->getQueryCount(), 'countChildren() uses the internal collection when passed no Criteria');
+
$nbChildren = $t3->countChildren(new Criteria(), $con);
$this->assertEquals($count + 2, $con->getQueryCount(), 'countChildren() issues a new query when passed a Criteria');
}
@@ -1499,4 +1501,11 @@ public function testGetAncestors2()
);
$this->assertEquals($expected, $this->dumpNodes($path), 'getAncestors() returns path from the current scope only');
}
+
+ public function testConstants()
+ {
+ $this->assertEquals(\NestedSetTable9::LEFT_COL, 'nested_set_table9.tree_left', 'nested_set adds a LEFT_COL constant');
+ $this->assertEquals(\NestedSetTable9::RIGHT_COL, 'nested_set_table9.tree_right', 'nested_set adds a RIGHT_COL constant');
+ $this->assertEquals(\NestedSetTable9::LEVEL_COL, 'nested_set_table9.tree_level', 'nested_set adds a LEVEL_COL constant');
+ }
}
View
32 ...ests/Generator/Behavior/NestedSet/NestedSetBehaviorObjectBuilderModifierWithScopeTest.php
@@ -234,7 +234,11 @@ public function testGetAncestors()
public function testInsertAsFirstChildOf()
{
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table10', 'insertAsFirstChildOf'), 'nested_set adds a insertAsFirstChildOf() method');
+ $this->assertTrue(
+ method_exists('NestedSetTable10', 'insertAsFirstChildOf'),
+ 'nested_set adds a insertAsFirstChildOf() method'
+ );
+
$fixtures = $this->initTreeWithScope();
/* Tree used for tests
Scope 1
@@ -303,7 +307,11 @@ public function testInsertAsFirstChildOfExistingObject()
public function testInsertAsLastChildOf()
{
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table10', 'insertAsLastChildOf'), 'nested_set adds a insertAsLastChildOf() method');
+ $this->assertTrue(
+ method_exists('NestedSetTable10', 'insertAsLastChildOf'),
+ 'nested_set adds a insertAsLastChildOf() method'
+ );
+
$fixtures = $this->initTreeWithScope();
/* Tree used for tests
Scope 1
@@ -372,7 +380,11 @@ public function testInsertAsLastChildOfExistingObject()
public function testInsertAsPrevSiblingOf()
{
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table10', 'insertAsPrevSiblingOf'), 'nested_set adds a insertAsPrevSiblingOf() method');
+ $this->assertTrue(
+ method_exists('NestedSetTable10', 'insertAsPrevSiblingOf'),
+ 'nested_set adds a insertAsPrevSiblingOf() method'
+ );
+
$fixtures = $this->initTreeWithScope();
/* Tree used for tests
Scope 1
@@ -452,7 +464,11 @@ public function testInsertAsPrevSiblingOfExistingObject()
public function testInsertAsNextSiblingOf()
{
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table10', 'insertAsNextSiblingOf'), 'nested_set adds a insertAsNextSiblingOf() method');
+ $this->assertTrue(
+ method_exists('NestedSetTable10', 'insertAsNextSiblingOf'),
+ 'nested_set adds a insertAsNextSiblingOf() method'
+ );
+
$fixtures = $this->initTreeWithScope();
/* Tree used for tests
Scope 1
@@ -709,4 +725,12 @@ public function testDeleteDescendants()
);
$this->assertEquals($expected, $this->dumpTreeWithScope(2), 'deleteDescendants() does not delete anything out of the scope');
}
+
+ public function testConstants()
+ {
+ $this->assertEquals(\NestedSetTable10::LEFT_COL, 'nested_set_table10.my_left_column');
+ $this->assertEquals(\NestedSetTable10::RIGHT_COL, 'nested_set_table10.my_right_column');
+ $this->assertEquals(\NestedSetTable10::LEVEL_COL, 'nested_set_table10.my_level_column');
+ $this->assertEquals(\NestedSetTable10::SCOPE_COL, 'nested_set_table10.my_scope_column');
+ }
}
View
353 tests/Propel/Tests/Generator/Behavior/NestedSet/NestedSetBehaviorPeerBuilderModifierTest.php
@@ -1,353 +0,0 @@
-<?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\Runtime\ActiveQuery\Criteria;
-
-/**
- * Tests for NestedSetBehaviorPeerBuilderModifier class
- *
- * @author François Zaninotto
- */
-class NestedSetBehaviorPeerBuilderModifierTest extends TestCase
-{
- public function setUp()
- {
- $this->markTestSkipped('These tests should move somewhere else');
- }
-
- public function testConstants()
- {
- $this->assertEquals(Table9Peer::LEFT_COL, 'table9.TREE_LEFT', 'nested_set adds a LEFT_COL constant');
- $this->assertEquals(Table9Peer::RIGHT_COL, 'table9.TREE_RIGHT', 'nested_set adds a RIGHT_COL constant');
- $this->assertEquals(Table9Peer::LEVEL_COL, 'table9.TREE_LEVEL', 'nested_set adds a LEVEL_COL constant');
- }
-
- public function testRetrieveRoot()
- {
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table9Peer', 'retrieveRoot'), 'nested_set adds a retrieveRoot() method');
- Table9Peer::doDeleteAll();
- $this->assertNull(Table9Peer::retrieveRoot(), 'retrieveRoot() returns null as long as no root node is defined');
- $t1 = new Table9();
- $t1->setLeftValue(123);
- $t1->setRightValue(456);
- $t1->save();
- $this->assertNull(Table9Peer::retrieveRoot(), 'retrieveRoot() returns null as long as no root node is defined');
- $t2 = new Table9();
- $t2->setLeftValue(1);
- $t2->setRightValue(2);
- $t2->save();
- $this->assertEquals(Table9Peer::retrieveRoot(), $t2, 'retrieveRoot() retrieves the root node');
- }
-
- public function testRetrieveTree()
- {
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7) = $this->initTree();
- $tree = Table9Peer::retrieveTree();
- $this->assertEquals(array($t1, $t2, $t3, $t4, $t5, $t6, $t7), $tree, 'retrieveTree() retrieves the whole tree');
- $c = new Criteria();
- $c->add(Table9Peer::LEFT_COL, 4, Criteria::GREATER_EQUAL);
- $tree = Table9Peer::retrieveTree($c);
- $this->assertEquals(array($t3, $t4, $t5, $t6, $t7), $tree, 'retrieveTree() accepts a Criteria as first parameter');
- }
-
- public function testIsValid()
- {
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table9Peer', 'isValid'), 'nested_set adds an isValid() method');
- $this->assertFalse(Table9Peer::isValid(null), 'isValid() returns false when passed null ');
- $t1 = new Table9();
- $this->assertFalse(Table9Peer::isValid($t1), 'isValid() returns false when passed an empty node object');
- $t2 = new Table9();
- $t2->setLeftValue(5)->setRightValue(2);
- $this->assertFalse(Table9Peer::isValid($t2), 'isValid() returns false when passed a node object with left > right');
- $t3 = new Table9();
- $t3->setLeftValue(5)->setRightValue(5);
- $this->assertFalse(Table9Peer::isValid($t3), 'isValid() returns false when passed a node object with left = right');
- $t4 = new Table9();
- $t4->setLeftValue(2)->setRightValue(5);
- $this->assertTrue(Table9Peer::isValid($t4), 'isValid() returns true when passed a node object with left < right');
- }
-
- public function testDeleteTree()
- {
- $this->initTree();
- Table9Peer::deleteTree();
- $this->assertEquals(array(), Table9Peer::doSelect(new Criteria()), 'deleteTree() deletes the whole tree');
- }
-
- public function testShiftRLValuesDelta()
- {
- $this->initTree();
- Table9Peer::shiftRLValues($delta = 1, $left = 1);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1' => array(2, 15, 0),
- 't2' => array(3, 4, 1),
- 't3' => array(5, 14, 1),
- 't4' => array(6, 7, 2),
- 't5' => array(8, 13, 2),
- 't6' => array(9, 10, 3),
- 't7' => array(11, 12, 3),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts all nodes with a positive amount');
- $this->initTree();
- Table9Peer::shiftRLValues($delta = -1, $left = 1);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1' => array(0, 13, 0),
- 't2' => array(1, 2, 1),
- 't3' => array(3, 12, 1),
- 't4' => array(4, 5, 2),
- 't5' => array(6, 11, 2),
- 't6' => array(7, 8, 3),
- 't7' => array(9, 10, 3),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues can shift all nodes with a negative amount');
- $this->initTree();
- Table9Peer::shiftRLValues($delta = 3, $left = 1);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1'=> array(4, 17, 0),
- 't2' => array(5, 6, 1),
- 't3' => array(7, 16, 1),
- 't4' => array(8, 9, 2),
- 't5' => array(10, 15, 2),
- 't6' => array(11, 12, 3),
- 't7' => array(13, 14, 3),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts all nodes several units to the right');
- Table9Peer::shiftRLValues($delta = -3, $left = 1);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1' => array(1, 14, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 13, 1),
- 't4' => array(5, 6, 2),
- 't5' => array(7, 12, 2),
- 't6' => array(8, 9, 3),
- 't7' => array(10, 11, 3),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts all nodes several units to the left');
- }
-
- public function testShiftRLValuesLeftLimit()
- {
- $this->initTree();
- Table9Peer::shiftRLValues($delta = 1, $left = 15);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1' => array(1, 14, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 13, 1),
- 't4' => array(5, 6, 2),
- 't5' => array(7, 12, 2),
- 't6' => array(8, 9, 3),
- 't7' => array(10, 11, 3),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues does not shift anything when the left parameter is higher than the highest right value');
- $this->initTree();
- Table9Peer::shiftRLValues($delta = 1, $left = 5);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1' => array(1, 15, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 14, 1),
- 't4' => array(6, 7, 2),
- 't5' => array(8, 13, 2),
- 't6' => array(9, 10, 3),
- 't7' => array(11, 12, 3),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts only the nodes having a LR value higher than the given left parameter');
- $this->initTree();
- Table9Peer::shiftRLValues($delta = 1, $left = 1);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1'=> array(2, 15, 0),
- 't2' => array(3, 4, 1),
- 't3' => array(5, 14, 1),
- 't4' => array(6, 7, 2),
- 't5' => array(8, 13, 2),
- 't6' => array(9, 10, 3),
- 't7' => array(11, 12, 3),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts all nodes when the left parameter is 1');
- }
-
- public function testShiftRLValuesRightLimit()
- {
- $this->initTree();
- Table9Peer::shiftRLValues($delta = 1, $left = 1, $right = 0);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1' => array(1, 14, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 13, 1),
- 't4' => array(5, 6, 2),
- 't5' => array(7, 12, 2),
- 't6' => array(8, 9, 3),
- 't7' => array(10, 11, 3),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues does not shift anything when the right parameter is 0');
- $this->initTree();
- Table9Peer::shiftRLValues($delta = 1, $left = 1, $right = 5);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1' => array(2, 14, 0),
- 't2' => array(3, 4, 1),
- 't3' => array(5, 13, 1),
- 't4' => array(6, 6, 2),
- 't5' => array(7, 12, 2),
- 't6' => array(8, 9, 3),
- 't7' => array(10, 11, 3),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shiftRLValues shifts only the nodes having a LR value lower than the given right parameter');
- $this->initTree();
- Table9Peer::shiftRLValues($delta = 1, $left = 1, $right = 15);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1'=> array(2, 15, 0),
- 't2' => array(3, 4, 1),
- 't3' => array(5, 14, 1),
- 't4' => array(6, 7, 2),
- 't5' => array(8, 13, 2),
- 't6' => array(9, 10, 3),
- 't7' => array(11, 12, 3),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts all nodes when the right parameter is higher than the highest right value');
- }
-
- public function testShiftLevel()
- {
- /* Tree used for tests
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- */
- $this->initTree();
- Table9Peer::shiftLevel($delta = 1, $first = 7, $last = 12);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1' => array(1, 14, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 13, 1),
- 't4' => array(5, 6, 2),
- 't5' => array(7, 12, 3),
- 't6' => array(8, 9, 4),
- 't7' => array(10, 11, 4),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftLevel shifts all nodes with a left value between the first and last');
- $this->initTree();
- Table9Peer::shiftLevel($delta = -1, $first = 7, $last = 12);
- Table9Peer::clearInstancePool();
- $expected = array(
- 't1' => array(1, 14, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 13, 1),
- 't4' => array(5, 6, 2),
- 't5' => array(7, 12, 1),
- 't6' => array(8, 9, 2),
- 't7' => array(10, 11, 2),
- );
- $this->assertEquals($this->dumpTree(), $expected, 'shiftLevel shifts all nodes wit ha negative amount');
- }
-
- public function testUpdateLoadedNodes()
- {
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table9Peer', 'updateLoadedNodes'), 'nested_set adds a updateLoadedNodes() method');
- $fixtures = $this->initTree();
- Table9Peer::shiftRLValues(1, 5);
- $expected = array(
- 't1' => array(1, 14),
- 't2' => array(2, 3),
- 't3' => array(4, 13),
- 't4' => array(5, 6),
- 't5' => array(7, 12),
- 't6' => array(8, 9),
- 't7' => array(10, 11),
- );
- $actual = array();
- foreach ($fixtures as $t) {
- $actual[$t->getTitle()] = array($t->getLeftValue(), $t->getRightValue());
- }
- $this->assertEquals($actual, $expected, 'Loaded nodes are not in sync before calling updateLoadedNodes()');
- Table9Peer::updateLoadedNodes();
- $expected = array(
- 't1' => array(1, 15),
- 't2' => array(2, 3),
- 't3' => array(4, 14),
- 't4' => array(6, 7),
- 't5' => array(8, 13),
- 't6' => array(9, 10),
- 't7' => array(11, 12),
- );
- $actual = array();
- foreach ($fixtures as $t) {
- $actual[$t->getTitle()] = array($t->getLeftValue(), $t->getRightValue());
- }
- $this->assertEquals($actual, $expected, 'Loaded nodes are in sync after calling updateLoadedNodes()');
- }
-
- public function testMakeRoomForLeaf()
- {
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table9Peer', 'makeRoomForLeaf'), 'nested_set adds a makeRoomForLeaf() method');
- list($t1, $t2, $t3, $t4, $t5, $t6, $t7) = $this->initTree();
- /* Tree used for tests
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- */
- $t = Table9Peer::makeRoomForLeaf(5); // first child of t3
- $expected = array(
- 't1' => array(1, 16, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 15, 1),
- 't4' => array(7, 8, 2),
- 't5' => array(9, 14, 2),
- 't6' => array(10, 11, 3),
- 't7' => array(12, 13, 3),
- );
- $this->assertEquals($expected, $this->dumpTree(), 'makeRoomForLeaf() shifts the other nodes correctly');
- foreach ($expected as $key => $values) {
- $this->assertEquals($values, array($$key->getLeftValue(), $$key->getRightValue(), $$key->getLevel()), 'makeRoomForLeaf() updates nodes already in memory');
- }
- }
-
- public function testFixLevels()
- {
- $fixtures = $this->initTree();
- // reset the levels
- foreach ($fixtures as $node) {
- $node->setLevel(null)->save();
- }
- // fix the levels
- Table9Peer::fixLevels();
- $expected = array(
- 't1' => array(1, 14, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 13, 1),
- 't4' => array(5, 6, 2),
- 't5' => array(7, 12, 2),
- 't6' => array(8, 9, 3),
- 't7' => array(10, 11, 3),
- );
- $this->assertEquals($expected, $this->dumpTree(), 'fixLevels() fixes the levels correctly');
- Table9Peer::fixLevels();
- $this->assertEquals($expected, $this->dumpTree(), 'fixLevels() can be called several times');
- }
-}
View
258 .../Tests/Generator/Behavior/NestedSet/NestedSetBehaviorPeerBuilderModifierWithScopeTest.php
@@ -1,258 +0,0 @@
-<?php
-
-/*
- * $Id$
- * 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\Runtime\ActiveQuery\Criteria;
-
-/**
- * Tests for NestedSetBehaviorPeerBuilderModifier class
- *
- * @author François Zaninotto
- */
-class NestedSetBehaviorPeerBuilderModifierWithScopeTest extends TestCase
-{
- public function setUp()
- {
- $this->markTestSkipped('These tests should move somewhere else');
- }
-
- public function testConstants()
- {
- $this->assertEquals(Table10Peer::LEFT_COL, 'table10.MY_LEFT_COLUMN', 'nested_set adds a LEFT_COL constant using the custom left_column parameter');
- $this->assertEquals(Table10Peer::RIGHT_COL, 'table10.MY_RIGHT_COLUMN', 'nested_set adds a RIGHT_COL constant using the custom right_column parameter');
- $this->assertEquals(Table10Peer::LEVEL_COL, 'table10.MY_LEVEL_COLUMN', 'nested_set adds a LEVEL_COL constant using the custom level_column parameter');
- $this->assertEquals(Table10Peer::SCOPE_COL, 'table10.MY_SCOPE_COLUMN', 'nested_set adds a SCOPE_COL constant when the use_scope parameter is true');
- }
-
- public function testRetrieveRoots()
- {
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table10Peer', 'retrieveRoots'), 'nested_set adds a retrieveRoots() method for trees that use scope');
- $this->assertFalse(method_exists('\Propel\Tests\Bookstore\Behavior\Table9Peer', 'retrieveRoots'), 'nested_set does not add a retrieveRoots() method for trees that don\'t use scope');
- 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(array($t1, $t8), Table10Peer::retrieveRoots(), 'retrieveRoots() returns the tree roots');
- $c = new Criteria();
- $c->add(Table10Peer::TITLE, 't1');
- $this->assertEquals(array($t1), Table10Peer::retrieveRoots($c), 'retrieveRoots() accepts a Criteria as first parameter');
- }
-
- public function testRetrieveRoot()
- {
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table10Peer', 'retrieveRoot'), 'nested_set adds a retrieveRoot() method');
- Table10Peer::doDeleteAll();
- $t1 = new Table10();
- $t1->setLeftValue(1);
- $t1->setRightValue(2);
- $t1->setScopeValue(2);
- $t1->save();
- $this->assertNull(Table10Peer::retrieveRoot(1), 'retrieveRoot() returns null as long as no root node is defined in the required scope');
- $t2 = new Table10();
- $t2->setLeftValue(1);
- $t2->setRightValue(2);
- $t2->setScopeValue(1);
- $t2->save();
- $this->assertEquals(Table10Peer::retrieveRoot(1), $t2, 'retrieveRoot() retrieves the root node in the required scope');
- }
-
- public function testRetrieveTree()
- {
- 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 = Table10Peer::retrieveTree(1);
- $this->assertEquals(array($t1, $t2, $t3, $t4, $t5, $t6, $t7), $tree, 'retrieveTree() retrieves the scoped tree');
- $tree = Table10Peer::retrieveTree(2);
- $this->assertEquals(array($t8, $t9, $t10), $tree, 'retrieveTree() retrieves the scoped tree');
- $c = new Criteria();
- $c->add(Table10Peer::LEFT_COL, 4, Criteria::GREATER_EQUAL);
- $tree = Table10Peer::retrieveTree(1, $c);
- $this->assertEquals(array($t3, $t4, $t5, $t6, $t7), $tree, 'retrieveTree() accepts a Criteria as first parameter');
- }
-
- public function testDeleteTree()
- {
- $this->initTreeWithScope();
- Table10Peer::deleteTree(1);
- $expected = array(
- 't8' => array(1, 6, 0),
- 't9' => array(2, 3, 1),
- 't10' => array(4, 5, 1),
- );
- $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'deleteTree() does not delete anything out of the scope');
- }
-
- public function testShiftRLValues()
- {
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table10Peer', 'shiftRLValues'), 'nested_set adds a shiftRLValues() method');
- $this->initTreeWithScope();
- Table10Peer::shiftRLValues(1, 100, null, 1);
- Table10Peer::clearInstancePool();
- $expected = array(
- 't1' => array(1, 14, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 13, 1),
- 't4' => array(5, 6, 2),
- 't5' => array(7, 12, 2),
- 't6' => array(8, 9, 3),
- 't7' => array(10, 11, 3),
- );
- $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues does not shift anything when the first parameter is higher than the highest right value');
- $expected = array(
- 't8' => array(1, 6, 0),
- 't9' => array(2, 3, 1),
- 't10' => array(4, 5, 1),
- );
- $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
- $this->initTreeWithScope();
- Table10Peer::shiftRLValues(1, 1, null, 1);
- Table10Peer::clearInstancePool();
- $expected = array(
- 't1' => array(2, 15, 0),
- 't2' => array(3, 4, 1),
- 't3' => array(5, 14, 1),
- 't4' => array(6, 7, 2),
- 't5' => array(8, 13, 2),
- 't6' => array(9, 10, 3),
- 't7' => array(11, 12, 3),
- );
- $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues can shift all nodes to the right');
- $expected = array(
- 't8' => array(1, 6, 0),
- 't9' => array(2, 3, 1),
- 't10' => array(4, 5, 1),
- );
- $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
- $this->initTreeWithScope();
- Table10Peer::shiftRLValues(-1, 1, null, 1);
- Table10Peer::clearInstancePool();
- $expected = array(
- 't1' => array(0, 13, 0),
- 't2' => array(1, 2, 1),
- 't3' => array(3, 12, 1),
- 't4' => array(4, 5, 2),
- 't5' => array(6, 11, 2),
- 't6' => array(7, 8, 3),
- 't7' => array(9, 10, 3),
- );
- $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues can shift all nodes to the left');
- $expected = array(
- 't8' => array(1, 6, 0),
- 't9' => array(2, 3, 1),
- 't10' => array(4, 5, 1),
- );
- $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
- $this->initTreeWithScope();
- Table10Peer::shiftRLValues(1, 5, null, 1);
- Table10Peer::clearInstancePool();
- $expected = array(
- 't1' => array(1, 15, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 14, 1),
- 't4' => array(6, 7, 2),
- 't5' => array(8, 13, 2),
- 't6' => array(9, 10, 3),
- 't7' => array(11, 12, 3),
- );
- $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues can shift some nodes to the right');
- $expected = array(
- 't8' => array(1, 6, 0),
- 't9' => array(2, 3, 1),
- 't10' => array(4, 5, 1),
- );
- $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
- }
-
- public function testShiftLevel()
- {
- $this->initTreeWithScope();
- Table10Peer::shiftLevel($delta = 1, $first = 7, $last = 12, $scope = 1);
- Table10Peer::clearInstancePool();
- $expected = array(
- 't1' => array(1, 14, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 13, 1),
- 't4' => array(5, 6, 2),
- 't5' => array(7, 12, 3),
- 't6' => array(8, 9, 4),
- 't7' => array(10, 11, 4),
- );
- $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftLevel can shift level with a scope');
- $expected = array(
- 't8' => array(1, 6, 0),
- 't9' => array(2, 3, 1),
- 't10' => array(4, 5, 1),
- );
- $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftLevel does not shift anything out of the scope');
- }
-
- public function testMakeRoomForLeaf()
- {
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\Table10Peer', 'makeRoomForLeaf'), 'nested_set adds a makeRoomForLeaf() method');
- $fixtures = $this->initTreeWithScope();
- /* Tree used for tests
- Scope 1
- t1
- | \
- t2 t3
- | \
- t4 t5
- | \
- t6 t7
- Scope 2
- t8
- | \
- t9 t10
- */
- $t = Table10Peer::makeRoomForLeaf(5, 1); // first child of t3
- $expected = array(
- 't1' => array(1, 16, 0),
- 't2' => array(2, 3, 1),
- 't3' => array(4, 15, 1),
- 't4' => array(7, 8, 2),
- 't5' => array(9, 14, 2),
- 't6' => array(10, 11, 3),
- 't7' => array(12, 13, 3),
- );
- $this->assertEquals($expected, $this->dumpTreeWithScope(1), 'makeRoomForLeaf() shifts the other nodes correctly');
- $expected = array(
- 't8' => array(1, 6, 0),
- 't9' => array(2, 3, 1),
- 't10' => array(4, 5, 1),
- );
- $this->assertEquals($expected, $this->dumpTreeWithScope(2), 'makeRoomForLeaf() does not shift anything out of the scope');
- }
-}
View
341 ...s/Propel/Tests/Generator/Behavior/NestedSet/NestedSetBehaviorQueryBuilderModifierTest.php
@@ -10,6 +10,7 @@
namespace Propel\Tests\Generator\Behavior\NestedSet;
+use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Collection\ObjectCollection;
/**
@@ -247,18 +248,23 @@ public function testOrderByLevel()
public function testFindRoot()
{
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\\NestedSetTable9Query', 'findRoot'), 'nested_set adds a findRoot() method');
+ $this->assertTrue(method_exists('NestedSetTable9Query', 'findRoot'), 'nested_set adds a findRoot() method');
+
\NestedSetTable9Query::create()->deleteAll();
$this->assertNull(\NestedSetTable9Query::create()->findRoot(), 'findRoot() returns null as long as no root node is defined');
- $t1 = new Table9();
+
+ $t1 = new \NestedSetTable9();
$t1->setLeftValue(123);
$t1->setRightValue(456);
$t1->save();
+
$this->assertNull(\NestedSetTable9Query::create()->findRoot(), 'findRoot() returns null as long as no root node is defined');
- $t2 = new Table9();
+
+ $t2 = new \NestedSetTable9();
$t2->setLeftValue(1);
$t2->setRightValue(2);
$t2->save();
+
$this->assertEquals(\NestedSetTable9Query::create()->findRoot(), $t2, 'findRoot() retrieves the root node');
}
@@ -278,4 +284,333 @@ protected function buildCollection($arr)
return $coll;
}
+
+ public function testRetrieveRoot()
+ {
+ $this->assertTrue(
+ method_exists('NestedSetTable9Query', 'retrieveRoot'),
+ 'nested_set adds a retrieveRoot() method'
+ );
+
+ \NestedSetTable9Peer::doDeleteAll();
+ $this->assertNull(\NestedSetTable9Query::retrieveRoot(), 'retrieveRoot() returns null as long as no root node is defined');
+
+ $t1 = new \NestedSetTable9();
+ $t1->setLeftValue(123);
+ $t1->setRightValue(456);
+ $t1->save();
+
+ $this->assertNull(\NestedSetTable9Query::retrieveRoot(), 'retrieveRoot() returns null as long as no root node is defined');
+
+ $t2 = new \NestedSetTable9();
+ $t2->setLeftValue(1);
+ $t2->setRightValue(2);
+ $t2->save();
+
+ $this->assertEquals(\NestedSetTable9Query::retrieveRoot(), $t2, 'retrieveRoot() retrieves the root node');
+ }
+
+ public function testRetrieveTree()
+ {
+ list($t1, $t2, $t3, $t4, $t5, $t6, $t7) = $this->initTree();
+ $tree = \NestedSetTable9Query::retrieveTree();
+ $this->assertEquals(array($t1, $t2, $t3, $t4, $t5, $t6, $t7), $tree, 'retrieveTree() retrieves the whole tree');
+ $c = new Criteria();
+ $c->add(\NestedSetTable9::LEFT_COL, 4, Criteria::GREATER_EQUAL);
+ $tree = \NestedSetTable9Query::retrieveTree($c);
+ $this->assertEquals(array($t3, $t4, $t5, $t6, $t7), $tree, 'retrieveTree() accepts a Criteria as first parameter');
+ }
+
+ public function testIsValid()
+ {
+ $this->assertTrue(method_exists('NestedSetTable9Query', 'isValid'), 'nested_set adds an isValid() method');
+ $this->assertFalse(\NestedSetTable9Query::isValid(null), 'isValid() returns false when passed null ');
+ $t1 = new \NestedSetTable9();
+ $this->assertFalse(\NestedSetTable9Query::isValid($t1), 'isValid() returns false when passed an empty node object');
+ $t2 = new \NestedSetTable9();
+ $t2->setLeftValue(5)->setRightValue(2);
+ $this->assertFalse(\NestedSetTable9Query::isValid($t2), 'isValid() returns false when passed a node object with left > right');
+ $t3 = new \NestedSetTable9();
+ $t3->setLeftValue(5)->setRightValue(5);
+ $this->assertFalse(\NestedSetTable9Query::isValid($t3), 'isValid() returns false when passed a node object with left = right');
+ $t4 = new \NestedSetTable9();
+ $t4->setLeftValue(2)->setRightValue(5);
+ $this->assertTrue(\NestedSetTable9Query::isValid($t4), 'isValid() returns true when passed a node object with left < right');
+ }
+
+ public function testDeleteTree()
+ {
+ $this->initTree();
+ \NestedSetTable9Query::deleteTree();
+ $this->assertEquals(array(), \NestedSetTable9Peer::doSelect(new Criteria()), 'deleteTree() deletes the whole tree');
+ }
+
+ public function testShiftRLValuesDelta()
+ {
+ $this->initTree();
+ \NestedSetTable9Query::shiftRLValues($delta = 1, $left = 1);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(2, 15, 0),
+ 't2' => array(3, 4, 1),
+ 't3' => array(5, 14, 1),
+ 't4' => array(6, 7, 2),
+ 't5' => array(8, 13, 2),
+ 't6' => array(9, 10, 3),
+ 't7' => array(11, 12, 3),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts all nodes with a positive amount');
+ $this->initTree();
+ \NestedSetTable9Query::shiftRLValues($delta = -1, $left = 1);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(0, 13, 0),
+ 't2' => array(1, 2, 1),
+ 't3' => array(3, 12, 1),
+ 't4' => array(4, 5, 2),
+ 't5' => array(6, 11, 2),
+ 't6' => array(7, 8, 3),
+ 't7' => array(9, 10, 3),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues can shift all nodes with a negative amount');
+ $this->initTree();
+ \NestedSetTable9Query::shiftRLValues($delta = 3, $left = 1);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1'=> array(4, 17, 0),
+ 't2' => array(5, 6, 1),
+ 't3' => array(7, 16, 1),
+ 't4' => array(8, 9, 2),
+ 't5' => array(10, 15, 2),
+ 't6' => array(11, 12, 3),
+ 't7' => array(13, 14, 3),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts all nodes several units to the right');
+ \NestedSetTable9Query::shiftRLValues($delta = -3, $left = 1);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(1, 14, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 13, 1),
+ 't4' => array(5, 6, 2),
+ 't5' => array(7, 12, 2),
+ 't6' => array(8, 9, 3),
+ 't7' => array(10, 11, 3),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts all nodes several units to the left');
+ }
+
+ public function testShiftRLValuesLeftLimit()
+ {
+ $this->initTree();
+ \NestedSetTable9Query::shiftRLValues($delta = 1, $left = 15);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(1, 14, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 13, 1),
+ 't4' => array(5, 6, 2),
+ 't5' => array(7, 12, 2),
+ 't6' => array(8, 9, 3),
+ 't7' => array(10, 11, 3),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues does not shift anything when the left parameter is higher than the highest right value');
+ $this->initTree();
+ \NestedSetTable9Query::shiftRLValues($delta = 1, $left = 5);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(1, 15, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 14, 1),
+ 't4' => array(6, 7, 2),
+ 't5' => array(8, 13, 2),
+ 't6' => array(9, 10, 3),
+ 't7' => array(11, 12, 3),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts only the nodes having a LR value higher than the given left parameter');
+ $this->initTree();
+ \NestedSetTable9Query::shiftRLValues($delta = 1, $left = 1);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1'=> array(2, 15, 0),
+ 't2' => array(3, 4, 1),
+ 't3' => array(5, 14, 1),
+ 't4' => array(6, 7, 2),
+ 't5' => array(8, 13, 2),
+ 't6' => array(9, 10, 3),
+ 't7' => array(11, 12, 3),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts all nodes when the left parameter is 1');
+ }
+
+ public function testShiftRLValuesRightLimit()
+ {
+ $this->initTree();
+ \NestedSetTable9Query::shiftRLValues($delta = 1, $left = 1, $right = 0);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(1, 14, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 13, 1),
+ 't4' => array(5, 6, 2),
+ 't5' => array(7, 12, 2),
+ 't6' => array(8, 9, 3),
+ 't7' => array(10, 11, 3),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues does not shift anything when the right parameter is 0');
+ $this->initTree();
+ \NestedSetTable9Query::shiftRLValues($delta = 1, $left = 1, $right = 5);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(2, 14, 0),
+ 't2' => array(3, 4, 1),
+ 't3' => array(5, 13, 1),
+ 't4' => array(6, 6, 2),
+ 't5' => array(7, 12, 2),
+ 't6' => array(8, 9, 3),
+ 't7' => array(10, 11, 3),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shiftRLValues shifts only the nodes having a LR value lower than the given right parameter');
+ $this->initTree();
+ \NestedSetTable9Query::shiftRLValues($delta = 1, $left = 1, $right = 15);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1'=> array(2, 15, 0),
+ 't2' => array(3, 4, 1),
+ 't3' => array(5, 14, 1),
+ 't4' => array(6, 7, 2),
+ 't5' => array(8, 13, 2),
+ 't6' => array(9, 10, 3),
+ 't7' => array(11, 12, 3),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftRLValues shifts all nodes when the right parameter is higher than the highest right value');
+ }
+
+ public function testShiftLevel()
+ {
+ /* Tree used for tests
+ t1
+ | \
+ t2 t3
+ | \
+ t4 t5
+ | \
+ t6 t7
+ */
+ $this->initTree();
+ \NestedSetTable9Query::shiftLevel($delta = 1, $first = 7, $last = 12);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(1, 14, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 13, 1),
+ 't4' => array(5, 6, 2),
+ 't5' => array(7, 12, 3),
+ 't6' => array(8, 9, 4),
+ 't7' => array(10, 11, 4),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftLevel shifts all nodes with a left value between the first and last');
+ $this->initTree();
+ \NestedSetTable9Query::shiftLevel($delta = -1, $first = 7, $last = 12);
+ \NestedSetTable9Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(1, 14, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 13, 1),
+ 't4' => array(5, 6, 2),
+ 't5' => array(7, 12, 1),
+ 't6' => array(8, 9, 2),
+ 't7' => array(10, 11, 2),
+ );
+ $this->assertEquals($this->dumpTree(), $expected, 'shiftLevel shifts all nodes wit ha negative amount');
+ }
+
+ public function testUpdateLoadedNodes()
+ {
+ $this->assertTrue(method_exists('NestedSetTable9Query', 'updateLoadedNodes'), 'nested_set adds a updateLoadedNodes() method');
+ $fixtures = $this->initTree();
+ \NestedSetTable9Query::shiftRLValues(1, 5);
+ $expected = array(
+ 't1' => array(1, 14),
+ 't2' => array(2, 3),
+ 't3' => array(4, 13),
+ 't4' => array(5, 6),
+ 't5' => array(7, 12),
+ 't6' => array(8, 9),
+ 't7' => array(10, 11),
+ );
+ $actual = array();
+ foreach ($fixtures as $t) {
+ $actual[$t->getTitle()] = array($t->getLeftValue(), $t->getRightValue());
+ }
+ $this->assertEquals($actual, $expected, 'Loaded nodes are not in sync before calling updateLoadedNodes()');
+ \NestedSetTable9Query::updateLoadedNodes();
+ $expected = array(
+ 't1' => array(1, 15),
+ 't2' => array(2, 3),
+ 't3' => array(4, 14),
+ 't4' => array(6, 7),
+ 't5' => array(8, 13),
+ 't6' => array(9, 10),
+ 't7' => array(11, 12),
+ );
+ $actual = array();
+ foreach ($fixtures as $t) {
+ $actual[$t->getTitle()] = array($t->getLeftValue(), $t->getRightValue());
+ }
+ $this->assertEquals($actual, $expected, 'Loaded nodes are in sync after calling updateLoadedNodes()');
+ }
+
+ public function testMakeRoomForLeaf()
+ {
+ $this->assertTrue(method_exists('NestedSetTable9Query', 'makeRoomForLeaf'), 'nested_set adds a makeRoomForLeaf() method');
+ list($t1, $t2, $t3, $t4, $t5, $t6, $t7) = $this->initTree();
+ /* Tree used for tests
+ t1
+ | \
+ t2 t3
+ | \
+ t4 t5
+ | \
+ t6 t7
+ */
+ $t = \NestedSetTable9Query::makeRoomForLeaf(5); // first child of t3
+ $expected = array(
+ 't1' => array(1, 16, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 15, 1),
+ 't4' => array(7, 8, 2),
+ 't5' => array(9, 14, 2),
+ 't6' => array(10, 11, 3),
+ 't7' => array(12, 13, 3),
+ );
+ $this->assertEquals($expected, $this->dumpTree(), 'makeRoomForLeaf() shifts the other nodes correctly');
+ foreach ($expected as $key => $values) {
+ $this->assertEquals($values, array($$key->getLeftValue(), $$key->getRightValue(), $$key->getLevel()), 'makeRoomForLeaf() updates nodes already in memory');
+ }
+ }
+
+ public function testFixLevels()
+ {
+ $fixtures = $this->initTree();
+ // reset the levels
+ foreach ($fixtures as $node) {
+ $node->setLevel(null)->save();
+ }
+ // fix the levels
+ \NestedSetTable9Query::fixLevels();
+ $expected = array(
+ 't1' => array(1, 14, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 13, 1),
+ 't4' => array(5, 6, 2),
+ 't5' => array(7, 12, 2),
+ 't6' => array(8, 9, 3),
+ 't7' => array(10, 11, 3),
+ );
+ $this->assertEquals($expected, $this->dumpTree(), 'fixLevels() fixes the levels correctly');
+
+ \NestedSetTable9Query::fixLevels();
+ $this->assertEquals($expected, $this->dumpTree(), 'fixLevels() can be called several times');
+ }
}
View
236 ...Tests/Generator/Behavior/NestedSet/NestedSetBehaviorQueryBuilderModifierWithScopeTest.php
@@ -10,6 +10,7 @@
namespace Propel\Tests\Generator\Behavior\NestedSet;
+use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Collection\ObjectCollection;
/**
@@ -225,7 +226,7 @@ public function testRootsOf()
public function testFindRoot()
{
- $this->assertTrue(method_exists('\Propel\Tests\Bookstore\Behavior\\NestedSetTable10Query', 'findRoot'), 'nested_set adds a findRoot() method');
+ $this->assertTrue(method_exists('NestedSetTable10Query', 'findRoot'), 'nested_set adds a findRoot() method');
\NestedSetTable10Query::create()->deleteAll();
$this->assertNull(\NestedSetTable10Query::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();
@@ -304,4 +305,237 @@ protected function buildCollection($arr)
return $coll;
}
+ public function testRetrieveRoots()
+ {
+ $this->assertTrue(
+ method_exists('NestedSetTable10Query', 'retrieveRoots'),
+ 'nested_set adds a retrieveRoots() method for trees that use scope'
+ );
+ $this->assertFalse(
+ method_exists('NestedSetTable9Query', 'retrieveRoots'),
+ "nested_set does not add a retrieveRoots() method for trees that don't use scope"
+ );
+
+ 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(array($t1, $t8), \NestedSetTable10Query::retrieveRoots(), 'retrieveRoots() returns the tree roots');
+ $c = new Criteria();
+ $c->add(\Map\NestedSetTable10TableMap::TITLE, 't1');
+ $this->assertEquals(array($t1), \NestedSetTable10Query::retrieveRoots($c), 'retrieveRoots() accepts a Criteria as first parameter');
+ }
+
+ public function testRetrieveRoot()
+ {
+ $this->assertTrue(method_exists('NestedSetTable10Query', 'retrieveRoot'), 'nested_set adds a retrieveRoot() method');
+ \NestedSetTable10Peer::doDeleteAll();
+
+ $t1 = new \NestedSetTable10();
+ $t1->setLeftValue(1);
+ $t1->setRightValue(2);
+ $t1->setScopeValue(2);
+ $t1->save();
+
+ $this->assertNull(\NestedSetTable10Query::retrieveRoot(1), 'retrieveRoot() returns null as long as no root node is defined in the required scope');
+
+ $t2 = new \NestedSetTable10();
+ $t2->setLeftValue(1);
+ $t2->setRightValue(2);
+ $t2->setScopeValue(1);
+ $t2->save();
+
+ $this->assertEquals(\NestedSetTable10Query::retrieveRoot(1), $t2, 'retrieveRoot() retrieves the root node in the required scope');
+ }
+
+ public function testRetrieveTree()
+ {
+ 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 = \NestedSetTable10Query::retrieveTree(1);
+ $this->assertEquals(array($t1, $t2, $t3, $t4, $t5, $t6, $t7), $tree, 'retrieveTree() retrieves the scoped tree');
+ $tree = \NestedSetTable10Query::retrieveTree(2);
+ $this->assertEquals(array($t8, $t9, $t10), $tree, 'retrieveTree() retrieves the scoped tree');
+ $c = new Criteria();
+ $c->add(\NestedSetTable10::LEFT_COL, 4, Criteria::GREATER_EQUAL);
+ $tree = \NestedSetTable10Query::retrieveTree(1, $c);
+ $this->assertEquals(array($t3, $t4, $t5, $t6, $t7), $tree, 'retrieveTree() accepts a Criteria as first parameter');
+ }
+
+ public function testDeleteTree()
+ {
+ $this->initTreeWithScope();
+ \NestedSetTable10Query::deleteTree(1);
+ $expected = array(
+ 't8' => array(1, 6, 0),
+ 't9' => array(2, 3, 1),
+ 't10' => array(4, 5, 1),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'deleteTree() does not delete anything out of the scope');
+ }
+
+ public function testShiftRLValues()
+ {
+ $this->assertTrue(method_exists('NestedSetTable10Query', 'shiftRLValues'), 'nested_set adds a shiftRLValues() method');
+ $this->initTreeWithScope();
+ \NestedSetTable10Query::shiftRLValues(1, 100, null, 1);
+ \NestedSetTable10Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(1, 14, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 13, 1),
+ 't4' => array(5, 6, 2),
+ 't5' => array(7, 12, 2),
+ 't6' => array(8, 9, 3),
+ 't7' => array(10, 11, 3),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues does not shift anything when the first parameter is higher than the highest right value');
+ $expected = array(
+ 't8' => array(1, 6, 0),
+ 't9' => array(2, 3, 1),
+ 't10' => array(4, 5, 1),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
+ $this->initTreeWithScope();
+ \NestedSetTable10Query::shiftRLValues(1, 1, null, 1);
+ \NestedSetTable10Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(2, 15, 0),
+ 't2' => array(3, 4, 1),
+ 't3' => array(5, 14, 1),
+ 't4' => array(6, 7, 2),
+ 't5' => array(8, 13, 2),
+ 't6' => array(9, 10, 3),
+ 't7' => array(11, 12, 3),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues can shift all nodes to the right');
+ $expected = array(
+ 't8' => array(1, 6, 0),
+ 't9' => array(2, 3, 1),
+ 't10' => array(4, 5, 1),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
+ $this->initTreeWithScope();
+ \NestedSetTable10Query::shiftRLValues(-1, 1, null, 1);
+ \NestedSetTable10Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(0, 13, 0),
+ 't2' => array(1, 2, 1),
+ 't3' => array(3, 12, 1),
+ 't4' => array(4, 5, 2),
+ 't5' => array(6, 11, 2),
+ 't6' => array(7, 8, 3),
+ 't7' => array(9, 10, 3),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues can shift all nodes to the left');
+ $expected = array(
+ 't8' => array(1, 6, 0),
+ 't9' => array(2, 3, 1),
+ 't10' => array(4, 5, 1),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
+ $this->initTreeWithScope();
+ \NestedSetTable10Query::shiftRLValues(1, 5, null, 1);
+ \NestedSetTable10Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(1, 15, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 14, 1),
+ 't4' => array(6, 7, 2),
+ 't5' => array(8, 13, 2),
+ 't6' => array(9, 10, 3),
+ 't7' => array(11, 12, 3),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues can shift some nodes to the right');
+ $expected = array(
+ 't8' => array(1, 6, 0),
+ 't9' => array(2, 3, 1),
+ 't10' => array(4, 5, 1),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
+ }
+
+ public function testShiftLevel()
+ {
+ $this->initTreeWithScope();
+ \NestedSetTable10Query::shiftLevel($delta = 1, $first = 7, $last = 12, $scope = 1);
+ \NestedSetTable10Peer::clearInstancePool();
+ $expected = array(
+ 't1' => array(1, 14, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 13, 1),
+ 't4' => array(5, 6, 2),
+ 't5' => array(7, 12, 3),
+ 't6' => array(8, 9, 4),
+ 't7' => array(10, 11, 4),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftLevel can shift level with a scope');
+ $expected = array(
+ 't8' => array(1, 6, 0),
+ 't9' => array(2, 3, 1),
+ 't10' => array(4, 5, 1),
+ );
+ $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftLevel does not shift anything out of the scope');
+ }
+
+ public function testMakeRoomForLeaf()
+ {
+ $this->assertTrue(method_exists('NestedSetTable10Query', 'makeRoomForLeaf'), 'nested_set adds a makeRoomForLeaf() method');
+ $fixtures = $this->initTreeWithScope();
+ /* Tree used for tests
+ Scope 1
+ t1
+ | \
+ t2 t3
+ | \
+ t4 t5
+ | \
+ t6 t7
+ Scope 2
+ t8
+ | \
+ t9 t10
+ */
+ $t = \NestedSetTable10Query::makeRoomForLeaf(5, 1); // first child of t3
+ $expected = array(
+ 't1' => array(1, 16, 0),
+ 't2' => array(2, 3, 1),
+ 't3' => array(4, 15, 1),
+ 't4' => array(7, 8, 2),
+ 't5' => array(9, 14, 2),
+ 't6' => array(10, 11, 3),
+ 't7' => array(12, 13, 3),
+ );
+ $this->assertEquals($expected, $this->dumpTreeWithScope(1), 'makeRoomForLeaf() shifts the other nodes correctly');
+ $expected = array(
+ 't8' => array(1, 6, 0),
+ 't9' => array(2, 3, 1),
+ 't10' => array(4, 5, 1),
+ );
+ $this->assertEquals($expected, $this->dumpTreeWithScope(2), 'makeRoomForLeaf() does not shift anything out of the scope');
+ }
}
View
9 tests/Propel/Tests/Generator/Behavior/NestedSet/PublicTable10.php
@@ -1,9 +0,0 @@
-<?php
-
-namespace Propel\Tests\Generator\Behavior\NestedSet;
-
-class PublicTable10 extends \NestedSetTable10
-{
- public $hasParentNode = null;
- public $parentNode = null;
-}
View
13 tests/Propel/Tests/Generator/Behavior/NestedSet/PublicTable9.php
@@ -1,13 +0,0 @@
-<?php
-
-namespace Propel\Tests\Generator\Behavior\NestedSet;
-
-class PublicTable9 extends \NestedSetTable9
-{
- public $hasParentNode = null;
- public $parentNode = null;
- public $hasPrevSibling = null;
- public $prevSibling = null;
- public $hasNextSibling = null;
- public $nextSibling = null;
-}

0 comments on commit 090db6a

Please sign in to comment.
Something went wrong with that request. Please try again.