Ejemplo n.º 1
0
 /**
  * @covers \BackBee\NestedNode\Repository\PageRepository::duplicateRecursively
  * @covers \BackBee\NestedNode\Repository\PageRepository::updateMainNodePostCloning
  * @covers \BackBee\NestedNode\Repository\PageRepository::updateRelatedPostCloning
  */
 public function testDuplicateRecursively()
 {
     // Initialize some mainnodes and circular related links
     $descendants = $this->repository->getDescendants($this->root, null, true);
     foreach ($descendants as $child) {
         $child->getContentSet()->first()->setMainNode($child);
     }
     $page1 = $this->repository->find('page1');
     $page3 = $this->repository->find('page3');
     $page1->getContentSet()->first()->push($page3->getContentSet()->first());
     $page3->getContentSet()->first()->push($page1->getContentSet()->first());
     self::$em->flush();
     // Recursively duplicate a tree
     $clone1 = $this->repository->duplicate($this->root);
     $this->assertInstanceOf('BackBee\\NestedNode\\Page', $clone1);
     $this->assertNull($clone1->getParent());
     $this->assertEquals('root', $clone1->getTitle());
     $this->assertTrue($clone1->hasMainSection());
     $new_descendants = $this->repository->getDescendants($clone1, null, true);
     $this->assertEquals(count($descendants), count($new_descendants));
     $new_page1 = $new_page3 = null;
     for ($i = 0; $i < count($descendants); $i++) {
         self::$em->refresh($new_descendants[$i]);
         $this->assertEquals($descendants[$i]->getTitle(), $new_descendants[$i]->getTitle());
         $this->assertEquals($descendants[$i]->hasMainSection(), $new_descendants[$i]->hasMainSection());
         $this->assertEquals($descendants[$i]->getLeftnode(), $new_descendants[$i]->getLeftnode());
         $this->assertEquals($descendants[$i]->getRightnode(), $new_descendants[$i]->getRightnode());
         $this->assertEquals($descendants[$i]->getPosition(), $new_descendants[$i]->getPosition());
         $this->assertEquals($descendants[$i]->getLevel(), $new_descendants[$i]->getLevel());
         $this->assertEquals($new_descendants[$i], $new_descendants[$i]->getContentSet()->first()->getMainNode());
         if ('page1' === $new_descendants[$i]->getTitle()) {
             $new_page1 = $new_descendants[$i];
         } elseif ('page3' === $new_descendants[$i]->getTitle()) {
             $new_page3 = $new_descendants[$i];
         }
     }
     $this->assertEquals($new_page1->getContentSet()->first()->last()->getUid(), $new_page3->getContentSet()->first()->getUid());
     $this->assertEquals($new_page3->getContentSet()->first()->last()->getUid(), $new_page1->getContentSet()->first()->getUid());
     // Duplicate children except deleted ones
     $section1 = $this->repository->find('section1');
     $section1->setState(Page::STATE_DELETED);
     $clone2 = $this->repository->duplicate($this->root);
     $this->assertEquals(count($this->repository->getDescendants($this->root)) - 3, count($this->repository->getDescendants($clone2)));
 }