瀏覽代碼

[tree] test case for setting parent to null

Gediminas Morkevicius 14 年之前
父節點
當前提交
97ff7885dd
共有 2 個文件被更改,包括 18 次插入1 次删除
  1. 1 1
      tests/Gedmo/Tree/Fixture/RootCategory.php
  2. 17 0
      tests/Gedmo/Tree/NestedTreeRootTest.php

+ 1 - 1
tests/Gedmo/Tree/Fixture/RootCategory.php

@@ -70,7 +70,7 @@ class RootCategory
         return $this->title;
     }
     
-    public function setParent($parent)
+    public function setParent(RootCategory $parent = null)
     {
         $this->parent = $parent;    
     }

+ 17 - 0
tests/Gedmo/Tree/NestedTreeRootTest.php

@@ -102,6 +102,23 @@ class NestedTreeRootTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(8, $node->getRight());
     }
     
+    public function testSetParentToNull()
+    {
+        $repo = $this->em->getRepository(self::TEST_ENTITY_CLASS);
+        $node = $repo->findOneByTitle('Vegitables');
+        $node->setParent(null);
+        
+        $this->em->persist($node);
+        $this->em->flush();
+        $this->em->clear();
+        
+        $node = $repo->findOneByTitle('Vegitables');
+        $this->assertEquals(4, $node->getRoot());
+        $this->assertEquals(1, $node->getLeft());
+        $this->assertEquals(6, $node->getRight());
+        $this->assertEquals(0, $node->getLevel());
+    }
+    
     public function testTreeUpdateShiftToNextBranch()
     {
         $repo = $this->em->getRepository(self::TEST_ENTITY_CLASS);