public function testInsertAsNextSiblingOfExistingObject() { \NestedSetTable9Query::create()->deleteAll(); $t = new \NestedSetTable9(); $t->makeRoot(); $t->save(); $t1 = new \NestedSetTable9(); $t1->insertAsFirstChildOf($t); $t1->save(); $this->assertEquals(1, $t->getLeftValue()); $this->assertEquals(4, $t->getRightValue()); $this->assertEquals(0, $t->getLevel()); $this->assertEquals(2, $t1->getLeftValue()); $this->assertEquals(3, $t1->getRightValue()); $this->assertEquals(1, $t1->getLevel()); $t2 = new \NestedSetTable9(); $t2->save(); $t2->insertAsNextSiblingOf($t1); $this->assertEquals(4, $t2->getLeftValue()); $this->assertEquals(5, $t2->getRightValue()); $this->assertEquals(1, $t2->getLevel()); $t2->save(); $this->assertEquals(1, $t->getLeftValue()); $this->assertEquals(6, $t->getRightValue()); $this->assertEquals(0, $t->getLevel()); $this->assertEquals(2, $t1->getLeftValue()); $this->assertEquals(3, $t1->getRightValue()); $this->assertEquals(1, $t1->getLevel()); $this->assertEquals(4, $t2->getLeftValue()); $this->assertEquals(5, $t2->getRightValue()); $this->assertEquals(1, $t2->getLevel()); }
public function testRetrieveRoot() { $this->assertTrue(method_exists('NestedSetTable9Query', 'retrieveRoot'), 'nested_set adds a retrieveRoot() method'); \Map\NestedSetTable9TableMap::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'); }