11
11
use Magento \Framework \ObjectManagerInterface ;
12
12
use Magento \Store \Model \Store ;
13
13
use Magento \Store \Model \StoreManagerInterface ;
14
+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
15
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
14
16
use Magento \TestFramework \Helper \Bootstrap ;
15
17
use Magento \UrlRewrite \Model \UrlFinderInterface ;
16
18
use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
@@ -37,6 +39,11 @@ class ProductProcessUrlRewriteSavingObserverTest extends TestCase
37
39
*/
38
40
private $ productRepository ;
39
41
42
+ /**
43
+ * @var DataFixtureStorage
44
+ */
45
+ private $ fixtures ;
46
+
40
47
/**
41
48
* Set up
42
49
*/
@@ -45,6 +52,7 @@ protected function setUp(): void
45
52
$ this ->objectManager = Bootstrap::getObjectManager ();
46
53
$ this ->storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
47
54
$ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
55
+ $ this ->fixtures = $ this ->objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
48
56
}
49
57
50
58
/**
@@ -632,4 +640,46 @@ public function testChangeVisibilityLocalScope()
632
640
$ this ->assertContainsEquals ($ row , $ actual );
633
641
}
634
642
}
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
+ }
635
685
}
0 commit comments