public function testInsertAsNextSiblingOfExistingObject() { \NestedSetTable10Query::create()->deleteAll(); $t = new \NestedSetTable10(); $t->setScopeValue(34); $t->makeRoot(); $t->save(); $t1 = new \NestedSetTable10(); $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(34, $t1->getScopeValue()); $this->assertEquals(1, $t1->getLevel()); $t2 = new \NestedSetTable10(); $t2->save(); $t2->insertAsNextSiblingOf($t1); $this->assertEquals(4, $t2->getLeftValue()); $this->assertEquals(5, $t2->getRightValue()); $this->assertEquals(34, $t2->getScopeValue()); $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(34, $t1->getScopeValue()); $this->assertEquals(1, $t1->getLevel()); $this->assertEquals(4, $t2->getLeftValue()); $this->assertEquals(5, $t2->getRightValue()); $this->assertEquals(34, $t2->getScopeValue()); $this->assertEquals(1, $t2->getLevel()); }
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 = ['t1' => [1, 16, 0], 't2' => [2, 3, 1], 't3' => [4, 15, 1], 't4' => [7, 8, 2], 't5' => [9, 14, 2], 't6' => [10, 11, 3], 't7' => [12, 13, 3]]; $this->assertEquals($expected, $this->dumpTreeWithScope(1), 'makeRoomForLeaf() shifts the other nodes correctly'); $expected = ['t8' => [1, 6, 0], 't9' => [2, 3, 1], 't10' => [4, 5, 1]]; $this->assertEquals($expected, $this->dumpTreeWithScope(2), 'makeRoomForLeaf() does not shift anything out of the scope'); }
protected function dumpTreeWithScope($scope) { return $this->dumpNodes(\NestedSetTable10Query::create()->filterByMyScopeColumn($scope)->orderByTitle()->find()); }