public function testShiftLevel()
 {
     $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($this->repository, $this->invokeMethod($this->repository, 'shiftLevel', array($page3, 1, true)));
     self::$em->refresh($page3);
     $this->assertEquals(1, $page3->getLevel());
     $this->assertEquals($this->repository, $this->invokeMethod($this->repository, 'shiftLevel', array($page3, 1, false)));
     self::$em->refresh($page3);
     $this->assertEquals(2, $page3->getLevel());
     $this->invokeMethod($this->repository, 'shiftLevel', array($this->root, 2));
     foreach ($this->repository->findAll() as $node) {
         self::$em->refresh($node);
     }
     $this->assertEquals(2, $this->root->getLevel());
     $this->assertEquals(3, $section1->getLevel());
     $this->assertEquals(3, $section2->getLevel());
     $this->assertEquals(4, $page1->getLevel());
     $this->assertEquals(4, $page2->getLevel());
     $this->assertEquals(4, $page3->getLevel());
     $this->invokeMethod($this->repository, 'shiftLevel', array($this->root, -2, true));
     foreach ($this->repository->findAll() as $node) {
         self::$em->refresh($node);
     }
     $this->assertEquals(2, $this->root->getLevel());
     $this->assertEquals(1, $section1->getLevel());
     $this->assertEquals(1, $section2->getLevel());
     $this->assertEquals(2, $page1->getLevel());
     $this->assertEquals(2, $page2->getLevel());
     $this->assertEquals(2, $page3->getLevel());
 }
Example #2
0
 /**
  * @covers BackBee\NestedNode\Page::setSection()
  */
 public function testSetSection()
 {
     $section = new Section('new_section');
     $section->setLevel(10);
     $this->page->setSection($section);
     $this->assertNull($this->page->getMainSection());
     $this->assertEquals($section, $this->page->getSection());
     $this->assertEquals(1, $this->page->getPosition());
     $this->assertEquals(11, $this->page->getLevel());
 }
Example #3
0
 /**
  * Move a section page as sibling of $target.
  *
  * @param  Page                 $page               The page to be moved.
  * @param  Page                 $target             The target page.
  * @param  boolean              $asPrevious         Move page as previous sibling of $target if true (default), next sibling elsewhere.
  *
  * @return Page                                     The moved page.
  */
 private function moveSectionAsSiblingOf(Page $page, Page $target, $asPrevious = true)
 {
     $delta = $target->getLevel() - $page->getLevel();
     $this->shiftLevel($page, $delta);
     $this->getEntityManager()->getRepository('BackBee\\NestedNode\\Section')->moveNode($page->getSection(), $target->getSection(), $asPrevious ? 'before' : 'after');
     return $page;
 }
Example #4
0
 /**
  * Add query part to select siblings of page.
  *
  * @param  Page                 $page               The page to look for siblings
  * @param  boolean              $strict             Optional, if false (by default) $node is include to the selection
  * @param  array|null           $order              Optional, ordering spec ( [$field => $sort] )
  * @param  integer|null         $limit              Optional, max number of results, if null no limit
  * @param  integer              $start              Optional, first result index (0 by default)
  *
  * @return PageQueryBuilder
  */
 public function andIsSiblingsOf(Page $page, $strict = false, array $order = null, $limit = null, $start = 0)
 {
     if (null === $page->getParent()) {
         $this->andParentIs(null);
     } else {
         $this->andIsDescendantOf($page->getParent(), false, $page->getLevel());
     }
     if (true === $strict) {
         $suffix = $this->getSuffix();
         $this->andWhere($this->getAlias() . ' != :page' . $suffix)->setParameter('page' . $suffix, $page);
     }
     if (null !== $order) {
         $this->addMultipleOrderBy($order);
     }
     if (null !== $limit) {
         $this->setMaxResults($limit)->setFirstResult($start);
     }
     return $this;
 }
Example #5
0
 /**
  * Move a section page as sibling of $target.
  *
  * @param  Page                 $page               The page to be moved.
  * @param  Page                 $target             The target page.
  * @param  boolean              $asPrevious         Move page as previous sibling of $target if true (default), next sibling elsewhere.
  *
  * @return Page                                     The moved page.
  *
  * @throws InvalidArgumentException                 Raises if target page is a section.
  */
 private function moveSectionAsSiblingOf(Page $page, Page $target, $asPrevious = true)
 {
     if (false === $target->hasMainSection()) {
         throw new InvalidArgumentException('Cannot move a section page as sibling of a non-section page.');
     }
     $delta = $page->getLevel() - $target->getLevel();
     $this->shiftLevel($page, $delta);
     if (true === $asPrevious) {
         $this->getEntityManager()->getRepository('BackBee\\NestedNode\\Section')->moveAsPrevSiblingOf($page->getSection(), $target->getSection());
     } else {
         $this->getEntityManager()->getRepository('BackBee\\NestedNode\\Section')->moveAsNextSiblingOf($page->getSection(), $target->getSection());
     }
     return $page;
 }