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_block_store', $whereForDelete)->willReturnSelf(); $whereForInsert = [$linkField => $linkId, 'store_id' => $newStore]; $adapter->expects($this->once())->method('insertMultiple')->with('cms_block_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\\Block')->willReturn($entityMetadata); $this->resourceBlock->expects($this->once())->method('lookupStoreIds')->willReturn([$oldStore]); $this->resourceBlock->expects($this->once())->method('getTable')->with('cms_block_store')->willReturn('cms_block_store'); $block = $this->getMockBuilder('Magento\\Cms\\Model\\Block')->disableOriginalConstructor()->setMethods(['getStores', 'getId', 'getData'])->getMock(); $block->expects($this->once())->method('getStores')->willReturn($newStore); $block->expects($this->once())->method('getId')->willReturn($entityId); $block->expects($this->exactly(2))->method('getData')->with($linkField)->willReturn($linkId); $result = $this->model->execute('Magento\\Cms\\Model\\Block', $block); $this->assertInstanceOf('Magento\\Cms\\Model\\Block', $result); }
public function testExecute() { $entityId = 1; $storeId = 1; $this->resourceBlock->expects($this->once())->method('lookupStoreIds')->willReturn([$storeId]); $block = $this->getMockBuilder('Magento\\Cms\\Model\\Block')->disableOriginalConstructor()->getMock(); $block->expects($this->exactly(2))->method('getId')->willReturn($entityId); $block->expects($this->exactly(2))->method('setData')->willReturnMap([['store_id', [$storeId], $block], ['stores', [$storeId], $block]]); $result = $this->model->execute('', $block); $this->assertInstanceOf('Magento\\Cms\\Model\\Block', $result); }
/** * @test * * @expectedException \Magento\Framework\Exception\NoSuchEntityException */ public function testGetByIdException() { $blockId = '123'; $this->block->expects($this->once())->method('getId')->willReturn(false); $this->blockResource->expects($this->once())->method('load')->with($this->block, $blockId)->willReturn($this->block); $this->repository->getById($blockId); }
/** * @test * * @expectedException \Magento\Framework\Exception\CouldNotSaveException */ public function testSaveException() { $this->locationResource->expects($this->once())->method('save')->with($this->location)->willThrowException(new \Exception()); $this->repository->save($this->location); }