/**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage There is no downloadable sample with provided ID.
  */
 public function testDeleteThrowsExceptionIfSampleIdIsNotValid()
 {
     $sampleId = 1;
     $sampleMock = $this->getMock('\\Magento\\Downloadable\\Model\\Sample', [], [], '', false);
     $this->sampleFactoryMock->expects($this->once())->method('create')->willReturn($sampleMock);
     $sampleMock->expects($this->once())->method('load')->with($sampleId)->willReturnSelf();
     $sampleMock->expects($this->any())->method('getId');
     $this->sampleResourceMock->expects($this->never())->method('delete');
     $this->service->delete($sampleId);
 }
 /**
  * {@inheritdoc}
  */
 public function delete($id)
 {
     /** @var $sample \Magento\Downloadable\Model\Sample */
     $sample = $this->sampleFactory->create()->load($id);
     if (!$sample->getId()) {
         throw new NoSuchEntityException(__('There is no downloadable sample with provided ID.'));
     }
     try {
         $this->resourceModel->delete($sample);
     } catch (\Exception $exception) {
         throw new StateException(__('Cannot delete sample with id %1', $sample->getId()), $exception);
     }
     return true;
 }
Example #3
0
 /**
  * @param Sample $sample
  * @return string
  */
 public function getSampleUrl($sample)
 {
     return $this->getUrl('downloadable/download/sample', ['sample_id' => $sample->getId()]);
 }