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
16
20
/**
17
21
* @magentoAppArea adminhtml
18
22
* @magentoDbIsolation disabled
23
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19
24
*/
20
25
class ProcessUrlRewriteOnChangeVisibilityObserverTest extends \PHPUnit \Framework \TestCase
21
26
{
@@ -34,6 +39,11 @@ class ProcessUrlRewriteOnChangeVisibilityObserverTest extends \PHPUnit\Framework
34
39
*/
35
40
private $ eventManager ;
36
41
42
+ /**
43
+ * @var DataFixtureStorage
44
+ */
45
+ private $ fixtures ;
46
+
37
47
/**
38
48
* Set up
39
49
*/
@@ -42,6 +52,8 @@ protected function setUp(): void
42
52
$ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
43
53
$ this ->productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
44
54
$ this ->eventManager = $ this ->objectManager ->create (ManagerInterface::class);
55
+
56
+ $ this ->fixtures = Bootstrap::getObjectManager ()->get (DataFixtureStorageManager::class)->getStorage ();
45
57
}
46
58
47
59
/**
@@ -148,6 +160,78 @@ public function testMakeProductVisibleViaMassAction()
148
160
}
149
161
}
150
162
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
+
151
235
/**
152
236
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/products_invisible.php
153
237
* @magentoAppIsolation enabled
0 commit comments