Example #1
0
 /**
  * @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')->will($this->returnValue($sampleMock));
     $sampleMock->expects($this->once())->method('load')->with($sampleId)->will($this->returnSelf());
     $sampleMock->expects($this->once())->method('getId');
     $sampleMock->expects($this->never())->method('delete');
     $this->service->delete($sampleId);
 }
 public function testGetList()
 {
     $productSku = 'downloadable_sku';
     $sampleData = ['id' => 324, 'store_title' => 'rock melody sample', 'title' => 'just melody sample', 'sort_order' => 21, 'sample_type' => 'file', 'sample_url' => null, 'sample_file' => '/r/o/rock.melody.ogg'];
     $sampleMock = $this->getMock('\\Magento\\Downloadable\\Model\\Sample', ['getId', 'getStoreTitle', 'getTitle', 'getSampleType', 'getSampleFile', 'getSampleUrl', 'getSortOrder', 'getData', '__wakeup'], [], '', false);
     $sampleInterfaceMock = $this->getMock('\\Magento\\Downloadable\\Api\\Data\\SampleInterface');
     $this->repositoryMock->expects($this->once())->method('get')->with($productSku)->will($this->returnValue($this->productMock));
     $this->productTypeMock->expects($this->once())->method('getSamples')->with($this->productMock)->will($this->returnValue([$sampleMock]));
     $this->setSampleAssertions($sampleMock, $sampleData);
     $this->sampleDataObjectFactory->expects($this->once())->method('create')->willReturn($sampleInterfaceMock);
     $this->assertEquals([$sampleInterfaceMock], $this->service->getList($productSku));
 }