/** * @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); }