Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
 protected function _setupFileMocks($doesExist = true, $size = self::FILE_SIZE, $path = self::FILE_PATH)
 {
     $this->_handleMock->expects($this->any())->method('stat')->will($this->returnValue(['size' => $size]));
     $this->_downloadableFileMock->expects($this->any())->method('ensureFileInFilesystem')->with($path)->will($this->returnValue($doesExist));
     $this->_workingDirectoryMock->expects($doesExist ? $this->once() : $this->never())->method('openFile')->will($this->returnValue($this->_handleMock));
     $this->_filesystemMock->expects($this->any())->method('getDirectoryRead')->with(DirectoryList::MEDIA)->will($this->returnValue($this->_workingDirectoryMock));
     $this->_helper->setResource($path, DownloadHelper::LINK_TYPE_FILE);
 }
Ejemplo n.º 4
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());
 }
Ejemplo n.º 5
0
 /**
  * Execute download sample file action
  */
 public function testExecuteFile()
 {
     $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\\File')->will($this->returnValue($this->fileHelper));
     $this->objectManager->expects($this->at(2))->method('get')->with('Magento\\Downloadable\\Model\\Sample')->will($this->returnValue($this->sampleModel));
     $this->objectManager->expects($this->at(3))->method('get')->with('Magento\\Downloadable\\Helper\\Download')->will($this->returnValue($this->downloadHelper));
     $this->fileHelper->expects($this->once())->method('getFilePath')->will($this->returnValue('filepath/sample.jpg'));
     $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('file'));
     $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('file'));
     $this->objectManager->expects($this->once())->method('create')->will($this->returnValue($this->sampleModel));
     $this->sample->execute();
 }
 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));
 }