@@ -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,13 @@ 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
+ ->setMethods (['create ' ])
393
+ ->getMock ();
377
394
$ this ->mediaConfig = $ this ->getMock (\Magento \Catalog \Model \Product \Media \Config::class, [], [], '' , false );
378
395
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
379
396
@@ -402,6 +419,8 @@ protected function setUp()
402
419
'mediaGalleryEntryConverterPool ' => $ this ->mediaGalleryEntryConverterPoolMock ,
403
420
'linkRepository ' => $ this ->productLinkRepositoryMock ,
404
421
'catalogProductMediaConfig ' => $ this ->mediaConfig ,
422
+ '_filesystem ' => $ this ->filesystemMock ,
423
+ '_collectionFactory ' => $ this ->collectionFactoryMock ,
405
424
'data ' => ['id ' => 1 ]
406
425
]
407
426
);
@@ -1230,6 +1249,71 @@ public function testSetMediaGalleryEntries()
1230
1249
$ this ->assertEquals ($ expectedResult , $ this ->model ->getMediaGallery ());
1231
1250
}
1232
1251
1252
+ public function testGetMediaGalleryImagesMerging ()
1253
+ {
1254
+ $ mediaEntries = [
1255
+ 'images ' => [
1256
+ [
1257
+ 'value_id ' => 1 ,
1258
+ 'file ' => 'imageFile.jpg ' ,
1259
+ 'media_type ' => 'image ' ,
1260
+ ],
1261
+ [
1262
+ 'value_id ' => 1 ,
1263
+ 'file ' => 'imageFile.jpg ' ,
1264
+ ],
1265
+ [
1266
+ 'value_id ' => 2 ,
1267
+ 'file ' => 'smallImageFile.jpg ' ,
1268
+ 'media_type ' => 'image ' ,
1269
+ ],
1270
+ ]
1271
+ ];
1272
+ $ expectedImageDataObject = new \Magento \Framework \DataObject ([
1273
+ 'value_id ' => 1 ,
1274
+ 'file ' => 'imageFile.jpg ' ,
1275
+ 'media_type ' => 'image ' ,
1276
+ 'url ' => 'http://magento.dev/pub/imageFile.jpg ' ,
1277
+ 'id ' => 1 ,
1278
+ 'path ' => '/var/www/html/pub/imageFile.jpg ' ,
1279
+ ]);
1280
+ $ expectedSmallImageDataObject = new \Magento \Framework \DataObject ([
1281
+ 'value_id ' => 2 ,
1282
+ 'file ' => 'smallImageFile.jpg ' ,
1283
+ 'media_type ' => 'image ' ,
1284
+ 'url ' => 'http://magento.dev/pub/smallImageFile.jpg ' ,
1285
+ 'id ' => 2 ,
1286
+ 'path ' => '/var/www/html/pub/smallImageFile.jpg ' ,
1287
+ ]);
1288
+
1289
+ $ directoryMock = $ this ->getMockBuilder (\Magento \Framework \Filesystem \Directory \ReadInterface::class)
1290
+ ->disableOriginalConstructor ()
1291
+ ->getMock ();
1292
+ $ this ->filesystemMock ->expects ($ this ->once ())->method ('getDirectoryRead ' )->willReturn ($ directoryMock );
1293
+ $ this ->model ->setData ('media_gallery ' , $ mediaEntries );
1294
+ $ imagesCollectionMock = $ this ->getMockBuilder (\Magento \Framework \Data \Collection::class)
1295
+ ->disableOriginalConstructor ()
1296
+ ->getMock ();
1297
+ $ this ->collectionFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ imagesCollectionMock );
1298
+ $ imagesCollectionMock ->expects ($ this ->at (2 ))->method ('getItemById ' )->with (1 )->willReturn ($ expectedImageDataObject );
1299
+ $ this ->mediaConfig ->expects ($ this ->at (0 ))
1300
+ ->method ('getMediaUrl ' )
1301
+ ->willReturn ('http://magento.dev/pub/imageFile.jpg ' );
1302
+ $ directoryMock ->expects ($ this ->at (0 ))
1303
+ ->method ('getAbsolutePath ' )
1304
+ ->willReturn ('/var/www/html/pub/imageFile.jpg ' );
1305
+ $ this ->mediaConfig ->expects ($ this ->at (2 ))
1306
+ ->method ('getMediaUrl ' )
1307
+ ->willReturn ('http://magento.dev/pub/smallImageFile.jpg ' );
1308
+ $ directoryMock ->expects ($ this ->at (1 ))
1309
+ ->method ('getAbsolutePath ' )
1310
+ ->willReturn ('/var/www/html/pub/smallImageFile.jpg ' );
1311
+ $ imagesCollectionMock ->expects ($ this ->at (1 ))->method ('addItem ' )->with ($ expectedImageDataObject );
1312
+ $ imagesCollectionMock ->expects ($ this ->at (4 ))->method ('addItem ' )->with ($ expectedSmallImageDataObject );
1313
+
1314
+ $ this ->model ->getMediaGalleryImages ();
1315
+ }
1316
+
1233
1317
public function testGetCustomAttributes ()
1234
1318
{
1235
1319
$ priceCode = 'price ' ;
0 commit comments