@@ -626,6 +626,7 @@ function ($input) {
626
626
explode (', ' , $ optionData )
627
627
)
628
628
);
629
+ // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge
629
630
$ option = array_merge (...$ option );
630
631
631
632
if (!empty ($ option ['type ' ]) && !empty ($ option ['name ' ])) {
@@ -692,12 +693,14 @@ protected function mergeWithExistingData(
692
693
}
693
694
} else {
694
695
$ existingOptionId = array_search ($ optionKey , $ expectedOptions );
696
+ // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge
695
697
$ expectedData [$ existingOptionId ] = array_merge (
696
698
$ this ->getOptionData ($ option ),
697
699
$ expectedData [$ existingOptionId ]
698
700
);
699
701
if ($ optionValues ) {
700
702
foreach ($ optionValues as $ optionKey => $ optionValue ) {
703
+ // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge
701
704
$ expectedValues [$ existingOptionId ][$ optionKey ] = array_merge (
702
705
$ optionValue ,
703
706
$ expectedValues [$ existingOptionId ][$ optionKey ]
@@ -842,6 +845,58 @@ public function testSaveMediaImage()
842
845
$ this ->assertEquals ('Additional Image Label Two ' , $ additionalImageTwoItem ->getLabel ());
843
846
}
844
847
848
+ /**
849
+ * Test that new images should be added after the existing ones.
850
+ *
851
+ * @magentoDataFixture mediaImportImageFixture
852
+ * @magentoAppIsolation enabled
853
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
854
+ */
855
+ public function testNewImagesShouldBeAddedAfterExistingOnes ()
856
+ {
857
+ $ this ->importDataForMediaTest ('import_media.csv ' );
858
+
859
+ $ product = $ this ->getProductBySku ('simple_new ' );
860
+
861
+ $ items = array_values ($ product ->getMediaGalleryImages ()->getItems ());
862
+
863
+ $ images = [
864
+ ['file ' => '/m/a/magento_image.jpg ' , 'label ' => 'Image Label ' ],
865
+ ['file ' => '/m/a/magento_small_image.jpg ' , 'label ' => 'Small Image Label ' ],
866
+ ['file ' => '/m/a/magento_thumbnail.jpg ' , 'label ' => 'Thumbnail Label ' ],
867
+ ['file ' => '/m/a/magento_additional_image_one.jpg ' , 'label ' => 'Additional Image Label One ' ],
868
+ ['file ' => '/m/a/magento_additional_image_two.jpg ' , 'label ' => 'Additional Image Label Two ' ],
869
+ ];
870
+
871
+ $ this ->assertCount (5 , $ items );
872
+ $ this ->assertEquals (
873
+ $ images ,
874
+ array_map (
875
+ function (\Magento \Framework \DataObject $ item ) {
876
+ return $ item ->toArray (['file ' , 'label ' ]);
877
+ },
878
+ $ items
879
+ )
880
+ );
881
+
882
+ $ this ->importDataForMediaTest ('import_media_additional_images.csv ' );
883
+ $ product ->cleanModelCache ();
884
+ $ product = $ this ->getProductBySku ('simple_new ' );
885
+ $ items = array_values ($ product ->getMediaGalleryImages ()->getItems ());
886
+ $ images [] = ['file ' => '/m/a/magento_additional_image_three.jpg ' , 'label ' => '' ];
887
+ $ images [] = ['file ' => '/m/a/magento_additional_image_four.jpg ' , 'label ' => '' ];
888
+ $ this ->assertCount (7 , $ items );
889
+ $ this ->assertEquals (
890
+ $ images ,
891
+ array_map (
892
+ function (\Magento \Framework \DataObject $ item ) {
893
+ return $ item ->toArray (['file ' , 'label ' ]);
894
+ },
895
+ $ items
896
+ )
897
+ );
898
+ }
899
+
845
900
/**
846
901
* Test that errors occurred during importing images are logged.
847
902
*
@@ -892,6 +947,14 @@ public static function mediaImportImageFixture()
892
947
'source ' => __DIR__ . '/_files/magento_additional_image_two.jpg ' ,
893
948
'dest ' => $ dirPath . '/magento_additional_image_two.jpg ' ,
894
949
],
950
+ [
951
+ 'source ' => __DIR__ . '/_files/magento_additional_image_three.jpg ' ,
952
+ 'dest ' => $ dirPath . '/magento_additional_image_three.jpg ' ,
953
+ ],
954
+ [
955
+ 'source ' => __DIR__ . '/_files/magento_additional_image_four.jpg ' ,
956
+ 'dest ' => $ dirPath . '/magento_additional_image_four.jpg ' ,
957
+ ],
895
958
];
896
959
897
960
foreach ($ items as $ item ) {
@@ -2023,7 +2086,17 @@ private function importDataForMediaTest(string $fileName, int $expectedErrors =
2023
2086
$ this ->assertTrue ($ errors ->getErrorsCount () == 0 );
2024
2087
2025
2088
$ this ->_model ->importData ();
2026
- $ this ->assertTrue ($ this ->_model ->getErrorAggregator ()->getErrorsCount () == $ expectedErrors );
2089
+ $ this ->assertEquals (
2090
+ $ expectedErrors ,
2091
+ $ this ->_model ->getErrorAggregator ()->getErrorsCount (),
2092
+ array_reduce (
2093
+ $ this ->_model ->getErrorAggregator ()->getAllErrors (),
2094
+ function ($ output , $ error ) {
2095
+ return "$ output \n{$ error ->getErrorMessage ()}" ;
2096
+ },
2097
+ ''
2098
+ )
2099
+ );
2027
2100
}
2028
2101
2029
2102
/**
0 commit comments