/** * @dataProvider moveNodeDataProvider * @param int $nodeId * @param int|null $parentNodeId * @param int $position * @param boolean $withException */ public function testMoveNode($nodeId, $parentNodeId, $position, $withException) { $this->preparePages($this->pages); $pages = $this->pagesCollection; $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock(); $em->expects($this->once())->method('getConnection')->will($this->returnValue($connection)); $this->managerRegistry->expects($this->once())->method('getManagerForClass')->with('OroB2BCMSBundle:Page')->will($this->returnValue($em)); $connection->expects($this->once())->method('beginTransaction'); $currentNode = $pages[$nodeId]; $parentNode = array_key_exists($parentNodeId, $pages) ? $pages[$parentNodeId] : null; if ($withException) { $this->repository->expects($this->at(0))->method('find')->willThrowException(new \Exception()); $connection->expects($this->once())->method('rollBack'); } else { $this->repository->expects($this->at(0))->method('find')->willReturn($currentNode); $this->repository->expects($this->at(1))->method('find')->willReturn($parentNode); if ('#' !== $parentNodeId) { if ($position) { $children = array_values($parentNode->getChildpages()->toArray()); $this->repository->expects($this->at(2))->method('__call')->with('persistAsNextSiblingOf', [$currentNode, $children[$position - 1]]); } else { $this->repository->expects($this->at(2))->method('__call')->with('persistAsFirstChildOf', [$currentNode, $parentNode]); } } $this->slugManager->expects($this->once())->method('makeUrlUnique')->with($currentNode->getCurrentSlug()); $em->expects($this->at(0))->method('flush'); $connection->expects($this->once())->method('commit'); } $this->pageTreeHandler->moveNode($nodeId, $parentNodeId, $position); if (!$withException) { $this->assertEquals($parentNode, $currentNode->getParentPage()); } }
/** * @dataProvider supportedMethods * @param string $method * @param boolean $isValid * @param boolean $isProcessed */ public function testProcessSupportedRequest($method, $isValid, $isProcessed) { if ($isValid) { $this->slugManager->expects($this->once())->method('makeUrlUnique')->with($this->entity->getCurrentSlug()); } else { $this->slugManager->expects($this->never())->method('makeUrlUnique')->with($this->entity->getCurrentSlug()); } parent::testProcessSupportedRequest($method, $isValid, $isProcessed); }
/** * @param Page $page * @return bool True on successful processing, false otherwise */ public function process(Page $page) { $this->form->setData($page); if (in_array($this->request->getMethod(), array('POST', 'PUT'))) { $this->form->submit($this->request); if ($this->form->isValid()) { $this->slugManager->makeUrlUnique($page->getCurrentSlug()); $this->manager->persist($page); $this->manager->flush(); return true; } } return false; }
public function testMakeUrlUnique() { $manager = $this->registry->getManagerForClass('OroB2BRedirectBundle:Slug'); $slug = new Slug(); $slug->setUrl('domain.com/hvac-equipment/detection-kits'); $slug->setRouteName('orob2b_cms_page_view'); $slug->setRouteParameters(['id' => 1]); $manager->persist($slug); $slug1 = new Slug(); $slug1->setUrl('domain.com/hvac-equipment/detection-kits1-1'); $slug1->setRouteName('orob2b_cms_page_view'); $slug1->setRouteParameters(['id' => 1]); $manager->persist($slug1); $slug2 = new Slug(); $slug2->setUrl('domain.com/hvac-equipment/detection-kits1-2'); $slug2->setRouteName('orob2b_cms_page_view'); $slug2->setRouteParameters(['id' => 1]); $manager->persist($slug2); $manager->flush(); $testSlug = new Slug(); $testSlug->setUrl('domain.com/hvac-equipment/detection-kits'); $testSlug->setRouteName('orob2b_cms_page_view'); $testSlug->setRouteParameters(['id' => 2]); $this->slugManager->makeUrlUnique($testSlug); $manager->persist($testSlug); $manager->flush(); $this->assertEquals('domain.com/hvac-equipment/detection-kits-1', $testSlug->getUrl()); $testSlug1 = new Slug(); $testSlug1->setUrl('domain.com/hvac-equipment/detection-kits'); $testSlug1->setRouteName('orob2b_cms_page_view'); $testSlug1->setRouteParameters(['id' => 21]); $this->slugManager->makeUrlUnique($testSlug1); $manager->persist($testSlug1); $manager->flush(); $this->assertEquals('domain.com/hvac-equipment/detection-kits-2', $testSlug1->getUrl()); $testSlug2 = new Slug(); $testSlug2->setUrl('domain.com/hvac-equipment/detection-kits1-1'); $testSlug2->setRouteName('orob2b_cms_page_view'); $testSlug2->setRouteParameters(['id' => 21]); $this->slugManager->makeUrlUnique($testSlug2); $manager->persist($testSlug2); $manager->flush(); $this->assertEquals('domain.com/hvac-equipment/detection-kits1-3', $testSlug2->getUrl()); }
/** * Move node processing * * @param int $entityId * @param int $parentId * @param int $position */ protected function moveProcessing($entityId, $parentId, $position) { /** @var PageRepository $entityRepository */ $entityRepository = $this->getEntityRepository(); /** @var page $page */ $page = $entityRepository->find($entityId); /** @var page $parentPage */ $parentPage = $entityRepository->find($parentId); if (null === $parentPage) { $page->setParentPage(null); } else { if ($parentPage->getChildPages()->contains($page)) { $parentPage->removeChildPage($page); } $parentPage->addChildPage($page); if ($position) { $children = array_values($parentPage->getChildPages()->toArray()); $entityRepository->persistAsNextSiblingOf($page, $children[$position - 1]); } else { $entityRepository->persistAsFirstChildOf($page, $parentPage); } } $this->slugManager->makeUrlUnique($page->getCurrentSlug()); }