/**
  * @covers \BackBee\NestedNode\Builder\PageBuilder::getPage
  * @covers \BackBee\NestedNode\Builder\PageBuilder::doPersistIfValid
  */
 public function testGetPagePersisted()
 {
     $chid1 = self::$builder->setUid('first-child')->setTitle('title')->setSite($this->site)->setLayout($this->layout)->setParent($this->root)->setPersistMode(PageBuilder::PERSIST_AS_FIRST_CHILD)->getPage();
     $this->assertTrue(self::$em->getUnitOfWork()->isScheduledForInsert($chid1));
     self::$em->flush();
     self::$em->refresh($this->root);
     $this->assertFalse($chid1->isRoot());
     $this->assertFalse($chid1->hasMainSection());
     $this->assertEquals(1, $this->root->getLeftnode());
     $this->assertEquals(2, $this->root->getRightnode());
     $this->assertEquals(1, $chid1->getPosition());
     $this->assertEquals(1, $chid1->getLevel());
     $child2 = self::$builder->setUid('second-child')->setTitle('title')->setSite($this->site)->setLayout($this->layout)->setParent($this->root)->setPersistMode(PageBuilder::PERSIST_AS_LAST_CHILD)->getPage();
     self::$em->flush();
     $this->assertEquals(2, $child2->getPosition());
     $this->assertEquals(1, $child2->getLevel());
     $section = self::$builder->setUid('section')->setTitle('title')->setSite($this->site)->setLayout($this->layout)->setParent($this->root)->isSection(true)->setPersistMode(PageBuilder::PERSIST_AS_FIRST_CHILD)->getPage();
     self::$em->flush();
     self::$em->refresh($this->root);
     $this->assertTrue($section->hasMainSection());
     $this->assertEquals(0, $section->getPosition());
     $this->assertEquals(1, $section->getLevel());
     $this->assertEquals(2, $section->getLeftnode());
     $this->assertEquals(3, $section->getRightnode());
     $this->assertEquals(1, $this->root->getLeftnode());
     $this->assertEquals(4, $this->root->getRightnode());
 }
 /**
  * @covers \BackBee\NestedNode\Repository\PageRepository::moveAsNextSiblingOf
  * @covers \BackBee\NestedNode\Repository\PageRepository::moveAsSiblingOf
  * @covers \BackBee\NestedNode\Repository\PageRepository::movePageAsSiblingOf
  * @covers \BackBee\NestedNode\Repository\PageRepository::moveSectionAsSiblingOf
  */
 public function testMoveAsNextSiblingOf()
 {
     $section1 = $this->repository->find('section1');
     $section2 = $this->repository->find('section2');
     $page1 = $this->repository->find('page1');
     $page2 = $this->repository->find('page2');
     $page3 = $this->repository->find('page3');
     $this->assertEquals($page3, $this->repository->moveAsNextSiblingOf($page3, $page2));
     self::$em->refresh($page1);
     self::$em->refresh($page2);
     self::$em->flush($page3);
     $this->assertEquals($section1, $page3->getParent());
     $this->assertEquals(2, $page3->getLevel());
     $this->assertEquals(1, $page2->getPosition());
     $this->assertEquals(2, $page3->getPosition());
     $this->assertEquals(3, $page1->getPosition());
     $this->assertEquals($section1, $this->repository->moveAsNextSiblingOf($section1, $section2));
     self::$em->refresh($section2);
     self::$em->flush($section1);
     $this->assertEquals(1, $this->root->getLeftnode());
     $this->assertEquals(6, $this->root->getRightnode());
     $this->assertEquals(2, $section2->getLeftnode());
     $this->assertEquals(3, $section2->getRightnode());
     $this->assertEquals(4, $section1->getLeftnode());
     $this->assertEquals(5, $section1->getRightnode());
 }
 /**
  * Replace root contentset for a page and its descendants.
  *
  * @param \BackBee\NestedNode\Page            $page
  * @param \BackBee\ClassContent\ContentSet    $oldContentSet
  * @param \BackBee\ClassContent\ContentSet    $newContentSet
  * @param \BackBee\Security\Token\BBUserToken $userToken
  */
 public function updateRootContentSetByPage(Page $page, ContentSet $oldContentSet, ContentSet $newContentSet, BBUserToken $userToken)
 {
     $em = $this->_em;
     $q = $this->createQueryBuilder('c');
     $results = $q->leftJoin('c._pages', 'p')->leftJoin('p._section', 'sp')->leftJoin('c._subcontent', 'subcontent')->where('subcontent = :contentToReplace')->andWhere('sp._root = :cpageRoot')->andWhere('sp._leftnode > :cpageLeftnode')->andWhere('sp._rightnode < :cpageRightnode')->setParameters(['contentToReplace' => $oldContentSet, 'cpageRoot' => $page->getSection()->getRoot(), 'cpageLeftnode' => $page->getLeftnode(), 'cpageRightnode' => $page->getRightnode()])->getQuery()->getResult();
     if ($results) {
         foreach ($results as $parentContentSet) {
             /* create draft for the main container */
             $draft = $em->getRepository('BackBee\\ClassContent\\Revision')->getDraft($parentContentSet, $userToken, true);
             if (null !== $draft) {
                 $parentContentSet->setDraft($draft);
             }
             /* Replace the old ContentSet by the new one */
             $parentContentSet->replaceChildBy($oldContentSet, $newContentSet);
             $em->persist($parentContentSet);
         }
     }
 }
示例#4
0
 /**
  * @covers BackBee\NestedNode\Page::getLeftnode()
  * @covers BackBee\NestedNode\Page::getRightnode()
  */
 public function testGetNode()
 {
     $this->assertEquals(1, $this->page->getLeftnode());
     $this->assertEquals(2, $this->page->getRightnode());
     $child = new Page('child');
     $child->setSection($this->page->getSection());
     $this->assertEquals(1, $child->getLeftnode());
     $this->assertEquals(2, $child->getRightnode());
 }
 /**
  * Set a page to filter the query on a nested portion.
  *
  * @param  BackBee\NestedNode\Page $page
  */
 public function addPageFilter(Page $page)
 {
     if ($page && !$page->isRoot()) {
         $this->leftJoin('cc._mainnode', 'p')->leftJoin('p._section', 'sp')->andWhere('sp._root = :selectedPageRoot')->andWhere('sp._leftnode >= :selectedPageLeftnode')->andWhere('sp._rightnode <= :selectedPageRightnode')->setParameters(['selectedPageRoot' => $page->getSection()->getRoot(), 'selectedPageLeftnode' => $page->getLeftnode(), 'selectedPageRightnode' => $page->getRightnode()]);
     }
 }