9
9
use Magento \Catalog \Api \ProductRepositoryInterface ;
10
10
use Magento \Catalog \Model \Product \Visibility ;
11
11
use Magento \Framework \Event \ManagerInterface ;
12
+ use Magento \Store \Model \Store ;
12
13
use Magento \Store \Model \StoreManagerInterface ;
14
+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
15
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
16
+ use Magento \TestFramework \Helper \Bootstrap ;
13
17
use Magento \UrlRewrite \Model \Exception \UrlAlreadyExistsException ;
14
18
use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
15
19
@@ -34,6 +38,11 @@ class ProcessUrlRewriteOnChangeVisibilityObserverTest extends \PHPUnit\Framework
34
38
*/
35
39
private $ eventManager ;
36
40
41
+ /**
42
+ * @var DataFixtureStorage
43
+ */
44
+ private $ fixtures ;
45
+
37
46
/**
38
47
* Set up
39
48
*/
@@ -42,6 +51,8 @@ protected function setUp(): void
42
51
$ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
43
52
$ this ->productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
44
53
$ this ->eventManager = $ this ->objectManager ->create (ManagerInterface::class);
54
+
55
+ $ this ->fixtures = Bootstrap::getObjectManager ()->get (DataFixtureStorageManager::class)->getStorage ();
45
56
}
46
57
47
58
/**
@@ -148,6 +159,76 @@ public function testMakeProductVisibleViaMassAction()
148
159
}
149
160
}
150
161
162
+ /**
163
+ * Test for multistore properties of the product to be respected in generated UrlRewrites
164
+ * during the mass update for visibility change
165
+ *
166
+ * @magentoDataFixture Magento\Store\Test\Fixture\Website as:w1
167
+ * @magentoDataFixture Magento\Store\Test\Fixture\Store as:s1
168
+ * @magentoDataFixture Magento\Store\Test\Fixture\Group as:g1 with:{"website_id": "$w1.id$", "default_store_id": "$s1.id$"}
169
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category as:c1
170
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"category_ids":["$c1.id$"], "visibility": "1", "extension_attributes": {"website_ids": [1, "$w1.id$"]}} as:p1
171
+ * @magentoAppIsolation enabled
172
+ */
173
+ public function testMassActionUrlRewriteForStore ()
174
+ {
175
+ $ product = $ this ->fixtures ->get ('p1 ' );
176
+ $ category = $ this ->fixtures ->get ('c1 ' );
177
+ $ store = $ this ->fixtures ->get ('s1 ' );
178
+
179
+ $ productFilter = [
180
+ UrlRewrite::ENTITY_TYPE => 'product ' ,
181
+ ];
182
+
183
+ $ beforeUpdate = $ this ->getActualResults ($ productFilter );
184
+ $ this ->assertCount (0 , $ beforeUpdate );
185
+
186
+ $ this ->eventManager ->dispatch (
187
+ 'catalog_product_attribute_update_before ' ,
188
+ [
189
+ 'attributes_data ' => [ ProductInterface::VISIBILITY => Visibility::VISIBILITY_BOTH ],
190
+ 'product_ids ' => [$ product ->getId ()],
191
+ 'store_id ' => Store::DEFAULT_STORE_ID
192
+ ]
193
+ );
194
+
195
+ $ expected = [
196
+ [
197
+ 'request_path ' => $ product ->getUrlKey () . ".html " ,
198
+ 'target_path ' => "catalog/product/view/id/ " . $ product ->getId (),
199
+ 'is_auto_generated ' => 1 ,
200
+ 'redirect_type ' => 0 ,
201
+ 'store_id ' => (String ) Store::DISTRO_STORE_ID
202
+ ],
203
+ [
204
+ 'request_path ' => $ category ->getUrlKey () . '/ ' . $ product ->getUrlKey () . ".html " ,
205
+ 'target_path ' => "catalog/product/view/id/ " . $ product ->getId () . '/category/ ' . $ category ->getId (),
206
+ 'is_auto_generated ' => 1 ,
207
+ 'redirect_type ' => 0 ,
208
+ 'store_id ' => (String ) Store::DISTRO_STORE_ID
209
+ ],
210
+ [
211
+ 'request_path ' => $ product ->getUrlKey () . ".html " ,
212
+ 'target_path ' => "catalog/product/view/id/ " . $ product ->getId (),
213
+ 'is_auto_generated ' => 1 ,
214
+ 'redirect_type ' => 0 ,
215
+ 'store_id ' => (String ) $ store ->getId ()
216
+ ],
217
+ [
218
+ 'request_path ' => $ category ->getUrlKey () . '/ ' . $ product ->getUrlKey () . ".html " ,
219
+ 'target_path ' => "catalog/product/view/id/ " . $ product ->getId () . '/category/ ' . $ category ->getId (),
220
+ 'is_auto_generated ' => 1 ,
221
+ 'redirect_type ' => 0 ,
222
+ 'store_id ' => (String ) $ store ->getId ()
223
+ ],
224
+ ];
225
+
226
+ $ actual = $ this ->getActualResults ($ productFilter );
227
+ foreach ($ expected as $ row ) {
228
+ $ this ->assertContains ($ row , $ actual );
229
+ }
230
+ }
231
+
151
232
/**
152
233
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/products_invisible.php
153
234
* @magentoAppIsolation enabled
0 commit comments