Skip to content

Commit 868e50e

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-69825' into EPAM-PR-81
2 parents 419fbf3 + 277a23a commit 868e50e

File tree

8 files changed

+266
-11
lines changed

8 files changed

+266
-11
lines changed

app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminCategoryActionGroup.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@
191191
<click selector="{{AdminCategorySidebarTreeSection.expandAll}}" stepKey="expandToSeeAllCategories"/>
192192
<dontSee selector="{{AdminCategorySidebarTreeSection.categoryInTree(categoryEntity.name)}}" stepKey="dontSeeCategoryInTree"/>
193193
</actionGroup>
194+
<actionGroup name="AdminDeleteCategoryByName" extends="DeleteCategory">
195+
<arguments>
196+
<argument name="categoryName" type="string" defaultValue="category1"/>
197+
</arguments>
198+
<remove keyForRemoval="clickCategoryLink"/>
199+
<remove keyForRemoval="dontSeeCategoryInTree"/>
200+
<remove keyForRemoval="expandToSeeAllCategories"/>
201+
<conditionalClick selector="{{AdminCategorySidebarTreeSection.expandAll}}" dependentSelector="{{AdminCategorySidebarTreeSection.categoryByName(categoryName)}}" visible="false" stepKey="expandCategories" after="waitForCategoryPageLoad"/>
202+
<click selector="{{AdminCategorySidebarTreeSection.categoryByName(categoryName)}}" stepKey="clickCategory" after="expandCategories"/>
203+
<conditionalClick selector="{{AdminCategorySidebarTreeSection.expandAll}}" dependentSelector="{{AdminCategorySidebarTreeSection.categoryByName(categoryName)}}" visible="false" stepKey="expandCategoriesToSeeAll" after="seeDeleteSuccess"/>
204+
<dontSee selector="{{AdminCategorySidebarTreeSection.categoryByName(categoryName)}}" stepKey="dontSeeCategory" after="expandCategoriesToSeeAll"/>
205+
</actionGroup>
194206

195207
<!-- Actions to fill out a new category from the product page-->
196208
<!-- The action assumes that you are already on an admin product configuration page -->

app/code/Magento/Catalog/Test/Mftf/Section/AdminCategorySidebarTreeSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
<element name="lastCreatedCategory" type="block" selector=".x-tree-root-ct li li:last-child" />
2020
<element name="treeContainer" type="block" selector=".tree-holder" />
2121
<element name="expandRootCategory" type="text" selector="img.x-tree-elbow-end-plus"/>
22+
<element name="categoryByName" type="text" selector="//div[contains(@class, 'categories-side-col')]//a/span[contains(text(), '{{categoryName}}')]" parameterized="true" timeout="30"/>
2223
</section>
2324
</sections>

app/code/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserver.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\CatalogUrlRewrite\Observer;
79

810
use Magento\Catalog\Model\Category;
@@ -18,6 +20,14 @@
1820
*/
1921
class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
2022
{
23+
24+
/**
25+
* Reserved endpoint names.
26+
*
27+
* @var string[]
28+
*/
29+
private $invalidValues = [];
30+
2131
/**
2232
* @var \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator
2333
*/
@@ -38,22 +48,34 @@ class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
3848
*/
3949
private $categoryRepository;
4050

51+
/**
52+
* @var \Magento\Backend\App\Area\FrontNameResolver
53+
*/
54+
private $frontNameResolver;
55+
4156
/**
4257
* @param CategoryUrlPathGenerator $categoryUrlPathGenerator
4358
* @param ChildrenCategoriesProvider $childrenCategoriesProvider
4459
* @param \Magento\CatalogUrlRewrite\Service\V1\StoreViewService $storeViewService
4560
* @param CategoryRepositoryInterface $categoryRepository
61+
* @param \Magento\Backend\App\Area\FrontNameResolver $frontNameResolver
62+
* @param string[] $invalidValues
4663
*/
4764
public function __construct(
4865
CategoryUrlPathGenerator $categoryUrlPathGenerator,
4966
ChildrenCategoriesProvider $childrenCategoriesProvider,
5067
StoreViewService $storeViewService,
51-
CategoryRepositoryInterface $categoryRepository
68+
CategoryRepositoryInterface $categoryRepository,
69+
\Magento\Backend\App\Area\FrontNameResolver $frontNameResolver = null,
70+
array $invalidValues = []
5271
) {
5372
$this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
5473
$this->childrenCategoriesProvider = $childrenCategoriesProvider;
5574
$this->storeViewService = $storeViewService;
5675
$this->categoryRepository = $categoryRepository;
76+
$this->frontNameResolver = $frontNameResolver ?: \Magento\Framework\App\ObjectManager::getInstance()
77+
->get(\Magento\Backend\App\Area\FrontNameResolver::class);
78+
$this->invalidValues = $invalidValues;
5779
}
5880

5981
/**
@@ -93,6 +115,17 @@ private function updateUrlKey($category, $urlKey)
93115
if (empty($urlKey)) {
94116
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid URL key'));
95117
}
118+
119+
if (in_array($urlKey, $this->getInvalidValues())) {
120+
throw new \Magento\Framework\Exception\LocalizedException(
121+
__(
122+
'URL key "%1" matches a reserved endpoint name (%2). Use another URL key.',
123+
$urlKey,
124+
implode(', ', $this->getInvalidValues())
125+
)
126+
);
127+
}
128+
96129
$category->setUrlKey($urlKey)
97130
->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
98131
if (!$category->isObjectNew()) {
@@ -103,6 +136,16 @@ private function updateUrlKey($category, $urlKey)
103136
}
104137
}
105138

139+
/**
140+
* Get reserved endpoint names.
141+
*
142+
* @return array
143+
*/
144+
private function getInvalidValues()
145+
{
146+
return array_unique(array_merge($this->invalidValues, [$this->frontNameResolver->getFrontName()]));
147+
}
148+
106149
/**
107150
* Update url path for children category.
108151
*
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="AdminCategoryRestrictedUrlErrorMessage">
12+
<data key="urlAdmin">URL key "admin" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.</data>
13+
<data key="urlSoap">URL key "soap" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.</data>
14+
<data key="urlRest">URL key "rest" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.</data>
15+
<data key="urlGraphql">URL key "graphql" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.</data>
16+
</entity>
17+
</entities>
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminCategoryWithRestrictedUrlKeyNotCreatedTest">
11+
<annotations>
12+
<features value="CatalogUrlRewrite"/>
13+
<stories value="Url rewrites"/>
14+
<title value="Category with restricted Url Key cannot be created"/>
15+
<description value="Category with restricted Url Key cannot be created"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MC-17515"/>
18+
<useCaseId value="MAGETWO-69825"/>
19+
<group value="CatalogUrlRewrite"/>
20+
</annotations>
21+
<before>
22+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
23+
</before>
24+
<after>
25+
<!--Delete created categories-->
26+
<comment userInput="Delete created categories" stepKey="commentDeleteCreatedCategories"/>
27+
<actionGroup ref="AdminDeleteCategoryByName" stepKey="deleteAdminCategory">
28+
<argument name="categoryName" value="admin"/>
29+
</actionGroup>
30+
<actionGroup ref="AdminDeleteCategoryByName" stepKey="deleteSoapCategory">
31+
<argument name="categoryName" value="soap"/>
32+
</actionGroup>
33+
<actionGroup ref="AdminDeleteCategoryByName" stepKey="deleteRestCategory">
34+
<argument name="categoryName" value="rest"/>
35+
</actionGroup>
36+
<actionGroup ref="AdminDeleteCategoryByName" stepKey="deleteGraphQlCategory">
37+
<argument name="categoryName" value="graphql"/>
38+
</actionGroup>
39+
<actionGroup ref="logout" stepKey="logout"/>
40+
</after>
41+
<!--Check category creation with restricted url key 'admin'-->
42+
<comment userInput="Check category creation with restricted url key 'admin'" stepKey="commentCheckAdminCategoryCreation"/>
43+
<actionGroup ref="goToCreateCategoryPage" stepKey="goToCreateAdminCategoryPage"/>
44+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillAdminFirstCategoryForm">
45+
<argument name="categoryName" value="admin"/>
46+
<argument name="categoryUrlKey" value=""/>
47+
</actionGroup>
48+
<see selector="{{AdminMessagesSection.errorMessage}}" userInput='{{AdminCategoryRestrictedUrlErrorMessage.urlAdmin}}' stepKey="seeAdminFirstErrorMessage"/>
49+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillAdminSecondCategoryForm">
50+
<argument name="categoryName" value="{{SimpleSubCategory.name}}"/>
51+
<argument name="categoryUrlKey" value="admin"/>
52+
</actionGroup>
53+
<see selector="{{AdminMessagesSection.errorMessage}}" userInput='{{AdminCategoryRestrictedUrlErrorMessage.urlAdmin}}' stepKey="seeAdminSecondErrorMessage"/>
54+
<!--Create category with 'admin' name-->
55+
<comment userInput="Create category with 'admin' name" stepKey="commentAdminCategoryCreation"/>
56+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillAdminThirdCategoryForm">
57+
<argument name="categoryName" value="admin"/>
58+
<argument name="categoryUrlKey" value="{{SimpleSubCategory.name}}"/>
59+
</actionGroup>
60+
<see selector="{{AdminMessagesSection.successMessage}}" userInput="You saved the category." stepKey="seeAdminSuccessMessage"/>
61+
<seeElement selector="{{AdminCategorySidebarTreeSection.categoryByName('admin')}}" stepKey="seeAdminCategoryInTree"/>
62+
<!--Check category creation with restricted url key 'soap'-->
63+
<comment userInput="Check category creation with restricted url key 'soap'" stepKey="commentCheckSoapCategoryCreation"/>
64+
<actionGroup ref="goToCreateCategoryPage" stepKey="goToCreateSoapCategoryPage"/>
65+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillSoapFirstCategoryForm">
66+
<argument name="categoryName" value="soap"/>
67+
<argument name="categoryUrlKey" value=""/>
68+
</actionGroup>
69+
<see selector="{{AdminMessagesSection.errorMessage}}" userInput='{{AdminCategoryRestrictedUrlErrorMessage.urlSoap}}' stepKey="seeSoapFirstErrorMessage"/>
70+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillSoapSecondCategoryForm">
71+
<argument name="categoryName" value="{{ApiCategory.name}}"/>
72+
<argument name="categoryUrlKey" value="soap"/>
73+
</actionGroup>
74+
<see selector="{{AdminMessagesSection.errorMessage}}" userInput='{{AdminCategoryRestrictedUrlErrorMessage.urlSoap}}' stepKey="seeSoapSecondErrorMessage"/>
75+
<!--Create category with 'soap' name-->
76+
<comment userInput="Create category with 'soap' name" stepKey="commentSoapCategoryCreation"/>
77+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillSoapThirdCategoryForm">
78+
<argument name="categoryName" value="soap"/>
79+
<argument name="categoryUrlKey" value="{{ApiCategory.name}}"/>
80+
</actionGroup>
81+
<see selector="{{AdminMessagesSection.successMessage}}" userInput="You saved the category." stepKey="seeSoapSuccessMessage"/>
82+
<seeElement selector="{{AdminCategorySidebarTreeSection.categoryByName('soap')}}" stepKey="seeSoapCategoryInTree"/>
83+
<!--Check category creation with restricted url key 'rest'-->
84+
<comment userInput="Check category creation with restricted url key 'rest'" stepKey="commentCheckRestCategoryCreation"/>
85+
<actionGroup ref="goToCreateCategoryPage" stepKey="goToCreateRestCategoryPage"/>
86+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillRestFirstCategoryForm">
87+
<argument name="categoryName" value="rest"/>
88+
<argument name="categoryUrlKey" value=""/>
89+
</actionGroup>
90+
<see selector="{{AdminMessagesSection.errorMessage}}" userInput='{{AdminCategoryRestrictedUrlErrorMessage.urlRest}}' stepKey="seeRestFirstErrorMessage"/>
91+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillRestSecondCategoryForm">
92+
<argument name="categoryName" value="{{SubCategoryWithParent.name}}"/>
93+
<argument name="categoryUrlKey" value="rest"/>
94+
</actionGroup>
95+
<see selector="{{AdminMessagesSection.errorMessage}}" userInput='{{AdminCategoryRestrictedUrlErrorMessage.urlRest}}' stepKey="seeRestSecondErrorMessage"/>
96+
<!--Create category with 'rest' name-->
97+
<comment userInput="Create category with 'rest' name" stepKey="commentRestCategoryCreation"/>
98+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillRestThirdCategoryForm">
99+
<argument name="categoryName" value="rest"/>
100+
<argument name="categoryUrlKey" value="{{SubCategoryWithParent.name}}"/>
101+
</actionGroup>
102+
<see selector="{{AdminMessagesSection.successMessage}}" userInput="You saved the category." stepKey="seeRestSuccessMesdgssage"/>
103+
<seeElement selector="{{AdminCategorySidebarTreeSection.categoryByName('rest')}}" stepKey="seeRestCategoryInTree"/>
104+
<!--Check category creation with restricted url key 'graphql'-->
105+
<comment userInput="Check category creation with restricted url key 'graphql'" stepKey="commentCheckGraphQlCategoryCreation"/>
106+
<actionGroup ref="goToCreateCategoryPage" stepKey="goToCreateCategoryPage"/>
107+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillGraphQlFirstCategoryForm">
108+
<argument name="categoryName" value="graphql"/>
109+
<argument name="categoryUrlKey" value=""/>
110+
</actionGroup>
111+
<see selector="{{AdminMessagesSection.errorMessage}}" userInput='{{AdminCategoryRestrictedUrlErrorMessage.urlGraphql}}' stepKey="seeGraphQlFirstErrorMessage"/>
112+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillGraphQlSecondCategoryForm">
113+
<argument name="categoryName" value="{{NewSubCategoryWithParent.name}}"/>
114+
<argument name="categoryUrlKey" value="graphql"/>
115+
</actionGroup>
116+
<see selector="{{AdminMessagesSection.errorMessage}}" userInput='{{AdminCategoryRestrictedUrlErrorMessage.urlGraphql}}' stepKey="seeGraphQlSecondErrorMessage"/>
117+
<!--Create category with 'graphql' name-->
118+
<comment userInput="Create category with 'graphql' name" stepKey="commentGraphQlCategoryCreation"/>
119+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillGraphQlThirdCategoryForm">
120+
<argument name="categoryName" value="graphql"/>
121+
<argument name="categoryUrlKey" value="{{NewSubCategoryWithParent.name}}"/>
122+
</actionGroup>
123+
<see selector="{{AdminMessagesSection.successMessage}}" userInput="You saved the category." stepKey="seeGraphQlSuccessMessage"/>
124+
<seeElement selector="{{AdminCategorySidebarTreeSection.categoryByName('graphql')}}" stepKey="seeGraphQlCategoryInTree"/>
125+
</test>
126+
</tests>

app/code/Magento/CatalogUrlRewrite/etc/di.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,15 @@
4545
</argument>
4646
</arguments>
4747
</type>
48+
<type name="Magento\CatalogUrlRewrite\Observer\CategoryUrlPathAutogeneratorObserver">
49+
<arguments>
50+
<argument name="invalidValues" xsi:type="array">
51+
<item name="0" xsi:type="string">admin</item>
52+
<item name="1" xsi:type="string">soap</item>
53+
<item name="2" xsi:type="string">rest</item>
54+
<item name="3" xsi:type="string">graphql</item>
55+
<item name="4" xsi:type="string">standard</item>
56+
</argument>
57+
</arguments>
58+
</type>
4859
</config>

app/code/Magento/CatalogUrlRewrite/i18n/en_US.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
"Product URL Suffix","Product URL Suffix"
66
"Use Categories Path for Product URLs","Use Categories Path for Product URLs"
77
"Create Permanent Redirect for URLs if URL Key Changed","Create Permanent Redirect for URLs if URL Key Changed"
8-
"Generate "category/product" URL Rewrites","Generate "category/product" URL Rewrites"
8+
"Generate "category/product" URL Rewrites","Generate "category/product" URL Rewrites"
9+
"URL key ""%1"" matches a reserved endpoint name (%2). Use another URL key.","URL key ""%1"" matches a reserved endpoint name (%2). Use another URL key."

0 commit comments

Comments
 (0)