예제 #1
0
 private function processDownload($resource, $resourceType)
 {
     $this->objectManager->expects($this->at(3))->method('get')->with('Magento\\Downloadable\\Helper\\Download')->willReturn($this->downloadHelper);
     $this->downloadHelper->expects($this->once())->method('setResource')->with($resource, $resourceType)->willReturnSelf();
     $this->downloadHelper->expects($this->once())->method('getFilename')->willReturn('file_name');
     $this->downloadHelper->expects($this->once())->method('getContentType')->willReturn('content_type');
     $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf();
     $this->response->expects($this->at(1))->method('setHeader')->with('Pragma', 'public', true)->willReturnSelf();
     $this->response->expects($this->at(2))->method('setHeader')->with('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->willReturnSelf();
     $this->response->expects($this->at(3))->method('setHeader')->with('Content-type', 'content_type', true)->willReturnSelf();
     $this->downloadHelper->expects($this->once())->method('getFileSize')->willReturn('file_size');
     $this->response->expects($this->at(4))->method('setHeader')->with('Content-Length', 'file_size')->willReturnSelf();
     $this->downloadHelper->expects($this->once())->method('getContentDisposition')->willReturn('content_disposition');
     $this->response->expects($this->at(5))->method('setHeader')->with('Content-Disposition', 'content_disposition; filename=file_name')->willReturnSelf();
     $this->response->expects($this->once())->method('clearBody')->willReturnSelf();
     $this->response->expects($this->once())->method('sendHeaders')->willReturnSelf();
     $this->downloadHelper->expects($this->once())->method('output');
 }
예제 #2
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();
 }
예제 #3
0
 public function testExecuteLinkTypeFile()
 {
     $sampleMock = $this->getMockBuilder('Magento\\Downloadable\\Model\\Sample')->disableOriginalConstructor()->setMethods(['getId', 'load', 'getSampleType', 'getSampleUrl', 'getBaseSamplePath'])->getMock();
     $fileHelperMock = $this->getMockBuilder('Magento\\Downloadable\\Helper\\File')->disableOriginalConstructor()->setMethods(['getFilePath'])->getMock();
     $this->request->expects($this->once())->method('getParam')->with('sample_id', 0)->willReturn('some_sample_id');
     $this->objectManager->expects($this->at(0))->method('create')->with('Magento\\Downloadable\\Model\\Sample')->willReturn($sampleMock);
     $sampleMock->expects($this->once())->method('load')->with('some_sample_id')->willReturnSelf();
     $sampleMock->expects($this->once())->method('getId')->willReturn('some_sample_id');
     $sampleMock->expects($this->any())->method('getSampleType')->willReturn(\Magento\Downloadable\Helper\Download::LINK_TYPE_FILE);
     $this->objectManager->expects($this->at(1))->method('get')->with('Magento\\Downloadable\\Helper\\File')->willReturn($fileHelperMock);
     $fileHelperMock->expects($this->once())->method('getFilePath')->willReturn('file_path');
     $this->objectManager->expects($this->at(2))->method('get')->with('Magento\\Downloadable\\Helper\\Download')->willReturn($this->downloadHelper);
     $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf();
     $this->response->expects($this->any())->method('setHeader')->willReturnSelf();
     $this->downloadHelper->expects($this->once())->method('output')->willThrowException(new \Exception());
     $this->messageManager->expects($this->once())->method('addError')->with('Sorry, there was an error getting requested content. Please contact the store owner.')->willReturnSelf();
     $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('redirect_url');
     $this->response->expects($this->once())->method('setRedirect')->with('redirect_url')->willReturnSelf();
     $this->assertEquals($this->response, $this->sample->execute());
 }