/** * Tree used for tests * t1 * | \ * t2 t3 * | \ * t4 t5 * | \ * t6 t7 */ protected function initTree() { \Map\NestedSetTable9TableMap::doDeleteAll(); $ret = array(); // shuffling the results so the db order is not the natural one $fixtures = array('t2' => array(2, 3, 1), 't5' => array(7, 12, 2), 't4' => array(5, 6, 2), 't7' => array(10, 11, 3), 't1' => array(1, 14, 0), 't6' => array(8, 9, 3), 't3' => array(4, 13, 1)); /* in correct order, this is: '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), */ foreach ($fixtures as $key => $data) { $t = new Fixtures\PublicTable9(); $t->setTitle($key); $t->setLeftValue($data[0]); $t->setRightValue($data[1]); $t->setLevel($data[2]); $t->save(); $ret[$key] = $t; } // reordering the results in the fixtures ksort($ret); return array_values($ret); }
public function testDefault() { $table9 = \Map\NestedSetTable9TableMap::getTableMap(); $this->assertEquals(count($table9->getColumns()), 5, 'nested_set adds three column by default'); $this->assertTrue(method_exists('NestedSetTable9', 'getTreeLeft'), 'nested_set adds a tree_left column by default'); $this->assertTrue(method_exists('NestedSetTable9', 'getLeftValue'), 'nested_set maps the left_value getter with the tree_left column'); $this->assertTrue(method_exists('NestedSetTable9', 'getTreeRight'), 'nested_set adds a tree_right column by default'); $this->assertTrue(method_exists('NestedSetTable9', 'getRightValue'), 'nested_set maps the right_value getter with the tree_right column'); $this->assertTrue(method_exists('NestedSetTable9', 'getTreeLevel'), 'nested_set adds a tree_level column by default'); $this->assertTrue(method_exists('NestedSetTable9', 'getLevel'), 'nested_set maps the level getter with the tree_level column'); $this->assertFalse(method_exists('NestedSetTable9', 'getTreeScope'), 'nested_set does not add a tree_scope column by default'); $this->assertFalse(method_exists('NestedSetTable9', 'getScopeValue'), 'nested_set does not map the scope_value getter with the tree_scope column by default'); }
public function testAddChild() { \Map\NestedSetTable9TableMap::doDeleteAll(); $t1 = new \NestedSetTable9(); $t1->setTitle('t1'); $t1->makeRoot(); $t1->save(); $t2 = new \NestedSetTable9(); $t2->setTitle('t2'); $t1->addChild($t2); $t2->save(); $t3 = new \NestedSetTable9(); $t3->setTitle('t3'); $t1->addChild($t3); $t3->save(); $t4 = new \NestedSetTable9(); $t4->setTitle('t4'); $t2->addChild($t4); $t4->save(); $expected = array('t1' => array(1, 8, 0), 't2' => array(4, 7, 1), 't3' => array(2, 3, 1), 't4' => array(5, 6, 2)); $this->assertEquals($expected, $this->dumpTree(), 'addChild() adds the child and saves it'); }
public function testShiftLevel() { /* Tree used for tests t1 | \ t2 t3 | \ t4 t5 | \ t6 t7 */ $this->initTree(); \NestedSetTable9Query::shiftLevel($delta = 1, $first = 7, $last = 12); \Map\NestedSetTable9TableMap::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); \Map\NestedSetTable9TableMap::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'); }