@@ -1367,23 +1367,53 @@ protected function setupProductMocksForSave(): void
13671367 public function testSaveExistingWithNewMediaGalleryEntries (): void
13681368 {
13691369 $ 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+ ];
13701385 $ newEntriesData = [
13711386 'images ' => [
13721387 [
1373- 'value_id ' => null ,
1374- 'label ' => "label_text " ,
1388+ 'value_id ' => 5 ,
1389+ "label " => "new_label_text " ,
1390+ 'file ' => 'filename1 ' ,
13751391 'position ' => 10 ,
13761392 '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
13871417 ]
13881418 ];
13891419
@@ -1395,7 +1425,7 @@ public function testSaveExistingWithNewMediaGalleryEntries(): void
13951425 ->method ('toNestedArray ' )
13961426 ->willReturn ($ this ->productData );
13971427
1398- $ this ->initializedProduct ->setData ('media_gallery ' , $ newEntriesData );
1428+ $ this ->initializedProduct ->setData ('media_gallery ' , $ initializedEntriesData );
13991429 $ this ->initializedProduct ->expects ($ this ->any ())
14001430 ->method ('getMediaAttributes ' )
14011431 ->willReturn (["image " => "imageAttribute " , "small_image " => "small_image_attribute " ]);
@@ -1431,10 +1461,19 @@ public function testSaveExistingWithNewMediaGalleryEntries(): void
14311461 ->method ('processImageContent ' )
14321462 ->willReturn ($ absolutePath );
14331463
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+ );
14381477 $ this ->processor ->expects ($ this ->once ())->method ('updateImage ' )
14391478 ->with (
14401479 $ this ->initializedProduct ,
0 commit comments