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->sampleFactoryMock->expects($this->once())->method('create')->willReturn($sampleInterfaceMock); $this->assertEquals([$sampleInterfaceMock], $this->service->getList($productSku)); }
public function testGetLinkData() { $expectingFileData = ['file' => ['file' => 'file/link.gif', 'name' => '<a href="final_url">link.gif</a>', 'size' => '1.1', 'status' => 'old'], 'sample_file' => ['file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old']]; $this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable')); $this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel)); $this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0)); $this->downloadableProductModel->expects($this->any())->method('getLinks')->will($this->returnValue([$this->downloadableLinkModel])); $this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel)); $this->downloadableLinkModel->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->downloadableLinkModel->expects($this->any())->method('getTitle')->will($this->returnValue('Link Title')); $this->downloadableLinkModel->expects($this->any())->method('getPrice')->will($this->returnValue('10')); $this->downloadableLinkModel->expects($this->any())->method('getNumberOfDownloads')->will($this->returnValue('6')); $this->downloadableLinkModel->expects($this->any())->method('getLinkUrl')->will($this->returnValue(null)); $this->downloadableLinkModel->expects($this->any())->method('getLinkType')->will($this->returnValue('file')); $this->downloadableLinkModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif')); $this->downloadableLinkModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file')); $this->downloadableLinkModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0)); $this->downloadableLinkModel->expects($this->any())->method('getLinkFile')->will($this->returnValue('file/link.gif')); $this->downloadableLinkModel->expects($this->any())->method('getStoreTitle')->will($this->returnValue('Store Title')); $this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Link Title')); $this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/link.gif')); $this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true)); $this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1')); $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url')); $linkData = $this->block->getLinkData(); foreach ($linkData as $link) { $fileSave = $link->getFileSave(0); $sampleFileSave = $link->getSampleFileSave(0); $this->assertEquals($expectingFileData['file'], $fileSave); $this->assertEquals($expectingFileData['sample_file'], $sampleFileSave); } }
public function testGetSampleData() { $expectingFileData = array('sample_file' => array('file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old')); $this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable')); $this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel)); $this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0)); $this->downloadableProductModel->expects($this->any())->method('getSamples')->will($this->returnValue(array($this->downloadableSampleModel))); $this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel)); $this->downloadableSampleModel->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->downloadableSampleModel->expects($this->any())->method('getTitle')->will($this->returnValue('Sample Title')); $this->downloadableSampleModel->expects($this->any())->method('getSampleUrl')->will($this->returnValue(null)); $this->downloadableSampleModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif')); $this->downloadableSampleModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file')); $this->downloadableSampleModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0)); $this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Sample Title')); $this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/sample.gif')); $this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true)); $this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1')); $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url')); $sampleData = $this->block->getSampleData(); foreach ($sampleData as $sample) { $fileSave = $sample->getFileSave(0); $this->assertEquals($expectingFileData['sample_file'], $fileSave); } }
public function testGetList() { $productSku = 'downloadable_sku'; $linkData = ['id' => 324, 'store_title' => 'rock melody', 'title' => 'just melody', 'price' => 23, 'number_of_downloads' => 3, 'sort_order' => 21, 'is_shareable' => 2, 'sample_type' => 'file', 'sample_url' => null, 'sample_file' => '/r/o/rock.melody.ogg', 'link_type' => 'url', 'link_url' => 'http://link.url', 'link_file' => null]; $linkMock = $this->getMock('Magento\\Downloadable\\Model\\Link', ['getId', 'getStoreTitle', 'getTitle', 'getPrice', 'getNumberOfDownloads', 'getSortOrder', 'getIsShareable', 'getData', '__wakeup', 'setId'], [], '', false); $linkInterfaceMock = $this->getMock('\\Magento\\Downloadable\\Api\\Data\\LinkInterface'); $this->repositoryMock->expects($this->once())->method('get')->with($productSku)->will($this->returnValue($this->productMock)); $this->productTypeMock->expects($this->once())->method('getLinks')->with($this->productMock)->will($this->returnValue([$linkMock])); $this->setLinkAssertions($linkMock, $linkData); $this->linkFactoryMock->expects($this->once())->method('create')->willReturn($linkInterfaceMock); $this->assertEquals([$linkInterfaceMock], $this->service->getList($productSku)); }