/** * Tree used for tests * t1 * | \ * t2 t3 * | \ * t4 t5 * | \ * t6 t7 */ protected function initTree() { Table9Peer::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 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 testRetrieveRoot() { $this->assertTrue(method_exists('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 testAddChild() { Table9Peer::doDeleteAll(); $t1 = new Table9(); $t1->setTitle('t1'); $t1->makeRoot(); $t1->save(); $t2 = new Table9(); $t2->setTitle('t2'); $t1->addChild($t2); $t2->save(); $t3 = new Table9(); $t3->setTitle('t3'); $t1->addChild($t3); $t3->save(); $t4 = new Table9(); $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'); }