@@ -185,6 +185,16 @@ class ProductTest extends \PHPUnit_Framework_TestCase
185
185
*/
186
186
private $ extensionAttributesFactory ;
187
187
188
+ /**
189
+ * @var \Magento\Framework\Filesystem
190
+ */
191
+ private $ filesystemMock ;
192
+
193
+ /**
194
+ * @var \Magento\Framework\Data\CollectionFactory
195
+ */
196
+ private $ collectionFactoryMock ;
197
+
188
198
/**
189
199
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
190
200
*/
@@ -374,6 +384,12 @@ protected function setUp()
374
384
$ this ->extensionAttributesFactory = $ this ->getMockBuilder (ExtensionAttributesFactory::class)
375
385
->disableOriginalConstructor ()
376
386
->getMock ();
387
+ $ this ->filesystemMock = $ this ->getMockBuilder (\Magento \Framework \Filesystem::class)
388
+ ->disableOriginalConstructor ()
389
+ ->getMock ();
390
+ $ this ->collectionFactoryMock = $ this ->getMockBuilder (\Magento \Framework \Data \CollectionFactory::class)
391
+ ->disableOriginalConstructor ()
392
+ ->getMock ();
377
393
$ this ->mediaConfig = $ this ->getMock (\Magento \Catalog \Model \Product \Media \Config::class, [], [], '' , false );
378
394
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
379
395
@@ -402,6 +418,8 @@ protected function setUp()
402
418
'mediaGalleryEntryConverterPool ' => $ this ->mediaGalleryEntryConverterPoolMock ,
403
419
'linkRepository ' => $ this ->productLinkRepositoryMock ,
404
420
'catalogProductMediaConfig ' => $ this ->mediaConfig ,
421
+ '_filesystem ' => $ this ->filesystemMock ,
422
+ '_collectionFactory ' => $ this ->collectionFactoryMock ,
405
423
'data ' => ['id ' => 1 ]
406
424
]
407
425
);
@@ -1230,6 +1248,71 @@ public function testSetMediaGalleryEntries()
1230
1248
$ this ->assertEquals ($ expectedResult , $ this ->model ->getMediaGallery ());
1231
1249
}
1232
1250
1251
+ public function testGetMediaGalleryImagesMerging ()
1252
+ {
1253
+ $ mediaEntries = [
1254
+ 'images ' => [
1255
+ [
1256
+ 'value_id ' => 1 ,
1257
+ 'file ' => 'imageFile.jpg ' ,
1258
+ 'media_type ' => 'image ' ,
1259
+ ],
1260
+ [
1261
+ 'value_id ' => 1 ,
1262
+ 'file ' => 'imageFile.jpg ' ,
1263
+ ],
1264
+ [
1265
+ 'value_id ' => 2 ,
1266
+ 'file ' => 'smallImageFile.jpg ' ,
1267
+ 'media_type ' => 'image ' ,
1268
+ ],
1269
+ ]
1270
+ ];
1271
+ $ expectedImageDataObject = new \Magento \Framework \DataObject ([
1272
+ 'value_id ' => 1 ,
1273
+ 'file ' => 'imageFile.jpg ' ,
1274
+ 'media_type ' => 'image ' ,
1275
+ 'url ' => 'http://magento.dev/pub/imageFile.jpg ' ,
1276
+ 'id ' => 1 ,
1277
+ 'path ' => '/var/www/html/pub/imageFile.jpg ' ,
1278
+ ]);
1279
+ $ expectedSmallImageDataObject = new \Magento \Framework \DataObject ([
1280
+ 'value_id ' => 2 ,
1281
+ 'file ' => 'smallImageFile.jpg ' ,
1282
+ 'media_type ' => 'image ' ,
1283
+ 'url ' => 'http://magento.dev/pub/smallImageFile.jpg ' ,
1284
+ 'id ' => 2 ,
1285
+ 'path ' => '/var/www/html/pub/smallImageFile.jpg ' ,
1286
+ ]);
1287
+
1288
+ $ directoryMock = $ this ->getMockBuilder (\Magento \Framework \Filesystem \Directory \ReadInterface::class)
1289
+ ->disableOriginalConstructor ()
1290
+ ->getMock ();
1291
+ $ this ->filesystemMock ->expects ($ this ->once ())->method ('getDirectoryRead ' )->willReturn ($ directoryMock );
1292
+ $ this ->model ->setData ('media_gallery ' , $ mediaEntries );
1293
+ $ imagesCollectionMock = $ this ->getMockBuilder (\Magento \Framework \Data \Collection::class)
1294
+ ->disableOriginalConstructor ()
1295
+ ->getMock ();
1296
+ $ this ->collectionFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ imagesCollectionMock );
1297
+ $ imagesCollectionMock ->expects ($ this ->at (2 ))->method ('getItemById ' )->with (1 )->willReturn ($ expectedImageDataObject );
1298
+ $ this ->mediaConfig ->expects ($ this ->at (0 ))
1299
+ ->method ('getMediaUrl ' )
1300
+ ->willReturn ('http://magento.dev/pub/imageFile.jpg ' );
1301
+ $ directoryMock ->expects ($ this ->at (0 ))
1302
+ ->method ('getAbsolutePath ' )
1303
+ ->willReturn ('/var/www/html/pub/imageFile.jpg ' );
1304
+ $ this ->mediaConfig ->expects ($ this ->at (2 ))
1305
+ ->method ('getMediaUrl ' )
1306
+ ->willReturn ('http://magento.dev/pub/smallImageFile.jpg ' );
1307
+ $ directoryMock ->expects ($ this ->at (1 ))
1308
+ ->method ('getAbsolutePath ' )
1309
+ ->willReturn ('/var/www/html/pub/smallImageFile.jpg ' );
1310
+ $ imagesCollectionMock ->expects ($ this ->at (1 ))->method ('addItem ' )->with ($ expectedImageDataObject );
1311
+ $ imagesCollectionMock ->expects ($ this ->at (4 ))->method ('addItem ' )->with ($ expectedSmallImageDataObject );
1312
+
1313
+ $ this ->model ->getMediaGalleryImages ();
1314
+ }
1315
+
1233
1316
public function testGetCustomAttributes ()
1234
1317
{
1235
1318
$ priceCode = 'price ' ;
0 commit comments