/**
  * @dataProvider uploadDataProvider
  * @covers \Magento\Framework\View\Design\Theme\Image\Uploader::uploadPreviewImage
  */
 public function testUploadPreviewImage($isUploaded, $isValid, $checkExtension, $save, $result, $exception)
 {
     if ($exception) {
         $this->setExpectedException($exception);
     }
     $testScope = 'scope';
     $this->_transferAdapterMock->expects($this->any())->method('isUploaded')->with($testScope)->will($this->returnValue($isUploaded));
     $this->_transferAdapterMock->expects($this->any())->method('isValid')->with($testScope)->will($this->returnValue($isValid));
     $this->_fileUploader->expects($this->any())->method('checkAllowedExtension')->will($this->returnValue($checkExtension));
     $this->_fileUploader->expects($this->any())->method('save')->will($this->returnValue($save));
     $this->_fileUploader->expects($this->any())->method('getUploadedFileName')->will($this->returnValue('test_filename'));
     $this->assertEquals($result, $this->_model->uploadPreviewImage($testScope, '/tmp'));
 }
 /**
  * @covers \Magento\Framework\View\Design\Theme\Image::uploadPreviewImage
  */
 public function testUploadPreviewImage()
 {
     $scope = 'test_scope';
     $tmpFilePath = '/media_path/tmp/temporary.png';
     $this->_themeMock->setData($this->_getThemeSampleData());
     $this->_themeMock->setData('preview_image', 'test.png');
     $this->_uploaderMock->expects($this->once())->method('uploadPreviewImage')->with($scope, '/media_path/tmp')->will($this->returnValue($tmpFilePath));
     $this->_mediaDirectoryMock->expects($this->at(0))->method('getRelativePath')->will($this->returnArgument(0));
     $this->_mediaDirectoryMock->expects($this->at(1))->method('delete')->with($this->stringContains('test.png'));
     $this->_mediaDirectoryMock->expects($this->at(2))->method('delete')->with($tmpFilePath);
     $this->_model->uploadPreviewImage($scope);
 }
Exemple #3
0
 /**
  * Upload and create preview image
  *
  * @param string $scope the request key for file
  * @return $this
  */
 public function uploadPreviewImage($scope)
 {
     $tmpDirPath = $this->themeImagePath->getTemporaryDirectory();
     $tmpFilePath = $this->uploader->uploadPreviewImage($scope, $tmpDirPath);
     if ($tmpFilePath) {
         if ($this->theme->getPreviewImage()) {
             $this->removePreviewImage();
         }
         $this->createPreviewImage($tmpFilePath);
         $this->mediaDirectory->delete($tmpFilePath);
     }
     return $this;
 }