Browse Source

[tests] add a test case based on #342

gedi 13 years ago
parent
commit
f975c1aa27
1 changed files with 29 additions and 0 deletions
  1. 29 0
      tests/Gedmo/Tree/NestedTreeRootRepositoryTest.php

+ 29 - 0
tests/Gedmo/Tree/NestedTreeRootRepositoryTest.php

@@ -30,6 +30,35 @@ class NestedTreeRootRepositoryTest extends BaseTestCaseORM
         $this->populate();
     }
 
+    /**
+     * Based on issue #342
+     *
+     * @test
+     */
+    function shouldBeAbleToShiftRootNode()
+    {
+        $repo = $this->em->getRepository(self::CATEGORY);
+
+        $food = $repo->findOneByTitle('Food');
+        $acme = new RootCategory;
+        $acme->setTitle('Acme');
+
+        $food->setParent($acme);
+
+        $this->em->persist($acme);
+        $this->em->persist($food);
+        $this->em->flush();
+
+        $this->assertNull($acme->getParent());
+        $this->assertSame($acme, $food->getParent());
+        $this->assertSame($acme->getId(), $acme->getRoot());
+        $this->assertSame($acme->getId(), $food->getRoot());
+        $this->assertSame(1, $acme->getLeft());
+        $this->assertSame(12, $acme->getRight());
+        $this->assertSame(2, $food->getLeft());
+        $this->assertSame(11, $food->getRight());
+    }
+
     /**
      * @test
      */