@@ -1367,23 +1367,53 @@ protected function setupProductMocksForSave(): void
1367
1367
public function testSaveExistingWithNewMediaGalleryEntries (): void
1368
1368
{
1369
1369
$ this ->storeManager ->expects ($ this ->any ())->method ('getWebsites ' )->willReturn ([1 => 'default ' ]);
1370
+ $ newEntry = [
1371
+ 'value_id ' => null ,
1372
+ 'label ' => "label_text " ,
1373
+ 'position ' => 10 ,
1374
+ 'disabled ' => false ,
1375
+ 'types ' => ['image ' , 'small_image ' ],
1376
+ 'content ' => [
1377
+ 'data ' => [
1378
+ ImageContentInterface::NAME => 'filename ' ,
1379
+ ImageContentInterface::TYPE => 'image/jpeg ' ,
1380
+ ImageContentInterface::BASE64_ENCODED_DATA => 'encoded_content '
1381
+ ]
1382
+ ],
1383
+ 'media_type ' => 'media_type '
1384
+ ];
1370
1385
$ newEntriesData = [
1371
1386
'images ' => [
1372
1387
[
1373
- 'value_id ' => null ,
1374
- 'label ' => "label_text " ,
1388
+ 'value_id ' => 5 ,
1389
+ "label " => "new_label_text " ,
1390
+ 'file ' => 'filename1 ' ,
1375
1391
'position ' => 10 ,
1376
1392
'disabled ' => false ,
1377
- 'types ' => ['image ' , 'small_image ' ],
1378
- 'content ' => [
1379
- 'data ' => [
1380
- ImageContentInterface::NAME => 'filename ' ,
1381
- ImageContentInterface::TYPE => 'image/jpeg ' ,
1382
- ImageContentInterface::BASE64_ENCODED_DATA => 'encoded_content '
1383
- ]
1384
- ],
1385
- 'media_type ' => 'media_type '
1386
- ]
1393
+ 'types ' => ['image ' , 'small_image ' ]
1394
+ ],
1395
+ $ newEntry
1396
+ ]
1397
+ ];
1398
+ $ initializedEntriesData = [
1399
+ 'images ' => [
1400
+ [
1401
+ 'value_id ' => 5 ,
1402
+ "label " => "label_text " ,
1403
+ 'file ' => 'filename1 ' ,
1404
+ 'position ' => 10 ,
1405
+ 'disabled ' => false ,
1406
+ 'types ' => ['image ' , 'small_image ' ]
1407
+ ],
1408
+ [
1409
+ 'value_id ' => 6 ,
1410
+ "label " => "label_text2 " ,
1411
+ 'file ' => 'filename2 ' ,
1412
+ 'position ' => 10 ,
1413
+ 'disabled ' => false ,
1414
+ 'types ' => ['image ' , 'small_image ' ]
1415
+ ],
1416
+ $ newEntry
1387
1417
]
1388
1418
];
1389
1419
@@ -1395,7 +1425,7 @@ public function testSaveExistingWithNewMediaGalleryEntries(): void
1395
1425
->method ('toNestedArray ' )
1396
1426
->willReturn ($ this ->productData );
1397
1427
1398
- $ this ->initializedProduct ->setData ('media_gallery ' , $ newEntriesData );
1428
+ $ this ->initializedProduct ->setData ('media_gallery ' , $ initializedEntriesData );
1399
1429
$ this ->initializedProduct ->expects ($ this ->any ())
1400
1430
->method ('getMediaAttributes ' )
1401
1431
->willReturn (["image " => "imageAttribute " , "small_image " => "small_image_attribute " ]);
@@ -1431,10 +1461,19 @@ public function testSaveExistingWithNewMediaGalleryEntries(): void
1431
1461
->method ('processImageContent ' )
1432
1462
->willReturn ($ absolutePath );
1433
1463
1434
- $ imageFileUri = "imageFileUri " ;
1435
- $ this ->processor ->expects ($ this ->once ())->method ('addImage ' )
1436
- ->with ($ this ->initializedProduct , $ mediaTmpPath . $ absolutePath , ['image ' , 'small_image ' ], true , false )
1437
- ->willReturn ($ imageFileUri );
1464
+ $ imageFileUri = $ mediaTmpPath . $ absolutePath ;
1465
+
1466
+ $ this ->processor ->expects ($ this ->once ())
1467
+ ->method ('addImage ' )
1468
+ ->willReturnCallback (
1469
+ function ($ product , $ imageFileUri ) use ($ newEntriesData ) {
1470
+ foreach ($ product ['media_gallery ' ]['images ' ] as $ entry ) {
1471
+ $ this ->assertArrayNotHasKey ('removed ' , $ entry );
1472
+ }
1473
+ $ this ->initializedProduct ->setData ('media_gallery ' , $ newEntriesData );
1474
+ return $ imageFileUri ;
1475
+ }
1476
+ );
1438
1477
$ this ->processor ->expects ($ this ->once ())->method ('updateImage ' )
1439
1478
->with (
1440
1479
$ this ->initializedProduct ,
0 commit comments