99use Magento \Catalog \Api \ProductRepositoryInterface ;
1010use Magento \Catalog \Model \Product \Visibility ;
1111use Magento \Framework \Event \ManagerInterface ;
12+ use Magento \Store \Model \Store ;
1213use Magento \Store \Model \StoreManagerInterface ;
14+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
15+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
16+ use Magento \TestFramework \Helper \Bootstrap ;
1317use Magento \UrlRewrite \Model \Exception \UrlAlreadyExistsException ;
1418use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
1519
1620/**
1721 * @magentoAppArea adminhtml
1822 * @magentoDbIsolation disabled
23+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1924 */
2025class ProcessUrlRewriteOnChangeVisibilityObserverTest extends \PHPUnit \Framework \TestCase
2126{
@@ -34,6 +39,11 @@ class ProcessUrlRewriteOnChangeVisibilityObserverTest extends \PHPUnit\Framework
3439 */
3540 private $ eventManager ;
3641
42+ /**
43+ * @var DataFixtureStorage
44+ */
45+ private $ fixtures ;
46+
3747 /**
3848 * Set up
3949 */
@@ -42,6 +52,8 @@ protected function setUp(): void
4252 $ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
4353 $ this ->productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
4454 $ this ->eventManager = $ this ->objectManager ->create (ManagerInterface::class);
55+
56+ $ this ->fixtures = Bootstrap::getObjectManager ()->get (DataFixtureStorageManager::class)->getStorage ();
4557 }
4658
4759 /**
@@ -148,6 +160,78 @@ public function testMakeProductVisibleViaMassAction()
148160 }
149161 }
150162
163+ /**
164+ * Test for multistore properties of the product to be respected in generated UrlRewrites
165+ * during the mass update for visibility change
166+ *
167+ * phpcs:disable Generic.Files.LineLength.TooLong
168+ * @magentoDataFixture Magento\Store\Test\Fixture\Website as:w1
169+ * @magentoDataFixture Magento\Store\Test\Fixture\Store as:s1
170+ * @magentoDataFixture Magento\Store\Test\Fixture\Group as:g1 with:{"website_id": "$w1.id$", "default_store_id": "$s1.id$"}
171+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category as:c1
172+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"category_ids":["$c1.id$"], "visibility": "1", "extension_attributes": {"website_ids": [1, "$w1.id$"]}} as:p1
173+ * @magentoAppIsolation enabled
174+ * phpcs:enable Generic.Files.LineLength.TooLong
175+ */
176+ public function testMassActionUrlRewriteForStore ()
177+ {
178+ $ product = $ this ->fixtures ->get ('p1 ' );
179+ $ category = $ this ->fixtures ->get ('c1 ' );
180+ $ store = $ this ->fixtures ->get ('s1 ' );
181+
182+ $ productFilter = [
183+ UrlRewrite::ENTITY_TYPE => 'product ' ,
184+ ];
185+
186+ $ beforeUpdate = $ this ->getActualResults ($ productFilter );
187+ $ this ->assertCount (0 , $ beforeUpdate );
188+
189+ $ this ->eventManager ->dispatch (
190+ 'catalog_product_attribute_update_before ' ,
191+ [
192+ 'attributes_data ' => [ ProductInterface::VISIBILITY => Visibility::VISIBILITY_BOTH ],
193+ 'product_ids ' => [$ product ->getId ()],
194+ 'store_id ' => Store::DEFAULT_STORE_ID
195+ ]
196+ );
197+
198+ $ expected = [
199+ [
200+ 'request_path ' => $ product ->getUrlKey () . ".html " ,
201+ 'target_path ' => "catalog/product/view/id/ " . $ product ->getId (),
202+ 'is_auto_generated ' => 1 ,
203+ 'redirect_type ' => 0 ,
204+ 'store_id ' => (String ) Store::DISTRO_STORE_ID
205+ ],
206+ [
207+ 'request_path ' => $ category ->getUrlKey () . '/ ' . $ product ->getUrlKey () . ".html " ,
208+ 'target_path ' => "catalog/product/view/id/ " . $ product ->getId () . '/category/ ' . $ category ->getId (),
209+ 'is_auto_generated ' => 1 ,
210+ 'redirect_type ' => 0 ,
211+ 'store_id ' => (String ) Store::DISTRO_STORE_ID
212+ ],
213+ [
214+ 'request_path ' => $ product ->getUrlKey () . ".html " ,
215+ 'target_path ' => "catalog/product/view/id/ " . $ product ->getId (),
216+ 'is_auto_generated ' => 1 ,
217+ 'redirect_type ' => 0 ,
218+ 'store_id ' => (String ) $ store ->getId ()
219+ ],
220+ [
221+ 'request_path ' => $ category ->getUrlKey () . '/ ' . $ product ->getUrlKey () . ".html " ,
222+ 'target_path ' => "catalog/product/view/id/ " . $ product ->getId () . '/category/ ' . $ category ->getId (),
223+ 'is_auto_generated ' => 1 ,
224+ 'redirect_type ' => 0 ,
225+ 'store_id ' => (String ) $ store ->getId ()
226+ ],
227+ ];
228+
229+ $ actual = $ this ->getActualResults ($ productFilter );
230+ foreach ($ expected as $ row ) {
231+ $ this ->assertContains ($ row , $ actual );
232+ }
233+ }
234+
151235 /**
152236 * @magentoDataFixture Magento/CatalogUrlRewrite/_files/products_invisible.php
153237 * @magentoAppIsolation enabled
0 commit comments