Пример #1
0
 public function testGetLinkData()
 {
     $expectingFileData = array('file' => array('file' => 'file/link.gif', 'name' => '<a href="final_url">link.gif</a>', 'size' => '1.1', 'status' => 'old'), '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('getLinks')->will($this->returnValue(array($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);
     }
 }
Пример #2
0
 /**
  * @dataProvider executeDataProvider
  * @param string $fileType
  */
 public function testExecuteUrl($fileType)
 {
     $this->request->expects($this->at(0))->method('getParam')->with('id', 0)->will($this->returnValue(1));
     $this->request->expects($this->at(1))->method('getParam')->with('type', 0)->will($this->returnValue($fileType));
     $this->response->expects($this->once())->method('setHttpResponseCode')->will($this->returnSelf());
     $this->response->expects($this->once())->method('clearBody')->will($this->returnSelf());
     $this->response->expects($this->any())->method('setHeader')->will($this->returnSelf());
     $this->response->expects($this->once())->method('sendHeaders')->will($this->returnSelf());
     $this->objectManager->expects($this->at(1))->method('get')->with('Magento\\Downloadable\\Helper\\Download')->will($this->returnValue($this->downloadHelper));
     $this->downloadHelper->expects($this->once())->method('setResource')->will($this->returnSelf());
     $this->downloadHelper->expects($this->once())->method('getFilename')->will($this->returnValue('link.jpg'));
     $this->downloadHelper->expects($this->once())->method('getContentType')->will($this->returnSelf('url'));
     $this->downloadHelper->expects($this->once())->method('getFileSize')->will($this->returnValue(null));
     $this->downloadHelper->expects($this->once())->method('getContentDisposition')->will($this->returnValue(null));
     $this->downloadHelper->expects($this->once())->method('output')->will($this->returnSelf());
     $this->linkModel->expects($this->once())->method('load')->will($this->returnSelf());
     $this->linkModel->expects($this->once())->method('getId')->will($this->returnValue('1'));
     $this->linkModel->expects($this->once())->method('get' . $fileType . 'Type')->will($this->returnValue('url'));
     $this->linkModel->expects($this->once())->method('get' . $fileType . 'Url')->will($this->returnValue('http://url.magento.com'));
     $this->objectManager->expects($this->once())->method('create')->will($this->returnValue($this->linkModel));
     $this->link->execute();
 }