Skip to content

Commit 26124b3

Browse files
committed
ACP2E-84: Mass attribute update creates URL rewrite for wrong store
1 parent 78c6815 commit 26124b3

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeVisibilityObserverTest.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
use Magento\Catalog\Api\ProductRepositoryInterface;
1010
use Magento\Catalog\Model\Product\Visibility;
1111
use Magento\Framework\Event\ManagerInterface;
12+
use Magento\Store\Model\Store;
1213
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\TestFramework\Fixture\DataFixtureStorage;
15+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
16+
use Magento\TestFramework\Helper\Bootstrap;
1317
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
1418
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
1519

@@ -34,6 +38,11 @@ class ProcessUrlRewriteOnChangeVisibilityObserverTest extends \PHPUnit\Framework
3438
*/
3539
private $eventManager;
3640

41+
/**
42+
* @var DataFixtureStorage
43+
*/
44+
private $fixtures;
45+
3746
/**
3847
* Set up
3948
*/
@@ -42,6 +51,8 @@ protected function setUp(): void
4251
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
4352
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
4453
$this->eventManager = $this->objectManager->create(ManagerInterface::class);
54+
55+
$this->fixtures = Bootstrap::getObjectManager()->get(DataFixtureStorageManager::class)->getStorage();
4556
}
4657

4758
/**
@@ -148,6 +159,76 @@ public function testMakeProductVisibleViaMassAction()
148159
}
149160
}
150161

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+
151232
/**
152233
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/products_invisible.php
153234
* @magentoAppIsolation enabled

0 commit comments

Comments
 (0)