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);
     }
 }
示例#2
0
 public function testExecute()
 {
     $data = ['tmp_name' => 'tmp_name', 'path' => 'path', 'file' => 'file'];
     $uploader = $this->getMockBuilder('Magento\\MediaStorage\\Model\\File\\Uploader')->disableOriginalConstructor()->getMock();
     $resultJson = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->setMethods(['setData'])->getMock();
     $this->request->expects($this->once())->method('getParam')->with('type')->willReturn('samples');
     $this->sample->expects($this->once())->method('getBaseTmpPath')->willReturn('base_tmp_path');
     $this->uploaderFactory->expects($this->once())->method('create')->willReturn($uploader);
     $this->fileHelper->expects($this->once())->method('uploadFromTmp')->willReturn($data);
     $this->storageDatabase->expects($this->once())->method('saveFile');
     $this->session->expects($this->once())->method('getName')->willReturn('Name');
     $this->session->expects($this->once())->method('getSessionId')->willReturn('SessionId');
     $this->session->expects($this->once())->method('getCookieLifetime')->willReturn('CookieLifetime');
     $this->session->expects($this->once())->method('getCookiePath')->willReturn('CookiePath');
     $this->session->expects($this->once())->method('getCookieDomain')->willReturn('CookieDomain');
     $this->resultFactory->expects($this->once())->method('create')->willReturn($resultJson);
     $resultJson->expects($this->once())->method('setData')->willReturnSelf();
     $this->assertEquals($resultJson, $this->upload->execute());
 }
示例#3
0
 /**
  * Execute download sample url action
  */
 public function testExecuteUrl()
 {
     $this->request->expects($this->at(0))->method('getParam')->with('id', 0)->will($this->returnValue(1));
     $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('sample.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->sampleModel->expects($this->once())->method('load')->will($this->returnSelf());
     $this->sampleModel->expects($this->once())->method('getId')->will($this->returnValue('1'));
     $this->sampleModel->expects($this->any())->method('getSampleType')->will($this->returnValue('url'));
     $this->objectManager->expects($this->once())->method('create')->will($this->returnValue($this->sampleModel));
     $this->sample->execute();
 }