1111use Magento \Framework \ObjectManagerInterface ;
1212use Magento \Store \Model \Store ;
1313use Magento \Store \Model \StoreManagerInterface ;
14+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
15+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
1416use Magento \TestFramework \Helper \Bootstrap ;
1517use Magento \UrlRewrite \Model \UrlFinderInterface ;
1618use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
@@ -37,6 +39,11 @@ class ProductProcessUrlRewriteSavingObserverTest extends TestCase
3739 */
3840 private $ productRepository ;
3941
42+ /**
43+ * @var DataFixtureStorage
44+ */
45+ private $ fixtures ;
46+
4047 /**
4148 * Set up
4249 */
@@ -45,6 +52,7 @@ protected function setUp(): void
4552 $ this ->objectManager = Bootstrap::getObjectManager ();
4653 $ this ->storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
4754 $ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
55+ $ this ->fixtures = $ this ->objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
4856 }
4957
5058 /**
@@ -632,4 +640,46 @@ public function testChangeVisibilityLocalScope()
632640 $ this ->assertContainsEquals ($ row , $ actual );
633641 }
634642 }
643+
644+ /**
645+ * phpcs:disable Generic.Files.LineLength.TooLong
646+ * @magentoDataFixture Magento\Store\Test\Fixture\Website as:website
647+ * @magentoDataFixture Magento\Store\Test\Fixture\Group with:{"website_id":"$website.id$"} as:store_group
648+ * @magentoDataFixture Magento\Store\Test\Fixture\Store with:{"store_group_id":"$store_group.id$"} as:store
649+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"sku":"simple1","website_ids":[1,"$website.id$"]} as:product
650+ * @magentoAppIsolation enabled
651+ */
652+ public function testRemoveProductFromAllWebsites (): void
653+ {
654+ $ testStore1 = $ this ->storeManager ->getStore ('default ' );
655+ $ testStore2 = $ this ->fixtures ->get ('store ' );
656+
657+ $ productFilter = [UrlRewrite::ENTITY_TYPE => 'product ' ];
658+
659+ /** @var Product $product*/
660+ $ product = $ this ->productRepository ->get ('simple1 ' );
661+ $ product ->setWebsiteIds ([])
662+ ->setVisibility (Visibility::VISIBILITY_NOT_VISIBLE );
663+ $ this ->productRepository ->save ($ product );
664+ $ unexpected = [
665+ [
666+ 'request_path ' => 'simple1.html ' ,
667+ 'target_path ' => 'catalog/product/view/id/ ' . $ product ->getId (),
668+ 'is_auto_generated ' => 1 ,
669+ 'redirect_type ' => 0 ,
670+ 'store_id ' => $ testStore1 ->getId (),
671+ ],
672+ [
673+ 'request_path ' => 'simple1.html ' ,
674+ 'target_path ' => 'catalog/product/view/id/ ' . $ product ->getId (),
675+ 'is_auto_generated ' => 1 ,
676+ 'redirect_type ' => 0 ,
677+ 'store_id ' => $ testStore2 ->getId (),
678+ ],
679+ ];
680+ $ actual = $ this ->getActualResults ($ productFilter );
681+ foreach ($ unexpected as $ row ) {
682+ $ this ->assertNotContains ($ row , $ actual );
683+ }
684+ }
635685}
0 commit comments