@@ -162,6 +162,9 @@ public function testSaveWithNoPreviousData()
162
162
$ imageContent ->expects ($ this ->any ())
163
163
->method ('getName ' )
164
164
->willReturn ('testFileName ' );
165
+ $ imageContent ->expects ($ this ->any ())
166
+ ->method ('getType ' )
167
+ ->willReturn ('image/jpg ' );
165
168
166
169
$ imageDataObject = $ this ->getMockBuilder ('Magento\Framework\Api\AttributeValue ' )
167
170
->disableOriginalConstructor ()
@@ -200,7 +203,7 @@ public function testSaveWithPreviousData()
200
203
->willReturn ('testImageData ' );
201
204
$ imageContent ->expects ($ this ->any ())
202
205
->method ('getName ' )
203
- ->willReturn ('testFileName ' );
206
+ ->willReturn ('testFileName.png ' );
204
207
205
208
$ imageDataObject = $ this ->getMockBuilder ('Magento\Framework\Api\AttributeValue ' )
206
209
->disableOriginalConstructor ()
@@ -238,4 +241,43 @@ public function testSaveWithPreviousData()
238
241
239
242
$ this ->assertEquals ($ imageData , $ this ->imageProcessor ->save ($ imageData , 'testEntityType ' , $ prevImageData ));
240
243
}
244
+
245
+ /**
246
+ * @expectedException \Magento\Framework\Exception\InputException
247
+ * @expectedExceptionMessage Cannot recognize image extension.
248
+ */
249
+ public function testSaveWithoutFileExtension ()
250
+ {
251
+ $ imageContent = $ this ->getMockBuilder ('Magento\Framework\Api\Data\ImageContentInterface ' )
252
+ ->disableOriginalConstructor ()
253
+ ->getMock ();
254
+ $ imageContent ->expects ($ this ->once ())
255
+ ->method ('getBase64EncodedData ' )
256
+ ->willReturn ('testImageData ' );
257
+ $ imageContent ->expects ($ this ->once ())
258
+ ->method ('getName ' )
259
+ ->willReturn ('testFileName ' );
260
+
261
+ $ imageDataObject = $ this ->getMockBuilder ('Magento\Framework\Api\AttributeValue ' )
262
+ ->disableOriginalConstructor ()
263
+ ->getMock ();
264
+ $ imageDataObject ->expects ($ this ->once ())
265
+ ->method ('getValue ' )
266
+ ->willReturn ($ imageContent );
267
+
268
+ $ imageData = $ this ->getMockForAbstractClass ('Magento\Framework\Api\CustomAttributesDataInterface ' );
269
+ $ imageData ->expects ($ this ->once ())
270
+ ->method ('getCustomAttributes ' )
271
+ ->willReturn ([]);
272
+
273
+ $ this ->dataObjectHelperMock ->expects ($ this ->once ())
274
+ ->method ('getCustomAttributeValueByType ' )
275
+ ->willReturn ([$ imageDataObject ]);
276
+
277
+ $ this ->contentValidatorMock ->expects ($ this ->once ())
278
+ ->method ('isValid ' )
279
+ ->willReturn (true );
280
+
281
+ $ this ->assertEquals ($ imageData , $ this ->imageProcessor ->save ($ imageData , 'testEntityType ' ));
282
+ }
241
283
}
0 commit comments