@@ -917,15 +917,15 @@ public function testSaveMediaImageError()
917
917
*/
918
918
public static function mediaImportImageFixture ()
919
919
{
920
- /** @var \Magento\Framework\Filesystem\Directory\Write $mediaDirectory */
921
- $ mediaDirectory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
920
+ /** @var \Magento\Framework\Filesystem\Directory\Write $varDirectory */
921
+ $ varDirectory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
922
922
\Magento \Framework \Filesystem::class
923
923
)->getDirectoryWrite (
924
- DirectoryList::MEDIA
924
+ DirectoryList::VAR_DIR
925
925
);
926
926
927
- $ mediaDirectory ->create ('import ' );
928
- $ dirPath = $ mediaDirectory ->getAbsolutePath ('import ' );
927
+ $ varDirectory ->create ('import ' . DIRECTORY_SEPARATOR . ' images ' );
928
+ $ dirPath = $ varDirectory ->getAbsolutePath ('import ' . DIRECTORY_SEPARATOR . ' images ' );
929
929
930
930
$ items = [
931
931
[
@@ -968,13 +968,15 @@ public static function mediaImportImageFixture()
968
968
*/
969
969
public static function mediaImportImageFixtureRollback ()
970
970
{
971
- /** @var \Magento\Framework\Filesystem\Directory\Write $mediaDirectory */
972
- $ mediaDirectory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
971
+ $ fileSystem = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
973
972
\Magento \Framework \Filesystem::class
974
- )->getDirectoryWrite (
975
- DirectoryList::MEDIA
976
973
);
977
- $ mediaDirectory ->delete ('import ' );
974
+ /** @var \Magento\Framework\Filesystem\Directory\Write $mediaDirectory */
975
+ $ mediaDirectory = $ fileSystem ->getDirectoryWrite (DirectoryList::MEDIA );
976
+
977
+ /** @var \Magento\Framework\Filesystem\Directory\Write $varDirectory */
978
+ $ varDirectory = $ fileSystem ->getDirectoryWrite (DirectoryList::VAR_DIR );
979
+ $ varDirectory ->delete ('import ' . DIRECTORY_SEPARATOR . 'images ' );
978
980
$ mediaDirectory ->delete ('catalog ' );
979
981
}
980
982
@@ -983,13 +985,13 @@ public static function mediaImportImageFixtureRollback()
983
985
*/
984
986
public static function mediaImportImageFixtureError ()
985
987
{
986
- /** @var \Magento\Framework\Filesystem\Directory\Write $mediaDirectory */
987
- $ mediaDirectory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
988
+ /** @var \Magento\Framework\Filesystem\Directory\Write $varDirectory */
989
+ $ varDirectory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
988
990
\Magento \Framework \Filesystem::class
989
991
)->getDirectoryWrite (
990
- DirectoryList::MEDIA
992
+ DirectoryList::VAR_DIR
991
993
);
992
- $ dirPath = $ mediaDirectory ->getAbsolutePath ('import ' );
994
+ $ dirPath = $ varDirectory ->getAbsolutePath ('import ' . DIRECTORY_SEPARATOR . ' images ' );
993
995
$ items = [
994
996
[
995
997
'source ' => __DIR__ . '/_files/magento_additional_image_error.jpg ' ,
@@ -2133,8 +2135,13 @@ private function importDataForMediaTest(string $fileName, int $expectedErrors =
2133
2135
$ uploader = $ this ->_model ->getUploader ();
2134
2136
2135
2137
$ mediaPath = $ appParams [DirectoryList::MEDIA ][DirectoryList::PATH ];
2136
- $ destDir = $ directory ->getRelativePath ($ mediaPath . '/catalog/product ' );
2137
- $ tmpDir = $ directory ->getRelativePath ($ mediaPath . '/import ' );
2138
+ $ varPath = $ appParams [DirectoryList::VAR_DIR ][DirectoryList::PATH ];
2139
+ $ destDir = $ directory ->getRelativePath (
2140
+ $ mediaPath . DIRECTORY_SEPARATOR . 'catalog ' . DIRECTORY_SEPARATOR . 'product '
2141
+ );
2142
+ $ tmpDir = $ directory ->getRelativePath (
2143
+ $ varPath . DIRECTORY_SEPARATOR . 'import ' . DIRECTORY_SEPARATOR . 'images '
2144
+ );
2138
2145
2139
2146
$ directory ->create ($ destDir );
2140
2147
$ this ->assertTrue ($ uploader ->setDestDir ($ destDir ));
@@ -2581,4 +2588,80 @@ private function importFile(string $fileName): void
2581
2588
2582
2589
$ this ->_model ->importData ();
2583
2590
}
2591
+
2592
+ /**
2593
+ * Hide product images via hide_from_product_page attribute during import CSV.
2594
+ *
2595
+ * @magentoAppIsolation enabled
2596
+ * @magentoDataFixture mediaImportImageFixture
2597
+ * @magentoDataFixture Magento/Catalog/_files/product_with_image.php
2598
+ */
2599
+ public function testImagesAreHiddenAfterImport ()
2600
+ {
2601
+ $ expectedActiveImages = [
2602
+ [
2603
+ 'file ' => '/m/a/magento_additional_image_one.jpg ' ,
2604
+ 'label ' => 'Additional Image Label One ' ,
2605
+ 'disabled ' => '0 '
2606
+ ],
2607
+ [
2608
+ 'file ' => '/m/a/magento_additional_image_two.jpg ' ,
2609
+ 'label ' => 'Additional Image Label Two ' ,
2610
+ 'disabled ' => '0 '
2611
+ ],
2612
+ ];
2613
+
2614
+ $ expectedHiddenImage = [
2615
+ 'file ' => '/m/a/magento_image.jpg ' ,
2616
+ 'label ' => 'Image Alt Text ' ,
2617
+ 'disabled ' => '1 '
2618
+ ];
2619
+ $ expectedAllProductImages = array_merge (
2620
+ [$ expectedHiddenImage ],
2621
+ $ expectedActiveImages
2622
+ );
2623
+
2624
+ $ this ->importDataForMediaTest ('hide_from_product_page_images.csv ' );
2625
+ $ actualAllProductImages = [];
2626
+ $ product = $ this ->getProductBySku ('simple ' );
2627
+
2628
+ // Check that new images are imported and existing image is disabled after import
2629
+ $ productMediaData = $ product ->getData ('media_gallery ' );
2630
+
2631
+ if (is_array ($ productMediaData ['images ' ])) {
2632
+ $ allProductImages = $ productMediaData ['images ' ];
2633
+ $ this ->assertCount (3 , $ productMediaData ['images ' ], 'Images are imported incorrect ' );
2634
+
2635
+ foreach ($ productMediaData ['images ' ] as $ image ) {
2636
+ $ actualAllProductImages [] = [
2637
+ 'file ' => $ image ['file ' ],
2638
+ 'label ' => $ image ['label ' ],
2639
+ 'disabled ' => $ image ['disabled ' ],
2640
+ ];
2641
+ }
2642
+ }
2643
+
2644
+ $ this ->assertEquals (
2645
+ $ expectedAllProductImages ,
2646
+ $ actualAllProductImages ,
2647
+ 'Images statuses are incorrect after import '
2648
+ );
2649
+
2650
+ // Check that on storefront only enabled images are shown
2651
+ $ actualActiveImages = array_values ($ product ->getMediaGalleryImages ()->getItems ());
2652
+ $ this ->assertCount (2 , $ actualActiveImages );
2653
+
2654
+ foreach ($ actualActiveImages as $ actualActiveImage ) {
2655
+ $ this ->assertNotEquals (
2656
+ $ expectedHiddenImage ['file ' ],
2657
+ $ actualActiveImage ->getFile (),
2658
+ 'Image should be hidden after import '
2659
+ );
2660
+ $ this ->assertNotEquals (
2661
+ $ expectedHiddenImage ['label ' ],
2662
+ $ actualActiveImage ->getLabel (),
2663
+ 'Image should be hidden after import '
2664
+ );
2665
+ }
2666
+ }
2584
2667
}
0 commit comments