/** * @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()); }
/** * @covers \BackBee\NestedNode\Repository\PageRepository::shiftPosition */ public function testShiftPosition() { $this->assertEquals($this->repository, $this->invokeMethod($this->repository, 'shiftPosition', array($this->root, 1))); $this->assertEquals(0, $this->root->getPosition()); $page1 = $this->repository->find('page1'); $page2 = $this->repository->find('page2'); self::$em->refresh($page1); self::$em->refresh($page2); $this->assertEquals($this->repository, $this->invokeMethod($this->repository, 'shiftPosition', array($page2, 1))); $this->assertEquals(2, $page2->getPosition()); self::$em->refresh($page1); $this->assertEquals(3, $page1->getPosition()); $this->assertEquals($this->repository, $this->invokeMethod($this->repository, 'shiftPosition', array($page2, 1, true))); $this->assertEquals(2, $page2->getPosition()); self::$em->refresh($page1); $this->assertEquals(4, $page1->getPosition()); }
/** * Shift position values for pages siblings of and after $page by $delta. * * @param Page $page The page for which to shift position. * @param integer $delta The shift value of position. * @param boolean $strict Does $page is include (true) or not (false, by default). * * @return PageRepository */ private function shiftPosition(Page $page, $delta, $strict = false) { if (true === $page->hasMainSection()) { return $this; } $query = $this->createQueryBuilder('p')->set('p._position', 'p._position + :delta_node')->andWhere('p._section = :section')->andWhere('p._position >= :position')->setParameters(['delta_node' => $delta, 'section' => $page->getSection(), 'position' => $page->getPosition()]); if (true === $strict) { $query->andWhere('p != :page')->setParameter('page', $page); } else { $page->setPosition($page->getPosition() + $delta); } $query->update()->getQuery()->execute(); return $this; }