/** * @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')); }
/** * 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; }