/**
  * 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 testInsertAsNextSiblingOf()
 {
     $this->assertTrue(method_exists('Table9', 'insertAsNextSiblingOf'), 'nested_set adds a insertAsNextSiblingOf() 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->insertAsNextSiblingOf($t3);
     $this->assertEquals($t8, $t, 'insertAsNextSiblingOf() returns the object it was called on');
     $this->assertEquals(14, $t1->getRightValue(), 'insertAsNextSiblingOf() does not modify the tree until the object is saved');
     $t8->save();
     $this->assertEquals(14, $t8->getLeftValue(), 'insertAsNextSiblingOf() sets the left value correctly');
     $this->assertEquals(15, $t8->getRightValue(), 'insertAsNextSiblingOf() sets the right value correctly');
     $this->assertEquals(1, $t8->getLevel(), 'insertAsNextSiblingOf() sets the level correctly');
     $expected = array('t1' => array(1, 16, 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), 't8' => array(14, 15, 1));
     $this->assertEquals($expected, $this->dumpTree(), 'insertAsNextSiblingOf() shifts the other nodes correctly');
     try {
         $t8->insertAsNextSiblingOf($t4);
         $this->fail('insertAsNextSiblingOf() throws an exception when called on a saved object');
     } catch (PropelException $e) {
         $this->assertTrue(true, 'insertAsNextSiblingOf() throws an exception when called on a saved object');
     }
 }