public function testBeforeSaveWithExistingFile()
 {
     $value = 'filename.jpg';
     $this->imageBackend->setValue([['url' => 'http://magento2.com/pub/media/tmp/image/' . $value, 'file' => $value, 'size' => 234234, 'exists' => true]]);
     $this->imageBackend->beforeSave();
     $this->assertEquals($value, $this->imageBackend->getValue());
 }
 public function testSaveToTmp()
 {
     $path = 'design/header/logo_src';
     $fieldCode = 'header_logo_src';
     $metadata = [$fieldCode => ['path' => $path, 'backend_model' => 'Magento\\Theme\\Model\\Design\\Backend\\Image']];
     $this->metadataProvider->expects($this->once())->method('get')->willReturn($metadata);
     $this->backendModelFactory->expects($this->once())->method('createByPath')->with($path)->willReturn($this->backendModel);
     $this->uploaderFactory->expects($this->once())->method('create')->with(['fileId' => $fieldCode])->willReturn($this->uploader);
     $this->uploader->expects($this->once())->method('setAllowRenameFiles')->with(true);
     $this->uploader->expects($this->once())->method('setFilesDispersion')->with(false);
     $this->backendModel->expects($this->once())->method('getAllowedExtensions')->willReturn(['png', 'jpg']);
     $this->uploader->expects($this->once())->method('setAllowedExtensions')->with(['png', 'jpg']);
     $this->uploader->expects($this->once())->method('addValidateCallback')->with('size', $this->backendModel, 'validateMaxSize');
     $this->imageConfig->expects($this->once())->method('getAbsoluteTmpMediaPath')->willReturn('absolute/path/to/tmp/media');
     $this->uploader->expects($this->once())->method('save')->with('absolute/path/to/tmp/media')->willReturn(['file' => 'file.jpg', 'size' => '234234']);
     $this->imageConfig->expects($this->once())->method('getTmpMediaUrl')->with('file.jpg')->willReturn('http://magento2.com/pub/media/tmp/file.jpg');
     $this->assertEquals(['file' => 'file.jpg', 'size' => '234234', 'url' => 'http://magento2.com/pub/media/tmp/file.jpg'], $this->imageProcessor->saveToTmp($fieldCode));
 }