Example #1
0
 /**
  * @dataProvider dataForExecute
  */
 public function testExecute($fileResult, $expectedResult)
 {
     $this->uploaderFactoryMock->expects($this->once())->method('create')->willReturn($this->uploaderMock);
     $this->adapterFactoryMock->expects($this->once())->method('create')->willReturn($this->adapterMock);
     $this->filesystemMock->expects($this->once())->method('getDirectoryRead')->with('media')->willReturn($this->mediaDirectoryMock);
     $this->uploaderMock->expects($this->once())->method('save')->willReturn($fileResult);
     $this->configMock->expects($this->once())->method('getTmpMediaUrl')->with($fileResult['file'])->willReturn('http://domain.com/tpm_dir/m/a/magento.png');
     $this->swatchHelperMock->expects($this->once())->method('moveImageFromTmp')->with('/m/a/magento.png.tmp')->willReturn('/m/a/magento.png');
     $this->swatchHelperMock->expects($this->once())->method('generateSwatchVariations');
     $this->swatchHelperMock->expects($this->once())->method('getSwatchMediaUrl')->willReturn('http://domain.com/media/path/');
     $this->responseMock->expects($this->once())->method('setBody')->willReturn(json_encode($expectedResult));
     $this->controller->execute();
 }
Example #2
0
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Exception!
  */
 public function testBeforeSaveWithException()
 {
     $value = 'value';
     $groupId = 1;
     $field = 'field';
     $tmpFileName = 'tmp_file_name';
     $name = 'name';
     $path = 'path';
     $scope = 'scope';
     $scopeId = 2;
     $uploadDir = 'upload_dir';
     $fieldConfig = ['upload_dir' => $uploadDir];
     $fileData = ['tmp_name' => $tmpFileName, 'name' => $name];
     $exception = 'Exception!';
     $this->model->setValue($value);
     $this->model->setPath($path);
     $this->model->setScope($scope);
     $this->model->setScopeId($scopeId);
     $this->model->setFieldConfig($fieldConfig);
     $_FILES['groups']['tmp_name'][$groupId]['fields'][$field]['value'] = $tmpFileName;
     $this->requestDataMock->expects($this->once())->method('getTmpName')->with($path)->willReturn($tmpFileName);
     $this->requestDataMock->expects($this->once())->method('getName')->with($path)->willReturn($name);
     $this->uploaderFactoryMock->expects($this->any())->method('create')->with(['fileId' => $fileData])->willReturn($this->uploaderMock);
     $this->uploaderMock->expects($this->once())->method('save')->with($uploadDir, null)->willThrowException(new \Exception($exception));
     $this->model->beforeSave();
 }
Example #3
0
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  */
 public function testUploadInvalidJsFile()
 {
     $fileName = 'file.name';
     $this->_service = new \Magento\Theme\Model\Uploader\Service($this->_filesystemMock, $this->_fileSizeMock, $this->_uploaderFactory, ['js' => '100M']);
     $this->_uploader->expects($this->once())->method('getFileSize')->will($this->returnValue(499 * self::MB_MULTIPLIER));
     $this->_service->uploadJsFile($fileName);
 }
 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));
 }