-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Forward Port PR-14344] Fix generating product URL rewrites for anchor categories #26784
Merged
magento-engcom-team
merged 8 commits into
magento:2.4-develop
from
hostep:forward-port-pr-14344
Mar 17, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cb685d1
Fix generating product URL rewrites for anchor categories
acb8642
Updated unit test and make sure it passes the store id to the get cal…
hostep 97258e1
Changes are covered by the integration test
engcom-Echo 6cf26dc
Merge branch '2.4-develop' of http://github.com/magento/magento2 into…
engcom-Echo 0b94121
Minor change
engcom-Echo b0c0c59
Cover MFTF test
engcom-Echo 28fa345
Minor change
engcom-Echo bf514b0
Refactoring test and add rollback for fixture
engcom-Echo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...og/Test/Mftf/ActionGroup/AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
|
||
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> | ||
<actionGroup name="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" extends="ChangeSeoUrlKeyForSubCategoryActionGroup"> | ||
<annotations> | ||
<description>Requires navigation to subcategory creation/edit. Updates the Search Engine Optimization with uncheck Redirect Checkbox .</description> | ||
</annotations> | ||
<arguments> | ||
<argument name="value" type="string"/> | ||
</arguments> | ||
|
||
<uncheckOption selector="{{AdminCategorySEOSection.UrlKeyRedirectCheckbox}}" stepKey="uncheckRedirectCheckbox" after="enterURLKey"/> | ||
</actionGroup> | ||
</actionGroups> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...Rewrite/Test/Mftf/ActionGroup/AssertStorefrontProductRewriteUrlSubCategoryActionGroup.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> | ||
<actionGroup name="AssertStorefrontProductRewriteUrlSubCategoryActionGroup"> | ||
<annotations> | ||
<description>Validates that the provided Product Title is present on the Rewrite URL with a subcategory page.</description> | ||
</annotations> | ||
<arguments> | ||
<argument name="category" type="string" defaultValue="simplecategory"/> | ||
<argument name="product" defaultValue="SimpleProduct" /> | ||
</arguments> | ||
|
||
<amOnPage url="{{category}}/{{product.urlKey}}2.html" stepKey="goToProductPage"/> | ||
<see selector="{{StorefrontProductInfoMainSection.productName}}" userInput="{{product.name}}" stepKey="seeProductNameInStoreFront"/> | ||
</actionGroup> | ||
</actionGroups> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> | ||
<test name="AdminRewriteProductWithTwoStoreTest"> | ||
<annotations> | ||
<title value="Rewriting URL of product"/> | ||
<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="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> | ||
|
||
<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="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="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" 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="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="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryCustomStore"> | ||
<argument name="value" value="{{SimpleSubCategoryDifferentUrlStore.url_key_custom_store}}"/> | ||
</actionGroup> | ||
<actionGroup ref="AssertStorefrontProductRewriteUrlSubCategoryActionGroup" 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="AssertStorefrontProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlCustomStore"> | ||
<argument name="category" value="{{_defaultCategoryDifferentUrlStore.url_key_custom_store}}"/> | ||
<argument name="product" value="SimpleProduct" /> | ||
</actionGroup> | ||
|
||
</test> | ||
</tests> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...ation/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogUrlRewrite\Model\Product; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\CatalogUrlRewrite\Model\ObjectRegistryFactory; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Store\Model\Store; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Verify generate url rewrites for anchor categories. | ||
*/ | ||
class AnchorUrlRewriteGeneratorTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var ProductRepositoryInterface | ||
*/ | ||
private $productRepository; | ||
|
||
/** | ||
* @var ObjectRegistryFactory | ||
*/ | ||
private $objectRegistryFactory; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); // TODO: Change the autogenerated stub | ||
|
||
$this->objectManager = Bootstrap::getObjectManager(); | ||
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::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 | ||
* @dataProvider getConfigGenerate | ||
*/ | ||
public function testGenerate(string $expect): void | ||
{ | ||
$product = $this->productRepository->get('simple'); | ||
$categories = $product->getCategoryCollection(); | ||
$productCategories = $this->objectRegistryFactory->create(['entities' => $categories]); | ||
|
||
/** @var AnchorUrlRewriteGenerator $generator */ | ||
$generator = $this->objectManager->get(AnchorUrlRewriteGenerator::class); | ||
|
||
/** @var $store Store */ | ||
$store = Bootstrap::getObjectManager()->get(Store::class); | ||
$store->load('fixture_second_store', 'code'); | ||
|
||
$urls = $generator->generate($store->getId(), $product, $productCategories); | ||
|
||
$this->assertEquals($expect, $urls[0]->getRequestPath()); | ||
} | ||
|
||
/** | ||
* Data provider for testGenerate | ||
* | ||
* @return array | ||
*/ | ||
public function getConfigGenerate(): array | ||
{ | ||
return [ | ||
[ | ||
'expect' => 'category-1-custom/simple-product.html' | ||
] | ||
]; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what input should the result change?
I see expectation attribute, but there's not context attribute.