@@ -416,7 +416,7 @@ public function testDeleteWithMultiWebsites(): void
416416 $ product ->setWebsiteIds ([$ defaultWebsiteId , $ secondWebsiteId ]);
417417 $ this ->productRepository ->save ($ product );
418418 // Assert that product image has roles in global scope only
419- $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product );
419+ $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product, $ imageRoles );
420420 $ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['image ' ]);
421421 $ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['small_image ' ]);
422422 $ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['thumbnail ' ]);
@@ -428,7 +428,7 @@ public function testDeleteWithMultiWebsites(): void
428428 $ product ->addData (array_fill_keys ($ imageRoles , $ image ));
429429 $ this ->productRepository ->save ($ product );
430430 // Assert that roles are assigned to product image for second store
431- $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product );
431+ $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product, $ imageRoles );
432432 $ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['image ' ]);
433433 $ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['small_image ' ]);
434434 $ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['thumbnail ' ]);
@@ -454,7 +454,7 @@ public function testDeleteWithMultiWebsites(): void
454454 $ this ->assertEmpty ($ product ->getMediaGalleryEntries ());
455455 $ this ->assertFileDoesNotExist ($ path );
456456 // Load image roles
457- $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product );
457+ $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product, $ imageRoles );
458458 // Assert that image roles are reset on global scope and removed on second store
459459 // as the product is no longer assigned to second website
460460 $ this ->assertEquals ('no_selection ' , $ imageRolesPerStore [$ globalScopeId ]['image ' ]);
@@ -466,14 +466,17 @@ public function testDeleteWithMultiWebsites(): void
466466
467467 /**
468468 * @param Product $product
469+ * @param array $roles
469470 * @return array
470471 */
471- private function getProductStoreImageRoles (Product $ product ): array
472+ private function getProductStoreImageRoles (Product $ product, array $ roles = [] ): array
472473 {
473474 $ imageRolesPerStore = [];
474475 $ stores = array_keys ($ this ->storeManager ->getStores (true ));
475476 foreach ($ this ->galleryResource ->getProductImages ($ product , $ stores ) as $ role ) {
476- $ imageRolesPerStore [$ role ['store_id ' ]][$ role ['attribute_code ' ]] = $ role ['filepath ' ];
477+ if (empty ($ roles ) || in_array ($ role ['attribute_code ' ], $ roles )) {
478+ $ imageRolesPerStore [$ role ['store_id ' ]][$ role ['attribute_code ' ]] = $ role ['filepath ' ];
479+ }
477480 }
478481 return $ imageRolesPerStore ;
479482 }
0 commit comments