/** * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Sample title cannot be empty. */ public function testUpdateThrowsExceptionIfTitleIsEmptyAndScopeIsGlobal() { $sampleId = 1; $productSku = 'simple'; $productId = 1; $sampleData = ['id' => $sampleId, 'title' => '', 'sort_order' => 1]; $this->repositoryMock->expects($this->any())->method('get')->with($productSku, true)->will($this->returnValue($this->productMock)); $this->productMock->expects($this->any())->method('getId')->will($this->returnValue($productId)); $existingSampleMock = $this->getMock('\\Magento\\Downloadable\\Model\\Sample', ['__wakeup', 'getId', 'load', 'save', 'getProductId'], [], '', false); $existingSampleMock->expects($this->any())->method('getId')->will($this->returnValue($sampleId)); $existingSampleMock->expects($this->once())->method('load')->with($sampleId)->will($this->returnSelf()); $existingSampleMock->expects($this->any())->method('getProductId')->will($this->returnValue($productId)); $this->sampleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($existingSampleMock)); $sampleMock = $this->getSampleMock($sampleData); $this->contentValidatorMock->expects($this->any())->method('isValid')->with($sampleMock)->will($this->returnValue(true)); $this->productTypeMock->expects($this->never())->method('save'); $this->service->save($productSku, $sampleMock, true); }
public function testSaveWithFile() { $sampleId = 1; $productId = 1; $productSku = 'simple'; $sampleFile = '/s/a/sample.jpg'; $sampleData = ['id' => $sampleId, 'title' => 'Updated Title', 'sort_order' => 1, 'sample_type' => 'file', 'file' => $sampleFile]; $this->repositoryMock->expects($this->once())->method('get')->with($productSku, true)->willReturn($this->productMock); $this->productMock->expects($this->once())->method('getTypeId')->willReturn('downloadable'); $this->productMock->expects($this->once())->method('getData')->with('id')->willReturn($productId); $sampleMock = $this->getSampleMock($sampleData); $this->contentValidatorMock->expects($this->any())->method('isValid')->with($sampleMock)->willReturn(true); $sampleMock->expects($this->once())->method('setProductId')->with($productId); $sampleMock->expects($this->exactly(2))->method('getFile')->willReturn($sampleFile); $this->jsonEncoderMock->expects($this->once())->method('jsonDecode')->willReturn($sampleFile); $this->contentUploaderMock->expects($this->once())->method('moveFileFromTmp')->with($sampleMock->getBaseTmpPath(), $sampleMock->getBasePath(), $sampleFile)->willReturn($sampleFile); $sampleMock->expects($this->once())->method('setSampleFile')->with($sampleFile); $sampleMock->expects($this->once())->method('setSampleUrl')->with(null); $this->sampleResourceMock->expects($this->once())->method('save')->with($sampleMock)->willReturn($sampleId); $this->assertEquals($sampleId, $this->service->save($productSku, $sampleMock)); }