/** * Custom patch process for Page's sibling or parent node. * * @param Page $page * @param array $operations passed by reference */ private function patchSiblingAndParentOperation(Page $page, array &$operations) { $sibling_operation = null; $parent_operation = null; foreach ($operations as $key => $operation) { $op = array('key' => $key, 'op' => $operation); if ('/sibling_uid' === $operation['path']) { $sibling_operation = $op; } elseif ('/parent_uid' === $operation['path']) { $parent_operation = $op; } } if (null !== $sibling_operation || null !== $parent_operation) { if ($page->isRoot()) { throw new BadRequestHttpException('Cannot move root node of a site.'); } if ($page->isOnline(true)) { $this->granted('PUBLISH', $page); // user must have publish permission on the page } } try { if (null !== $sibling_operation) { unset($operations[$sibling_operation['key']]); $sibling = $this->getPageByUid($sibling_operation['op']['value']); $this->granted('EDIT', $sibling->getParent()); $this->getPageRepository()->moveAsPrevSiblingOf($page, $sibling); } elseif (null !== $parent_operation) { unset($operations[$parent_operation['key']]); $parent = $this->getPageByUid($parent_operation['op']['value']); if ($this->isFinal($parent)) { throw new BadRequestHttpException('Can\'t create children of ' . $parent->getLayout()->getLabel() . ' layout'); } $this->moveAsFirstChildOf($page, $parent); } } catch (InvalidArgumentException $e) { throw new BadRequestHttpException('Invalid node move action: ' . $e->getMessage()); } }
/** * @covers BackBee\NestedNode\Page::isOnline */ public function testIsOnline() { $page = new Page(); $page->setParent($this->page); $this->assertFalse($page->isOnline()); $this->assertFalse($page->isOnline(true)); $page->setState(Page::STATE_ONLINE); $this->assertTrue($page->isOnline()); $this->assertTrue($page->isOnline(true)); $page->setState(Page::STATE_ONLINE + Page::STATE_HIDDEN); $this->assertTrue($page->isOnline()); $this->assertTrue($page->isOnline(true)); $page->setState(Page::STATE_ONLINE + Page::STATE_HIDDEN + Page::STATE_DELETED); $this->assertFalse($page->isOnline()); $this->assertFalse($page->isOnline(true)); $tomorrow = new \DateTime('tomorrow'); $page->setState(Page::STATE_ONLINE)->setPublishing($tomorrow)->setArchiving(); $this->assertFalse($page->isOnline()); $this->assertTrue($page->isOnline(true)); }