1<?php 2/** 3 * Doctrine_Ticket_838_TestCase 4 * 5 * @package Doctrine 6 * @author Jani Hartikainen <firstname at codeutopia net> 7 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL 8 * @category Object Relational Mapping 9 * @link www.doctrine-project.org 10 * @version $Revision$ 11 */ 12 13class Doctrine_Ticket_838_TestCase extends Doctrine_UnitTestCase 14{ 15 public function prepareTables() 16 { 17 $this->tables[] = 'NestedSetTest_SingleRootNode'; 18 parent::prepareTables(); 19 } 20 21 public function prepareData() 22 { 23 24 } 25 26 /** 27 * Test that the old root is placed correctly under the new root 28 */ 29 public function testMoveRoot() 30 { 31 $node = new NestedSetTest_SingleRootNode(); 32 $node->name = 'oldroot'; 33 $tree = $this->conn->getTable('NestedSetTest_SingleRootNode')->getTree(); 34 $tree->createRoot($node); 35 36 $oldRoot = $node->copy(); 37 // detach the node, so that it can be inserted as a new node 38 $oldRoot->getNode()->detach(); 39 40 $node->getNode()->delete(); 41 42 $this->assertTrue($oldRoot !== $node); 43 $this->assertEqual(0, $oldRoot['lft']); 44 $this->assertEqual(0, $oldRoot['rgt']); 45 $this->assertEqual(0, $oldRoot['level']); 46 47 $newRoot = new NestedSetTest_SingleRootNode(); 48 $newRoot->name = 'newroot'; 49 $tree->createRoot($newRoot); 50 $this->assertEqual(1, $newRoot['lft']); 51 $this->assertEqual(2, $newRoot['rgt']); 52 $this->assertEqual(0, $newRoot['level']); 53 54 $oldRoot->getNode()->insertAsFirstChildOf($newRoot); 55 56 $this->assertEqual(2, $oldRoot['lft']); 57 $this->assertEqual(3, $oldRoot['rgt']); 58 $this->assertEqual(1, $oldRoot['level']); 59 60 $newRoot->refresh(); 61 62 $this->assertEqual(1, $newRoot['lft']); 63 $this->assertEqual(4, $newRoot['rgt']); 64 $this->assertEqual(0, $newRoot['level']); 65 66 $children = $newRoot->getNode()->getChildren(); 67 $oldRoot = $children[0]; 68 69 $this->assertEqual(2, $oldRoot['lft']); 70 $this->assertEqual(3, $oldRoot['rgt']); 71 $this->assertEqual(1, $oldRoot['level']); 72 } 73}