Пример #1
0
 /**
  * Get maximum upload size message
  *
  * @return string
  */
 public function getMaxUploadSizeMessage()
 {
     $maxImageSize = $this->_fileSize->getMaxFileSizeInMb();
     if ($maxImageSize) {
         $message = __('The total size of the uploadable files can\'t be more than %1M', $maxImageSize);
     } else {
         $message = __('System doesn\'t allow to get file upload settings');
     }
     return $message;
 }
Пример #2
0
 /**
  * Get maximum upload size message
  *
  * @return \Magento\Framework\Phrase
  */
 public function getMaxUploadSizeMessage()
 {
     $maxImageSize = $this->_fileSize->getMaxFileSizeInMb();
     if ($maxImageSize) {
         $message = __('Make sure your file isn\'t more than %1M.', $maxImageSize);
     } else {
         $message = __('We can\'t provide the upload settings right now.');
     }
     return $message;
 }
Пример #3
0
 protected function prepare()
 {
     $relativePath = '/custom_options/quote/file';
     $absolutePath = '/absolute/path' . $relativePath;
     $this->directoryRead->expects($this->once())->method('isFile')->with('/custom_options/quote/file')->willReturn(true);
     $this->directoryRead->expects($this->once())->method('getAbsolutePath')->with('/custom_options/quote/file')->willReturn($absolutePath);
     $this->validateFactory->expects($this->once())->method('create')->willReturn($this->zendValidator);
     $this->option->expects($this->once())->method('getImageSizeX')->willReturn(0);
     $this->option->expects($this->once())->method('getImageSizeY')->willReturn(0);
     $this->option->expects($this->once())->method('getFileExtension')->willReturn('');
     $this->scopeConfig->expects($this->once())->method('getValue')->with('catalog/custom_options/forbidden_extensions', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn('');
     $this->fileSize->expects($this->once())->method('getMaxFileSize')->willReturn(9999999);
     $this->zendValidator->expects($this->any())->method('addValidator');
     $this->zendValidator->expects($this->once())->method('isValid')->with($absolutePath)->willReturn(true);
 }
Пример #4
0
 /**
  * @param \Zend_File_Transfer_Adapter_Http|\Zend_Validate $object
  * @param \Magento\Catalog\Model\Product\Option $option
  * @param array $fileFullPath
  * @return \Zend_File_Transfer_Adapter_Http|\Zend_Validate $object
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function buildImageValidator($object, $option, $fileFullPath = null)
 {
     $dimensions = [];
     if ($option->getImageSizeX() > 0) {
         $dimensions['maxwidth'] = $option->getImageSizeX();
     }
     if ($option->getImageSizeY() > 0) {
         $dimensions['maxheight'] = $option->getImageSizeY();
     }
     if (count($dimensions) > 0) {
         if ($fileFullPath !== null && !$this->isImage($fileFullPath)) {
             throw new \Magento\Framework\Exception\InputException(__('File \'%1\' is not an image.', $option->getTitle()));
         }
         $object->addValidator(new \Zend_Validate_File_ImageSize($dimensions));
     }
     // File extension
     $allowed = $this->parseExtensionsString($option->getFileExtension());
     if ($allowed !== null) {
         $object->addValidator(new \Zend_Validate_File_Extension($allowed));
     } else {
         $forbidden = $this->parseExtensionsString($this->getConfigData('forbidden_extensions'));
         if ($forbidden !== null) {
             $object->addValidator(new \Zend_Validate_File_ExcludeExtension($forbidden));
         }
     }
     $object->addValidator(new \Zend_Validate_File_FilesSize(['max' => $this->fileSize->getMaxFileSize()]));
     return $object;
 }
Пример #5
0
 /**
  * Get note string for theme's preview image
  *
  * @return \Magento\Framework\Phrase
  */
 protected function _getPreviewImageNote()
 {
     $maxImageSize = $this->_fileSize->getMaxFileSizeInMb();
     if ($maxImageSize) {
         return __('Max image size %1M', $maxImageSize);
     } else {
         return __('Something is wrong with the file upload settings.');
     }
 }
Пример #6
0
 public function testUploadJsFile()
 {
     $fileName = 'file.name';
     $this->_fileSizeMock->expects($this->once())->method('getMaxFileSize')->will($this->returnValue(600 * self::MB_MULTIPLIER));
     $this->_service = new \Magento\Theme\Model\Uploader\Service($this->_filesystemMock, $this->_fileSizeMock, $this->_uploaderFactory, ['js' => '500M']);
     $this->_directoryMock->expects($this->once())->method('getRelativePath')->with($fileName)->will($this->returnValue($fileName));
     $this->_directoryMock->expects($this->once())->method('readFile')->with($fileName)->will($this->returnValue('content'));
     $this->_uploader->expects($this->once())->method('validateFile')->will($this->returnValue(['name' => $fileName, 'tmp_name' => $fileName]));
     $this->_uploader->expects($this->once())->method('getFileSize')->will($this->returnValue('499'));
     $this->assertEquals(['content' => 'content', 'filename' => $fileName], $this->_service->uploadJsFile($fileName));
 }
Пример #7
0
 /**
  * Get maximum file size to upload in bytes
  *
  * @return int
  */
 protected function _getFileMaxSize()
 {
     return $this->_fileConfig->getMaxFileSize();
 }
Пример #8
0
 /**
  * @dataProvider getConvertSizeToIntegerDataProvider
  * @backupStaticAttributes
  * @param string $value
  * @param int $expected
  */
 public function testConvertSizeToInteger($value, $expected)
 {
     $this->assertEquals($expected, $this->_fileSize->convertSizeToInteger($value));
 }
Пример #9
0
 /**
  * Get js upload max size in megabytes
  *
  * @return float
  */
 public function getJsUploadMaxSizeInMb()
 {
     return $this->_fileSize->getFileSizeInMb($this->getJsUploadMaxSize());
 }
Пример #10
0
 /**
  * @backupStaticAttributes
  */
 public function testGetMaxFileSize()
 {
     $this->assertGreaterThanOrEqual(0, $this->_fileSize->getMaxFileSize());
     $this->assertGreaterThanOrEqual(0, $this->_fileSize->getMaxFileSizeInMb());
 }