56 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
58 $this->directoryWriteMock = $this->getMockForAbstractClass(
61 $this->fileSystemMock = $this->getMockBuilder(\
Magento\Framework\Filesystem::class)
62 ->disableOriginalConstructor()
64 $this->fileSystemMock->expects($this->any())
65 ->method(
'getDirectoryWrite')
66 ->willReturn($this->directoryWriteMock);
67 $this->contentValidatorMock = $this->getMockBuilder(
68 \
Magento\Framework\Api\ImageContentValidatorInterface::class
70 ->disableOriginalConstructor()
72 $this->dataObjectHelperMock = $this->getMockBuilder(\
Magento\Framework\Api\DataObjectHelper::class)
73 ->disableOriginalConstructor()
75 $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
76 ->disableOriginalConstructor()
78 $this->uploaderMock = $this->getMockBuilder(\
Magento\Framework\Api\Uploader::class)
81 'processFileAttributes',
83 'setFilenamesCaseSensitivity',
84 'setAllowRenameFiles',
89 ->disableOriginalConstructor()
92 $this->imageProcessor = $this->objectManager->getObject(
93 \
Magento\Framework\Api\ImageProcessor::class,
95 'fileSystem' => $this->fileSystemMock,
96 'contentValidator' => $this->contentValidatorMock,
97 'dataObjectHelper' => $this->dataObjectHelperMock,
98 'logger' => $this->loggerMock,
99 'uploader' => $this->uploaderMock
106 $imageDataMock = $this->getMockBuilder(\
Magento\Framework\Api\CustomAttributesDataInterface::class)
107 ->disableOriginalConstructor()
109 $imageDataMock->expects($this->once())
110 ->method(
'getCustomAttributes')
113 $this->dataObjectHelperMock->expects($this->once())
114 ->method(
'getCustomAttributeValueByType')
117 $this->assertEquals($imageDataMock, $this->imageProcessor->save($imageDataMock,
'testEntityType'));
127 ->disableOriginalConstructor()
129 $imageDataObject = $this->getMockBuilder(\
Magento\Framework\Api\AttributeValue::class)
130 ->disableOriginalConstructor()
132 $imageDataObject->expects($this->once())
136 $imageDataMock = $this->getMockBuilder(\
Magento\Framework\Api\CustomAttributesDataInterface::class)
137 ->disableOriginalConstructor()
139 $imageDataMock->expects($this->once())
140 ->method(
'getCustomAttributes')
143 $this->dataObjectHelperMock->expects($this->once())
144 ->method(
'getCustomAttributeValueByType')
145 ->willReturn([$imageDataObject]);
147 $this->contentValidatorMock->expects($this->once())
151 $this->imageProcessor->save($imageDataMock,
'testEntityType');
157 ->disableOriginalConstructor()
160 ->method(
'getBase64EncodedData')
161 ->willReturn(
'testImageData');
164 ->willReturn(
'testFileName');
167 ->willReturn(
'image/jpg');
169 $imageDataObject = $this->getMockBuilder(\
Magento\Framework\Api\AttributeValue::class)
170 ->disableOriginalConstructor()
172 $imageDataObject->expects($this->once())
176 $imageData = $this->getMockForAbstractClass(\
Magento\Framework\Api\CustomAttributesDataInterface::class);
177 $imageData->expects($this->once())
178 ->method(
'getCustomAttributes')
181 $this->dataObjectHelperMock->expects($this->once())
182 ->method(
'getCustomAttributeValueByType')
183 ->willReturn([$imageDataObject]);
185 $this->contentValidatorMock->expects($this->once())
189 $this->directoryWriteMock->expects($this->any())
190 ->method(
'getAbsolutePath')
191 ->willReturn(
'testPath');
193 $this->assertEquals($imageData, $this->imageProcessor->save($imageData,
'testEntityType'));
199 ->disableOriginalConstructor()
202 ->method(
'getBase64EncodedData')
203 ->willReturn(
'testImageData');
206 ->willReturn(
'testFileName.png');
208 $imageDataObject = $this->getMockBuilder(\
Magento\Framework\Api\AttributeValue::class)
209 ->disableOriginalConstructor()
211 $imageDataObject->expects($this->once())
215 $imageData = $this->getMockForAbstractClass(\
Magento\Framework\Api\CustomAttributesDataInterface::class);
216 $imageData->expects($this->once())
217 ->method(
'getCustomAttributes')
220 $this->dataObjectHelperMock->expects($this->once())
221 ->method(
'getCustomAttributeValueByType')
222 ->willReturn([$imageDataObject]);
224 $this->contentValidatorMock->expects($this->once())
228 $this->directoryWriteMock->expects($this->any())
229 ->method(
'getAbsolutePath')
230 ->willReturn(
'testPath');
232 $prevImageAttribute = $this->getMockForAbstractClass(\
Magento\Framework\Api\AttributeInterface::class);
233 $prevImageAttribute->expects($this->once())
235 ->willReturn(
'testImagePath');
237 $prevImageData = $this->getMockForAbstractClass(\
Magento\Framework\Api\CustomAttributesDataInterface::class);
238 $prevImageData->expects($this->once())
239 ->method(
'getCustomAttribute')
240 ->willReturn($prevImageAttribute);
242 $this->assertEquals($imageData, $this->imageProcessor->save($imageData,
'testEntityType', $prevImageData));
252 ->disableOriginalConstructor()
255 ->method(
'getBase64EncodedData')
256 ->willReturn(
'testImageData');
259 ->willReturn(
'testFileName');
261 $imageDataObject = $this->getMockBuilder(\
Magento\Framework\Api\AttributeValue::class)
262 ->disableOriginalConstructor()
264 $imageDataObject->expects($this->once())
268 $imageData = $this->getMockForAbstractClass(\
Magento\Framework\Api\CustomAttributesDataInterface::class);
269 $imageData->expects($this->once())
270 ->method(
'getCustomAttributes')
273 $this->dataObjectHelperMock->expects($this->once())
274 ->method(
'getCustomAttributeValueByType')
275 ->willReturn([$imageDataObject]);
277 $this->contentValidatorMock->expects($this->once())
281 $this->assertEquals($imageData, $this->imageProcessor->save($imageData,
'testEntityType'));
testSaveWithoutFileExtension()
testSaveWithNoImageData()
testSaveWithNoPreviousData()
testSaveWithPreviousData()