public function testInsertAsPrevSiblingOf() { $this->assertTrue(method_exists('Table9', 'insertAsPrevSiblingOf'), 'nested_set adds a insertAsPrevSiblingOf() method'); list($t1, $t2, $t3, $t4, $t5, $t6, $t7) = $this->initTree(); /* Tree used for tests t1 | \ t2 t3 | \ t4 t5 | \ t6 t7 */ $t8 = new PublicTable9(); $t8->setTitle('t8'); $t = $t8->insertAsPrevSiblingOf($t3); $this->assertEquals($t8, $t, 'insertAsPrevSiblingOf() returns the object it was called on'); $this->assertEquals(4, $t3->getLeftValue(), 'insertAsPrevSiblingOf() does not modify the tree until the object is saved'); $t8->save(); $this->assertEquals(4, $t8->getLeftValue(), 'insertAsPrevSiblingOf() sets the left value correctly'); $this->assertEquals(5, $t8->getRightValue(), 'insertAsPrevSiblingOf() sets the right value correctly'); $this->assertEquals(1, $t8->getLevel(), 'insertAsPrevSiblingOf() sets the level correctly'); $expected = array('t1' => array(1, 16, 0), 't2' => array(2, 3, 1), 't3' => array(6, 15, 1), 't4' => array(7, 8, 2), 't5' => array(9, 14, 2), 't6' => array(10, 11, 3), 't7' => array(12, 13, 3), 't8' => array(4, 5, 1)); $this->assertEquals($expected, $this->dumpTree(), 'insertAsPrevSiblingOf() shifts the other nodes correctly'); try { $t8->insertAsPrevSiblingOf($t4); $this->fail('insertAsPrevSiblingOf() throws an exception when called on a saved object'); } catch (PropelException $e) { $this->assertTrue(true, 'insertAsPrevSiblingOf() throws an exception when called on a saved object'); } }