public function testExecute() { $entityId = 1; $linkId = 2; $oldStore = 1; $newStore = 2; $linkField = 'link_id'; $adapter = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMockForAbstractClass(); $whereForDelete = [$linkField . ' = ?' => $linkId, 'store_id IN (?)' => [$oldStore]]; $adapter->expects($this->once())->method('delete')->with('cms_page_store', $whereForDelete)->willReturnSelf(); $whereForInsert = [$linkField => $linkId, 'store_id' => $newStore]; $adapter->expects($this->once())->method('insertMultiple')->with('cms_page_store', [$whereForInsert])->willReturnSelf(); $entityMetadata = $this->getMockBuilder('Magento\\Framework\\Model\\Entity\\EntityMetadata')->disableOriginalConstructor()->getMock(); $entityMetadata->expects($this->once())->method('getEntityConnection')->willReturn($adapter); $entityMetadata->expects($this->once())->method('getLinkField')->willReturn($linkField); $this->metadataPool->expects($this->once())->method('getMetadata')->with('Magento\\Cms\\Model\\Page')->willReturn($entityMetadata); $this->resourcePage->expects($this->once())->method('lookupStoreIds')->willReturn([$oldStore]); $this->resourcePage->expects($this->once())->method('getTable')->with('cms_page_store')->willReturn('cms_page_store'); $page = $this->getMockBuilder('Magento\\Cms\\Model\\Page')->disableOriginalConstructor()->setMethods(['getStores', 'getStoreId', 'getId', 'getData'])->getMock(); $page->expects($this->once())->method('getStores')->willReturn(null); $page->expects($this->once())->method('getStoreId')->willReturn($newStore); $page->expects($this->once())->method('getId')->willReturn($entityId); $page->expects($this->exactly(2))->method('getData')->with($linkField)->willReturn($linkId); $result = $this->model->execute('Magento\\Cms\\Model\\Page', $page); $this->assertInstanceOf('Magento\\Cms\\Model\\Page', $result); }
/** * @covers \Magento\Cms\Model\Page::checkIdentifier */ public function testCheckIdentifier() { $identifier = 1; $storeId = 2; $fetchOneResult = 'some result'; $this->resourcePageMock->expects($this->atLeastOnce())->method('checkIdentifier')->with($identifier, $storeId)->willReturn($fetchOneResult); $this->assertInternalType('string', $this->thisMock->checkIdentifier($identifier, $storeId)); }
public function testExecute() { $entityId = 1; $storeId = 1; $this->resourcePage->expects($this->once())->method('lookupStoreIds')->willReturn([$storeId]); $page = $this->getMockBuilder('Magento\\Cms\\Model\\Page')->disableOriginalConstructor()->getMock(); $page->expects($this->exactly(2))->method('getId')->willReturn($entityId); $page->expects($this->once())->method('setData')->with('store_id', [$storeId])->willReturnSelf(); $result = $this->model->execute('', $page); $this->assertInstanceOf('Magento\\Cms\\Model\\Page', $result); }
protected function setUp() { $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock(); $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->resourcePageMock = $this->getMockBuilder(PageResource::class)->disableOriginalConstructor()->setMethods(['getIdFieldName', 'checkIdentifier'])->getMock(); $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock(); $this->resourcesMock = $this->getMockBuilder(AbstractResource::class)->setMethods(['getIdFieldName', 'load', 'checkIdentifier'])->getMockForAbstractClass(); $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)->getMockForAbstractClass(); $this->contextMock->expects($this->any())->method('getEventDispatcher')->willReturn($this->eventManagerMock); $this->resourcePageMock->expects($this->any())->method('getResources')->willReturn($this->resourcesMock); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectManager->getObject(Page::class, ['context' => $this->contextMock, 'resource' => $this->resourcesMock]); $objectManager->setBackwardCompatibleProperty($this->model, 'scopeConfig', $this->scopeConfigMock); }
public function testGetLabelByPageId() { $pageId = 1; $label = 'Label by page id'; $this->mockResourcePage->expects($this->once())->method('getCmsPageTitleById')->with($pageId)->willReturn($label); $this->linkElement->setData('page_id', $pageId); $this->assertEquals($label, $this->linkElement->getLabel()); }
/** * @test * * @expectedException \Magento\Framework\Exception\CouldNotDeleteException */ public function testDeleteException() { $this->pageResource->expects($this->once())->method('delete')->with($this->page)->willThrowException(new \Exception()); $this->repository->delete($this->page); }