/**
  * Save file to storage
  *
  * @param  array $result
  * @return $this
  */
 protected function _afterSave($result)
 {
     if (empty($result['path']) || empty($result['file'])) {
         return $this;
     }
     if ($this->_coreFileStorage->isInternalStorage() || $this->skipDbProcessing()) {
         return $this;
     }
     $this->_result['file'] = $this->_coreFileStorageDb->saveUploadedFile($result);
     return $this;
 }
Beispiel #2
0
 /**
  * Retrieve storage model
  * If storage not defined - retrieve current storage
  *
  * params = array(
  *  connection  => string,  - define connection for model if needed
  *  init        => bool     - force initialization process for storage model
  * )
  *
  * @param  int|null $storage
  * @param  array $params
  * @return AbstractModel|bool
  */
 public function getStorageModel($storage = null, $params = [])
 {
     if (is_null($storage)) {
         $storage = $this->_coreFileStorage->getCurrentStorageCode();
     }
     switch ($storage) {
         case self::STORAGE_MEDIA_FILE_SYSTEM:
             $model = $this->_fileFactory->create();
             break;
         case self::STORAGE_MEDIA_DATABASE:
             $connection = isset($params['connection']) ? $params['connection'] : null;
             $model = $this->_databaseFactory->create(['connectionName' => $connection]);
             break;
         default:
             return false;
     }
     if (isset($params['init']) && $params['init']) {
         $model->init();
     }
     return $model;
 }
 public function testExecuteGetParamImage()
 {
     $decodedFile = 'decoded_file';
     $file = 'file';
     $fileName = 'customer/' . $file;
     $path = 'path';
     $stat = ['size' => 10, 'mtime' => 10];
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['file', null, null], ['image', null, $decodedFile]]);
     $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($fileName)->willReturn($path);
     $this->directoryMock->expects($this->once())->method('stat')->with($path)->willReturn($stat);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->with(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->willReturn($this->directoryMock);
     $this->storage->expects($this->once())->method('processStorageFile')->with($path)->willReturn(true);
     $this->objectManager->expects($this->any())->method('get')->willReturnMap([['Magento\\Framework\\Filesystem', $this->fileSystemMock], ['Magento\\MediaStorage\\Helper\\File\\Storage', $this->storage]]);
     $this->urlDecoderMock->expects($this->once())->method('decode')->with($decodedFile)->willReturn($file);
     $this->resultRawMock->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf();
     $this->resultRawMock->expects($this->any())->method('setHeader')->willReturnMap([['Pragma', 'public', true, $this->resultRawMock], ['Content-type', 'application/octet-stream', true, $this->resultRawMock], ['Content-Length', $stat['size'], false, $this->resultRawMock], ['Pragma', 'public', true, $this->resultRawMock]]);
     $this->resultRawFactoryMock = $this->getMock('Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false);
     $this->resultRawFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRawMock);
     /** @var \Magento\Customer\Controller\Adminhtml\Index\Viewfile $controller */
     $controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Viewfile', ['context' => $this->contextMock, 'urlDecoder' => $this->urlDecoderMock, 'resultRawFactory' => $this->resultRawFactoryMock]);
     $this->assertSame($this->resultRawMock, $controller->execute());
 }
 public function testSaveFileToFileSystem()
 {
     $file = 'file';
     $this->filesystemStorageMock->expects($this->once())->method('saveFile')->with($file, true)->will($this->returnValue(1));
     $this->assertEquals(1, $this->helper->saveFileToFileSystem($file));
 }