public function testSimpleTreePositionedInserts()
 {
     $repo = $this->em->getRepository(self::CATEGORY);
     // test child positioned inserts
     $food = new Category();
     $food->setTitle('Food');
     $repo->persistAsFirstChild($food);
     $fruits = new Category();
     $fruits->setTitle('Fruits');
     $fruits->setParent($food);
     $repo->persistAsFirstChild($fruits);
     $vegitables = new Category();
     $vegitables->setTitle('Vegitables');
     $vegitables->setParent($food);
     $repo->persistAsFirstChild($vegitables);
     $milk = new Category();
     $milk->setTitle('Milk');
     $milk->setParent($food);
     $repo->persistAsLastChild($milk);
     $meat = new Category();
     $meat->setTitle('Meat');
     $meat->setParent($food);
     $repo->persistAsLastChild($meat);
     $this->em->flush();
     $this->assertEquals(4, $fruits->getLeft());
     $this->assertEquals(5, $fruits->getRight());
     $this->assertEquals(2, $vegitables->getLeft());
     $this->assertEquals(3, $vegitables->getRight());
     $this->assertEquals(6, $milk->getLeft());
     $this->assertEquals(7, $milk->getRight());
     $this->assertEquals(8, $meat->getLeft());
     $this->assertEquals(9, $meat->getRight());
     // test sibling positioned inserts
     $cookies = new Category();
     $cookies->setTitle('Cookies');
     $cookies->setParent($milk);
     $repo->persistAsNextSibling($cookies);
     $drinks = new Category();
     $drinks->setTitle('Drinks');
     $drinks->setParent($milk);
     $repo->persistAsPrevSibling($drinks);
     $this->em->flush();
     $this->assertEquals(6, $drinks->getLeft());
     $this->assertEquals(7, $drinks->getRight());
     $this->assertEquals(10, $cookies->getLeft());
     $this->assertEquals(11, $cookies->getRight());
     $this->assertTrue($repo->verify());
 }
 private function populate()
 {
     $root = new Category();
     $root->setTitle("Food");
     $root2 = new Category();
     $root2->setTitle("Sports");
     $child = new Category();
     $child->setTitle("Fruits");
     $child->setParent($root);
     $child2 = new Category();
     $child2->setTitle("Vegitables");
     $child2->setParent($root);
     $childsChild = new Category();
     $childsChild->setTitle("Carrots");
     $childsChild->setParent($child2);
     $potatoes = new Category();
     $potatoes->setTitle("Potatoes");
     $potatoes->setParent($child2);
     $this->em->persist($root);
     $this->em->persist($root2);
     $this->em->persist($child);
     $this->em->persist($child2);
     $this->em->persist($childsChild);
     $this->em->persist($potatoes);
     $this->em->flush();
     $this->em->clear();
 }
Пример #3
0
 public function testIssue33()
 {
     $repo = $this->em->getRepository(self::CATEGORY);
     $root = new Category();
     $root->setTitle('root');
     $node1 = new Category();
     $node1->setTitle('node1');
     $node1->setParent($root);
     $node2 = new Category();
     $node2->setTitle('node2');
     $node2->setParent($root);
     $subNode = new Category();
     $subNode->setTitle('sub-node');
     $subNode->setParent($node2);
     $this->em->persist($root);
     $this->em->persist($node1);
     $this->em->persist($node2);
     $this->em->persist($subNode);
     $this->em->flush();
     $this->em->clear();
     $subNode = $repo->findOneByTitle('sub-node');
     $node1 = $repo->findOneByTitle('node1');
     $subNode->setParent($node1);
     $this->em->persist($subNode);
     $this->em->flush();
     $this->em->clear();
     $meta = $this->em->getClassMetadata(self::CATEGORY);
     $subNode = $repo->findOneByTitle('sub-node');
     $left = $meta->getReflectionProperty('lft')->getValue($subNode);
     $right = $meta->getReflectionProperty('rgt')->getValue($subNode);
     $this->assertEquals(3, $left);
     $this->assertEquals(4, $right);
     $node1 = $repo->findOneByTitle('node1');
     $left = $meta->getReflectionProperty('lft')->getValue($node1);
     $right = $meta->getReflectionProperty('rgt')->getValue($node1);
     $this->assertEquals(2, $left);
     $this->assertEquals(5, $right);
 }
 private function populate()
 {
     $root = new Category();
     $root->setTitle("Root");
     $root2 = new Category();
     $root2->setTitle("Root2");
     $child = new Category();
     $child->setTitle("child");
     $child->setParent($root);
     $child2 = new Category();
     $child2->setTitle("child2");
     $child2->setParent($root);
     $childsChild = new Category();
     $childsChild->setTitle("childs2_child");
     $childsChild->setParent($child2);
     $this->em->persist($root);
     $this->em->persist($root2);
     $this->em->persist($child);
     $this->em->persist($child2);
     $this->em->persist($childsChild);
     $this->em->flush();
     $this->em->clear();
 }