From cb685d15b2b590bdb4d99a3d4ebe563037d0aa31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maksymilian=20Szyd=C5=82o?= Date: Sat, 24 Mar 2018 17:11:45 +0100 Subject: [PATCH 1/7] Fix generating product URL rewrites for anchor categories (cherry picked from commit 63111ed399b2e058efc0bf1c7c5427299cb8c5fc) --- .../Model/Product/AnchorUrlRewriteGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGenerator.php index 5d08ea33ff8a1..a6589c6062846 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGenerator.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGenerator.php @@ -67,7 +67,7 @@ public function generate($storeId, Product $product, ObjectRegistry $productCate $anchorCategoryIds = $category->getAnchorsAbove(); if ($anchorCategoryIds) { foreach ($anchorCategoryIds as $anchorCategoryId) { - $anchorCategory = $this->categoryRepository->get($anchorCategoryId); + $anchorCategory = $this->categoryRepository->get($anchorCategoryId, $storeId); if ((int)$anchorCategory->getParentId() === Category::TREE_ROOT_ID) { continue; } From acb8642c44d1ecb60ad023c81f6541fa9ebae47d Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Sun, 9 Feb 2020 14:32:08 +0100 Subject: [PATCH 2/7] Updated unit test and make sure it passes the store id to the get call on the category repository. This is not testing for the bugfix but makes sure that when not passing the storeId param in the tested code, the test starts complaining. --- .../Unit/Model/Product/AnchorUrlRewriteGeneratorTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/AnchorUrlRewriteGeneratorTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/AnchorUrlRewriteGeneratorTest.php index 662e156b8f100..8eb46f912d491 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/AnchorUrlRewriteGeneratorTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/AnchorUrlRewriteGeneratorTest.php @@ -100,9 +100,9 @@ public function testGenerateCategories() ->expects($this->any()) ->method('get') ->withConsecutive( - [ 'category_id' => $categoryIds[0]], - [ 'category_id' => $categoryIds[1]], - [ 'category_id' => $categoryIds[2]] + [$categoryIds[0], $storeId], + [$categoryIds[1], $storeId], + [$categoryIds[2], $storeId], ) ->will($this->returnValue($category)); $this->categoryRegistry->expects($this->any())->method('getList') From 97258e1a9ce97ad32971731eceac8fee32f66b74 Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Thu, 13 Feb 2020 16:21:06 +0200 Subject: [PATCH 3/7] Changes are covered by the integration test --- .../Product/AnchorUrlRewriteGeneratorTest.php | 81 +++++++++++++++++++ .../_files/categories_with_stores.php | 81 +++++++++++++++++++ .../_files/product_with_stores.php | 46 +++++++++++ 3 files changed, 208 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php create mode 100644 dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php create mode 100644 dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores.php diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php new file mode 100644 index 0000000000000..a348a3eca2b74 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php @@ -0,0 +1,81 @@ +objectManager = Bootstrap::getObjectManager(); + $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class); + $this->collectionCategory = $this->objectManager->create(Category::class); + $this->objectRegistryFactory = $this->objectManager->create(ObjectRegistryFactory::class); + } + + /** + * Verify correct generate of the relative "StoreId" + * + * @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_with_stores.php + * @magentoDbIsolation disabled + * + * @return void + */ + public function testGenerate(): void + { + $product = $this->productRepository->get('simple'); + $categories = $product->getCategoryCollection(); + $productCategories = $this->objectRegistryFactory->create(['entities' => $categories]); + + /** @var Store $store */ + $store = Bootstrap::getObjectManager()->get(Store::class); + $store->load('fixture_second_store', 'code'); + + /** @var AnchorUrlRewriteGenerator $generator */ + $generator = $this->objectManager->get(AnchorUrlRewriteGenerator::class); + + $this->assertEquals([], $generator->generate(1, $product, $productCategories)); + $this->assertNotEquals([], $generator->generate($store->getId(), $product, $productCategories)); + } +} diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php new file mode 100644 index 0000000000000..7ac0487478d57 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php @@ -0,0 +1,81 @@ +loadArea(FrontNameResolver::AREA_CODE); + +/** + * After installation system has categories: + * + * root one with ID:1 and Default category with ID:3 both with StoreId:1, + * + * root one with ID:1 and Default category with ID:2 both with StoreId:2 + */ + +$store = Bootstrap::getObjectManager()->get(Store::class); +$store->load('fixture_second_store', 'code'); + +/** @var $category Category */ +$category = Bootstrap::getObjectManager()->create(Category::class); +$category->isObjectNew(true); +$category->setId(3) + ->setName('Category 1') + ->setParentId(1) + ->setPath('1/2') + ->setLevel(1) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(1) + ->save(); + +$category = Bootstrap::getObjectManager()->create(Category::class); +$category->isObjectNew(true); +$category->setId(4) + ->setName('Category 1.1') + ->setParentId(3) + ->setPath('1/2/3') + ->setLevel(2) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(1) + ->save(); + +$category = Bootstrap::getObjectManager()->create(Category::class); +$category->isObjectNew(true); +$category->setId(3) + ->setName('Category 1') + ->setParentId(2) + ->setPath('1/2/3') + ->setLevel(2) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setStoreId($store->getId()) + ->setIsActive(true) + ->setPosition(1) + ->save(); + +$category = Bootstrap::getObjectManager()->create(Category::class); +$category->isObjectNew(true); +$category->setId(4) + ->setName('Category 1.1') + ->setParentId(3) + ->setPath('1/2/3/4') + ->setLevel(3) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setStoreId($store->getId()) + ->setIsActive(true) + ->setPosition(1) + ->save(); diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores.php new file mode 100644 index 0000000000000..bcc7c9ed313d3 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores.php @@ -0,0 +1,46 @@ +create( + \Magento\Catalog\Setup\CategorySetup::class +); +require __DIR__ . '/categories_with_stores.php'; + +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); +$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); +$categoryLinkRepository = $objectManager->create( + \Magento\Catalog\Api\CategoryLinkRepositoryInterface::class, + [ + 'productRepository' => $productRepository + ] +); + +/** @var Magento\Catalog\Api\CategoryLinkManagementInterface $linkManagement */ +$categoryLinkManagement = $objectManager->create( + \Magento\Catalog\Api\CategoryLinkManagementInterface::class, + [ + 'productRepository' => $productRepository, + 'categoryLinkRepository' => $categoryLinkRepository + ] +); + +/** @var $product \Magento\Catalog\Model\Product */ +$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class); +$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) + ->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default')) + ->setStoreId(1) + ->setWebsiteIds([1]) + ->setName('Simple Product') + ->setSku('simple') + ->setPrice(10) + ->setWeight(18) + ->setStockData(['use_config_manage_stock' => 0]) + ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH) + ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) + ->save(); +$categoryLinkManagement->assignProductToCategories($product->getSku(), [4]); From 0b941218dcc86dcbd518f5400934e995ad1f2e3c Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Fri, 14 Feb 2020 10:20:18 +0200 Subject: [PATCH 4/7] Minor change --- .../Product/AnchorUrlRewriteGeneratorTest.php | 60 +++++++++++++------ .../Product/AnchorUrlRewriteGeneratorTest.php | 2 +- .../_files/categories_with_stores.php | 3 +- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/AnchorUrlRewriteGeneratorTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/AnchorUrlRewriteGeneratorTest.php index 8eb46f912d491..d8fec2de0e46e 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/AnchorUrlRewriteGeneratorTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/AnchorUrlRewriteGeneratorTest.php @@ -3,53 +3,67 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Product; +use Magento\Catalog\Api\CategoryRepositoryInterface; +use Magento\Catalog\Model\Product; +use Magento\CatalogUrlRewrite\Model\ObjectRegistry; +use Magento\CatalogUrlRewrite\Model\Product\AnchorUrlRewriteGenerator; +use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator; use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; +use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory; +use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject as MockObject; -class AnchorUrlRewriteGeneratorTest extends \PHPUnit\Framework\TestCase +class AnchorUrlRewriteGeneratorTest extends TestCase { - /** @var \Magento\CatalogUrlRewrite\Model\Product\AnchorUrlRewriteGenerator */ + /** @var AnchorUrlRewriteGenerator */ protected $anchorUrlRewriteGenerator; - /** @var \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator|\PHPUnit_Framework_MockObject_MockObject */ + /** @var ProductUrlPathGenerator|MockObject */ protected $productUrlPathGenerator; - /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject */ + /** @var Product|MockObject */ protected $product; - /** @var \Magento\Catalog\Api\CategoryRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** @var CategoryRepositoryInterface|MockObject */ private $categoryRepositoryInterface; - /** @var \Magento\CatalogUrlRewrite\Model\ObjectRegistry|\PHPUnit_Framework_MockObject_MockObject */ + /** @var ObjectRegistry|MockObject */ protected $categoryRegistry; - /** @var \Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory|\PHPUnit_Framework_MockObject_MockObject */ + /** @var UrlRewriteFactory|MockObject */ protected $urlRewriteFactory; - /** @var \Magento\UrlRewrite\Service\V1\Data\UrlRewrite|\PHPUnit_Framework_MockObject_MockObject */ + /** @var UrlRewrite|MockObject */ protected $urlRewrite; + /** + * @inheritDoc + */ protected function setUp() { - $this->urlRewriteFactory = $this->getMockBuilder(\Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory::class) + $this->urlRewriteFactory = $this->getMockBuilder(UrlRewriteFactory::class) ->setMethods(['create']) ->disableOriginalConstructor()->getMock(); - $this->urlRewrite = $this->getMockBuilder(\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class) + $this->urlRewrite = $this->getMockBuilder(UrlRewrite::class) ->disableOriginalConstructor()->getMock(); - $this->product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + $this->product = $this->getMockBuilder(Product::class) ->disableOriginalConstructor()->getMock(); $this->categoryRepositoryInterface = $this->getMockBuilder( - \Magento\Catalog\Api\CategoryRepositoryInterface::class + CategoryRepositoryInterface::class )->disableOriginalConstructor()->getMock(); - $this->categoryRegistry = $this->getMockBuilder(\Magento\CatalogUrlRewrite\Model\ObjectRegistry::class) + $this->categoryRegistry = $this->getMockBuilder(ObjectRegistry::class) ->disableOriginalConstructor()->getMock(); $this->productUrlPathGenerator = $this->getMockBuilder( - \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator::class + ProductUrlPathGenerator::class )->disableOriginalConstructor()->getMock(); $this->anchorUrlRewriteGenerator = (new ObjectManager($this))->getObject( - \Magento\CatalogUrlRewrite\Model\Product\AnchorUrlRewriteGenerator::class, + AnchorUrlRewriteGenerator::class, [ 'productUrlPathGenerator' => $this->productUrlPathGenerator, 'urlRewriteFactory' => $this->urlRewriteFactory, @@ -58,7 +72,12 @@ protected function setUp() ); } - public function testGenerateEmpty() + /** + * Verify generate if category registry list is empty. + * + * @return void + */ + public function testGenerateEmpty(): void { $this->categoryRegistry->expects($this->any())->method('getList')->will($this->returnValue([])); @@ -68,7 +87,12 @@ public function testGenerateEmpty() ); } - public function testGenerateCategories() + /** + * Verify generate product rewrites for anchor categories. + * + * @return void + */ + public function testGenerateCategories(): void { $urlPathWithCategory = 'category1/category2/category3/simple-product.html'; $storeId = 10; @@ -102,7 +126,7 @@ public function testGenerateCategories() ->withConsecutive( [$categoryIds[0], $storeId], [$categoryIds[1], $storeId], - [$categoryIds[2], $storeId], + [$categoryIds[2], $storeId] ) ->will($this->returnValue($category)); $this->categoryRegistry->expects($this->any())->method('getList') diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php index a348a3eca2b74..32eee8dd78250 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php @@ -15,7 +15,7 @@ use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; -/**3 +/** * Verify generate url rewrites for anchor categories. */ class AnchorUrlRewriteGeneratorTest extends TestCase diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php index 7ac0487478d57..6794316b4bb93 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php @@ -11,8 +11,7 @@ use Magento\TestFramework\Helper\Bootstrap; require __DIR__ . '/../../../Magento/Store/_files/second_store.php'; -Bootstrap::getInstance() - ->loadArea(FrontNameResolver::AREA_CODE); +Bootstrap::getInstance()->loadArea(FrontNameResolver::AREA_CODE); /** * After installation system has categories: From b0c0c59900b4ddf8d70cf2ae9c9ec12805d13908 Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Mon, 17 Feb 2020 13:48:51 +0200 Subject: [PATCH 5/7] Cover MFTF test --- ...rSubCategoryWithoutRedirectActionGroup.xml | 21 +++++ .../Catalog/Test/Mftf/Data/CategoryData.xml | 16 ++++ ...roductRewriteUrlSubCategoryActionGroup.xml | 22 +++++ ...ateCategoryProductUrlRewriteConfigData.xml | 8 ++ .../AdminRewriteProductWithTwoStoreTest.xml | 80 +++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml create mode 100644 app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml create mode 100644 app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml new file mode 100644 index 0000000000000..4f0b87937baa9 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml @@ -0,0 +1,21 @@ + + + + + + + Requires navigation to subcategory creation/edit. Updates the Search Engine Optimization with uncheck Redirect Checkbox . + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Data/CategoryData.xml b/app/code/Magento/Catalog/Test/Mftf/Data/CategoryData.xml index 6ffb4e1902424..e766a233c401c 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Data/CategoryData.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Data/CategoryData.xml @@ -110,6 +110,22 @@ false false + + SimpleCategory + simplecategory + true + default-simplecategory + custom-simplecategory + + + SimpleSubCategory + simplesubcategory + true + default-simplesubcategory + custom-simplesubcategory + true + + Gear diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml new file mode 100644 index 0000000000000..8c0519d08545c --- /dev/null +++ b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml @@ -0,0 +1,22 @@ + + + + + + Validates that the provided Product Title is present on the Rewrite URL with a subcategory page. + + + + + + + + + + + diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Data/GenerateCategoryProductUrlRewriteConfigData.xml b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Data/GenerateCategoryProductUrlRewriteConfigData.xml index 10d2213b64717..9ce6d397a551b 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Data/GenerateCategoryProductUrlRewriteConfigData.xml +++ b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Data/GenerateCategoryProductUrlRewriteConfigData.xml @@ -19,4 +19,12 @@ No 0 + + catalog/seo/product_use_categories + 1 + + + catalog/seo/product_use_categories + 0 + diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml new file mode 100644 index 0000000000000..2f421276b1889 --- /dev/null +++ b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml @@ -0,0 +1,80 @@ + + + + + + + <description value="Rewriting URL of product. Verify the full URL address"/> + <group value="CatalogUrlRewrite"/> + </annotations> + + <before> + <magentoCLI command="config:set {{EnableCategoriesPathProductUrls.path}} {{EnableCategoriesPathProductUrls.value}}" stepKey="enableUseCategoriesPath"/> + <magentoCLI command="cache:flush" stepKey="flushCache"/> + + <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/> + <actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createStoreView" /> + <createData entity="_defaultCategoryDifferentUrlStore" stepKey="defaultCategory"/> + <createData entity="SimpleSubCategoryDifferentUrlStore" stepKey="subCategory"> + <requiredEntity createDataKey="defaultCategory"/> + </createData> + <createData entity="SimpleProduct" stepKey="simpleProduct"> + <requiredEntity createDataKey="subCategory"/> + </createData> + </before> + + <after> + <actionGroup ref="AdminDeleteStoreViewActionGroup" stepKey="deleteStoreView"/> + <actionGroup ref="logout" stepKey="logout"/> + <deleteData createDataKey="subCategory" stepKey="deleteSubCategory"/> + <deleteData createDataKey="defaultCategory" stepKey="deleteNewRootCategory"/> + + <magentoCLI command="config:set {{DisableCategoriesPathProductUrls.path}} {{DisableCategoriesPathProductUrls.value}}" stepKey="disableUseCategoriesPath"/> + <magentoCLI command="cache:flush" stepKey="flushCache"/> + </after> + + <actionGroup ref="NavigateToCreatedCategoryActionGroup" stepKey="navigateToCreatedDefaultCategory"> + <argument name="Category" value="$$defaultCategory$$"/> + </actionGroup> + <actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchDefaultStoreViewForDefaultCategory"> + <argument name="storeView" value="_defaultStore.name"/> + </actionGroup> + <actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForDefaultCategoryDefaultStore"> + <argument name="value" value="{{_defaultCategoryDifferentUrlStore.url_key_default_store}}"/> + </actionGroup> + <actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchCustomStoreViewForDefaultCategory"> + <argument name="storeView" value="customStore.name"/> + </actionGroup> + <actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForDefaultCategoryCustomStore"> + <argument name="value" value="{{_defaultCategoryDifferentUrlStore.url_key_custom_store}}"/> + </actionGroup> + + <actionGroup ref="NavigateToCreatedCategoryActionGroup" stepKey="navigateToCreatedSubCategory"> + <argument name="Category" value="$$subCategory$$"/> + </actionGroup> + <actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchDefaultStoreViewForSubCategory"> + <argument name="storeView" value="_defaultStore.name"/> + </actionGroup> + <actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryDefaultStore"> + <argument name="value" value="{{SimpleSubCategoryDifferentUrlStore.url_key_default_store}}"/> + </actionGroup> + <actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchCustomStoreViewForSubCategory"> + <argument name="storeView" value="customStore.name"/> + </actionGroup> + <actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryCustomStore"> + <argument name="value" value="{{SimpleSubCategoryDifferentUrlStore.url_key_custom_store}}"/> + </actionGroup> + + <actionGroup ref="StorefrontAssertProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrl"> + <argument name="category" value="_defaultCategoryDifferentUrlStore"/> + <argument name="subCategory" value="SimpleSubCategoryDifferentUrlStore" /> + <argument name="product" value="SimpleProduct" /> + </actionGroup> + + </test> +</tests> From 28fa34531f4c7cd4bcad46500ba027b9b58ff297 Mon Sep 17 00:00:00 2001 From: engcom-Echo <engcom-vendorworker-echo@adobe.com> Date: Mon, 17 Feb 2020 17:11:51 +0200 Subject: [PATCH 6/7] Minor change --- ...tProductRewriteUrlSubCategoryActionGroup.xml | 5 ++--- .../AdminRewriteProductWithTwoStoreTest.xml | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml index 8c0519d08545c..4e72c7f704866 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml +++ b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml @@ -11,12 +11,11 @@ <description>Validates that the provided Product Title is present on the Rewrite URL with a subcategory page.</description> </annotations> <arguments> - <argument name="category" defaultValue="_defaultCategory"/> - <argument name="subCategory" defaultValue="SimpleSubCategory"/> + <argument name="category" type="string" defaultValue="simplecategory"/> <argument name="product" defaultValue="SimpleProduct" /> </arguments> - <amOnPage url="{{category.url_key_default_store}}/{{subCategory.url_key_default_store}}/{{product.urlKey}}2.html" stepKey="goToProductPage"/> + <amOnPage url="{{category}}/{{product.urlKey}}2.html" stepKey="goToProductPage"/> <see selector="{{StorefrontProductInfoMainSection.productName}}" userInput="{{product.name}}" stepKey="seeProductNameInStoreFront"/> </actionGroup> </actionGroups> diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml index 2f421276b1889..ac9b3f573deba 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml +++ b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml @@ -31,9 +31,8 @@ <after> <actionGroup ref="AdminDeleteStoreViewActionGroup" stepKey="deleteStoreView"/> <actionGroup ref="logout" stepKey="logout"/> - <deleteData createDataKey="subCategory" stepKey="deleteSubCategory"/> + <deleteData createDataKey="simpleProduct" stepKey="deleteSimpleProduct"/> <deleteData createDataKey="defaultCategory" stepKey="deleteNewRootCategory"/> - <magentoCLI command="config:set {{DisableCategoriesPathProductUrls.path}} {{DisableCategoriesPathProductUrls.value}}" stepKey="disableUseCategoriesPath"/> <magentoCLI command="cache:flush" stepKey="flushCache"/> </after> @@ -70,9 +69,17 @@ <argument name="value" value="{{SimpleSubCategoryDifferentUrlStore.url_key_custom_store}}"/> </actionGroup> - <actionGroup ref="StorefrontAssertProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrl"> - <argument name="category" value="_defaultCategoryDifferentUrlStore"/> - <argument name="subCategory" value="SimpleSubCategoryDifferentUrlStore" /> + <actionGroup ref="StorefrontAssertProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlDefaultStore"> + <argument name="category" value="{{_defaultCategoryDifferentUrlStore.url_key_default_store}}"/> + <argument name="product" value="SimpleProduct" /> + </actionGroup> + + <actionGroup ref="StorefrontSwitchStoreViewActionGroup" stepKey="switchStore"> + <argument name="storeView" value="customStore" /> + </actionGroup> + + <actionGroup ref="StorefrontAssertProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlCustomStore"> + <argument name="category" value="{{_defaultCategoryDifferentUrlStore.url_key_custom_store}}"/> <argument name="product" value="SimpleProduct" /> </actionGroup> From bf514b0b435a75f5688f56f8e9465af9bb3284c1 Mon Sep 17 00:00:00 2001 From: engcom-Echo <engcom-vendorworker-echo@adobe.com> Date: Tue, 18 Feb 2020 13:20:32 +0200 Subject: [PATCH 7/7] Refactoring test and add rollback for fixture --- ...SubCategoryWithoutRedirectActionGroup.xml} | 2 +- ...oductRewriteUrlSubCategoryActionGroup.xml} | 2 +- .../AdminRewriteProductWithTwoStoreTest.xml | 15 ++++--- .../Product/AnchorUrlRewriteGeneratorTest.php | 41 ++++++++++++------- .../_files/categories_with_stores.php | 26 ++++++------ .../categories_with_stores_rollback.php | 23 +++++++++++ .../_files/product_with_stores.php | 3 +- .../_files/product_with_stores_rollback.php | 29 +++++++++++++ 8 files changed, 101 insertions(+), 40 deletions(-) rename app/code/Magento/Catalog/Test/Mftf/ActionGroup/{ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml => AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml} (85%) rename app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/{StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml => AssertStorefrontProductRewriteUrlSubCategoryActionGroup.xml} (93%) create mode 100644 dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores_rollback.php diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml similarity index 85% rename from app/code/Magento/Catalog/Test/Mftf/ActionGroup/ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml rename to app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml index 4f0b87937baa9..fc010cec4cb65 100644 --- a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml @@ -8,7 +8,7 @@ <actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> - <actionGroup name="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" extends="ChangeSeoUrlKeyForSubCategoryActionGroup"> + <actionGroup name="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" extends="ChangeSeoUrlKeyForSubCategoryActionGroup"> <annotations> <description>Requires navigation to subcategory creation/edit. Updates the Search Engine Optimization with uncheck Redirect Checkbox .</description> </annotations> diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/AssertStorefrontProductRewriteUrlSubCategoryActionGroup.xml similarity index 93% rename from app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml rename to app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/AssertStorefrontProductRewriteUrlSubCategoryActionGroup.xml index 4e72c7f704866..4675d3b2669a4 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/StorefrontAssertProductRewriteUrlSubCategoryActionGroup.xml +++ b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/ActionGroup/AssertStorefrontProductRewriteUrlSubCategoryActionGroup.xml @@ -6,7 +6,7 @@ */ --> <actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> - <actionGroup name="StorefrontAssertProductRewriteUrlSubCategoryActionGroup"> + <actionGroup name="AssertStorefrontProductRewriteUrlSubCategoryActionGroup"> <annotations> <description>Validates that the provided Product Title is present on the Rewrite URL with a subcategory page.</description> </annotations> diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml index ac9b3f573deba..db4811273a5cc 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml +++ b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml @@ -43,13 +43,13 @@ <actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchDefaultStoreViewForDefaultCategory"> <argument name="storeView" value="_defaultStore.name"/> </actionGroup> - <actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForDefaultCategoryDefaultStore"> + <actionGroup ref="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForDefaultCategoryDefaultStore"> <argument name="value" value="{{_defaultCategoryDifferentUrlStore.url_key_default_store}}"/> </actionGroup> <actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchCustomStoreViewForDefaultCategory"> <argument name="storeView" value="customStore.name"/> </actionGroup> - <actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForDefaultCategoryCustomStore"> + <actionGroup ref="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForDefaultCategoryCustomStore"> <argument name="value" value="{{_defaultCategoryDifferentUrlStore.url_key_custom_store}}"/> </actionGroup> @@ -59,17 +59,17 @@ <actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchDefaultStoreViewForSubCategory"> <argument name="storeView" value="_defaultStore.name"/> </actionGroup> - <actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryDefaultStore"> + <actionGroup ref="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryDefaultStore"> <argument name="value" value="{{SimpleSubCategoryDifferentUrlStore.url_key_default_store}}"/> </actionGroup> <actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchCustomStoreViewForSubCategory"> <argument name="storeView" value="customStore.name"/> </actionGroup> - <actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryCustomStore"> + + <actionGroup ref="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryCustomStore"> <argument name="value" value="{{SimpleSubCategoryDifferentUrlStore.url_key_custom_store}}"/> </actionGroup> - - <actionGroup ref="StorefrontAssertProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlDefaultStore"> + <actionGroup ref="AssertStorefrontProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlDefaultStore"> <argument name="category" value="{{_defaultCategoryDifferentUrlStore.url_key_default_store}}"/> <argument name="product" value="SimpleProduct" /> </actionGroup> @@ -77,8 +77,7 @@ <actionGroup ref="StorefrontSwitchStoreViewActionGroup" stepKey="switchStore"> <argument name="storeView" value="customStore" /> </actionGroup> - - <actionGroup ref="StorefrontAssertProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlCustomStore"> + <actionGroup ref="AssertStorefrontProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlCustomStore"> <argument name="category" value="{{_defaultCategoryDifferentUrlStore.url_key_custom_store}}"/> <argument name="product" value="SimpleProduct" /> </actionGroup> diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php index 32eee8dd78250..446b423e17187 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php @@ -8,7 +8,6 @@ namespace Magento\CatalogUrlRewrite\Model\Product; use Magento\Catalog\Api\ProductRepositoryInterface; -use Magento\Catalog\Model\Category; use Magento\CatalogUrlRewrite\Model\ObjectRegistryFactory; use Magento\Framework\ObjectManagerInterface; use Magento\Store\Model\Store; @@ -31,11 +30,6 @@ class AnchorUrlRewriteGeneratorTest extends TestCase */ private $productRepository; - /** - * @var Category - */ - private $collectionCategory; - /** * @var ObjectRegistryFactory */ @@ -50,32 +44,49 @@ public function setUp() $this->objectManager = Bootstrap::getObjectManager(); $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class); - $this->collectionCategory = $this->objectManager->create(Category::class); $this->objectRegistryFactory = $this->objectManager->create(ObjectRegistryFactory::class); } /** * Verify correct generate of the relative "StoreId" * + * @param string $expect + * @return void + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\Framework\Exception\NoSuchEntityException * @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_with_stores.php * @magentoDbIsolation disabled - * - * @return void + * @dataProvider getConfigGenerate */ - public function testGenerate(): void + public function testGenerate(string $expect): void { $product = $this->productRepository->get('simple'); $categories = $product->getCategoryCollection(); $productCategories = $this->objectRegistryFactory->create(['entities' => $categories]); - /** @var Store $store */ + /** @var AnchorUrlRewriteGenerator $generator */ + $generator = $this->objectManager->get(AnchorUrlRewriteGenerator::class); + + /** @var $store Store */ $store = Bootstrap::getObjectManager()->get(Store::class); $store->load('fixture_second_store', 'code'); - /** @var AnchorUrlRewriteGenerator $generator */ - $generator = $this->objectManager->get(AnchorUrlRewriteGenerator::class); + $urls = $generator->generate($store->getId(), $product, $productCategories); + + $this->assertEquals($expect, $urls[0]->getRequestPath()); + } - $this->assertEquals([], $generator->generate(1, $product, $productCategories)); - $this->assertNotEquals([], $generator->generate($store->getId(), $product, $productCategories)); + /** + * Data provider for testGenerate + * + * @return array + */ + public function getConfigGenerate(): array + { + return [ + [ + 'expect' => 'category-1-custom/simple-product.html' + ] + ]; } } diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php index 6794316b4bb93..5fc9d75598da6 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php @@ -13,14 +13,6 @@ require __DIR__ . '/../../../Magento/Store/_files/second_store.php'; Bootstrap::getInstance()->loadArea(FrontNameResolver::AREA_CODE); -/** - * After installation system has categories: - * - * root one with ID:1 and Default category with ID:3 both with StoreId:1, - * - * root one with ID:1 and Default category with ID:2 both with StoreId:2 - */ - $store = Bootstrap::getObjectManager()->get(Store::class); $store->load('fixture_second_store', 'code'); @@ -29,11 +21,13 @@ $category->isObjectNew(true); $category->setId(3) ->setName('Category 1') - ->setParentId(1) - ->setPath('1/2') - ->setLevel(1) + ->setParentId(2) + ->setPath('1/2/3') + ->setLevel(2) ->setAvailableSortBy('name') ->setDefaultSortBy('name') + ->setUrlPath('category-1-default') + ->setUrlKey('category-1-default') ->setIsActive(true) ->setPosition(1) ->save(); @@ -43,10 +37,12 @@ $category->setId(4) ->setName('Category 1.1') ->setParentId(3) - ->setPath('1/2/3') - ->setLevel(2) + ->setPath('1/2/3/4') + ->setLevel(3) ->setAvailableSortBy('name') ->setDefaultSortBy('name') + ->setUrlPath('category-1-1-default') + ->setUrlKey('category-1-1-default') ->setIsActive(true) ->setPosition(1) ->save(); @@ -61,6 +57,8 @@ ->setAvailableSortBy('name') ->setDefaultSortBy('name') ->setStoreId($store->getId()) + ->setUrlPath('category-1-custom') + ->setUrlKey('category-1-custom') ->setIsActive(true) ->setPosition(1) ->save(); @@ -75,6 +73,8 @@ ->setAvailableSortBy('name') ->setDefaultSortBy('name') ->setStoreId($store->getId()) + ->setUrlPath('category-1-1-custom') + ->setUrlKey('category-1-1-custom') ->setIsActive(true) ->setPosition(1) ->save(); diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores_rollback.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores_rollback.php new file mode 100644 index 0000000000000..a89c80a61ccbc --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores_rollback.php @@ -0,0 +1,23 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +/** @var \Magento\Framework\Registry $registry */ +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); +$registry = $objectManager->get(\Magento\Framework\Registry::class); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */ +$collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Category\Collection::class); +$collection + ->addAttributeToFilter('level', 2) + ->load() + ->delete(); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores.php index bcc7c9ed313d3..84fa9b3044af9 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores.php +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores.php @@ -9,6 +9,7 @@ $installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( \Magento\Catalog\Setup\CategorySetup::class ); + require __DIR__ . '/categories_with_stores.php'; $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); @@ -33,8 +34,6 @@ $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class); $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) ->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default')) - ->setStoreId(1) - ->setWebsiteIds([1]) ->setName('Simple Product') ->setSku('simple') ->setPrice(10) diff --git a/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores_rollback.php b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores_rollback.php new file mode 100644 index 0000000000000..86f0ce34af00c --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores_rollback.php @@ -0,0 +1,29 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Framework\Exception\NoSuchEntityException; + +\Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize(); + +/** @var \Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ +$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); +try { + $product = $productRepository->get('simple', true); + if ($product->getId()) { + $productRepository->delete($product); + } +} catch (NoSuchEntityException $e) { +} +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false);