Skip to content

Commit

Permalink
Merge pull request #4869 from magento-epam/EPAM-PR-81
Browse files Browse the repository at this point in the history
[epam] EPAM-PR-81
  • Loading branch information
fascinosum committed Oct 16, 2019
2 parents 128c2ad + 17f05b3 commit 99f206f
Show file tree
Hide file tree
Showing 32 changed files with 805 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@
<click selector="{{AdminCategorySidebarTreeSection.expandAll}}" stepKey="expandToSeeAllCategories"/>
<dontSee selector="{{AdminCategorySidebarTreeSection.categoryInTree(categoryEntity.name)}}" stepKey="dontSeeCategoryInTree"/>
</actionGroup>
<actionGroup name="AdminDeleteCategoryByName" extends="DeleteCategory">
<arguments>
<argument name="categoryName" type="string" defaultValue="category1"/>
</arguments>
<remove keyForRemoval="clickCategoryLink"/>
<remove keyForRemoval="dontSeeCategoryInTree"/>
<remove keyForRemoval="expandToSeeAllCategories"/>
<conditionalClick selector="{{AdminCategorySidebarTreeSection.expandAll}}" dependentSelector="{{AdminCategorySidebarTreeSection.categoryByName(categoryName)}}" visible="false" stepKey="expandCategories" after="waitForCategoryPageLoad"/>
<click selector="{{AdminCategorySidebarTreeSection.categoryByName(categoryName)}}" stepKey="clickCategory" after="expandCategories"/>
<conditionalClick selector="{{AdminCategorySidebarTreeSection.expandAll}}" dependentSelector="{{AdminCategorySidebarTreeSection.categoryByName(categoryName)}}" visible="false" stepKey="expandCategoriesToSeeAll" after="seeDeleteSuccess"/>
<dontSee selector="{{AdminCategorySidebarTreeSection.categoryByName(categoryName)}}" stepKey="dontSeeCategory" after="expandCategoriesToSeeAll"/>
</actionGroup>

<!-- Actions to fill out a new category from the product page-->
<!-- The action assumes that you are already on an admin product configuration page -->
Expand Down
19 changes: 19 additions & 0 deletions app/code/Magento/Catalog/Test/Mftf/Data/CatalogPriceConfigData.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
<entity name="CatalogPriceScopeWebsiteConfigData">
<data key="path">catalog/price/scope</data>
<data key="value">1</data>
</entity>
<entity name="CatalogPriceScopeGlobalConfigData">
<data key="path">catalog/price/scope</data>
<data key="value">0</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<element name="lastCreatedCategory" type="block" selector=".x-tree-root-ct li li:last-child" />
<element name="treeContainer" type="block" selector=".tree-holder" />
<element name="expandRootCategory" type="text" selector="img.x-tree-elbow-end-plus"/>
<element name="categoryByName" type="text" selector="//div[contains(@class, 'categories-side-col')]//a/span[contains(text(), '{{categoryName}}')]" parameterized="true" timeout="30"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminProductFormSection">
<element name="datepickerNewAttribute" type="input" selector="[data-index='{{attrName}}'] input" timeout="30" parameterized="true"/>
<element name="attributeSet" type="select" selector="div[data-index='attribute_set_id'] .admin__field-control"/>
<element name="attributeSetFilter" type="input" selector="div[data-index='attribute_set_id'] .admin__field-control input" timeout="30"/>
<element name="attributeSetFilterResult" type="input" selector="div[data-index='attribute_set_id'] .action-menu-item._last" timeout="30"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Ui\DataProvider\Product\Modifier;

use Magento\Framework\Escaper;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;

/**
* Modify product listing attributes
*/
class Attributes implements ModifierInterface
{
/**
* @var Escaper
*/
private $escaper;

/**
* @var array
*/
private $escapeAttributes;

/**
* @param Escaper $escaper
* @param array $escapeAttributes
*/
public function __construct(
Escaper $escaper,
array $escapeAttributes = []
) {
$this->escaper = $escaper;
$this->escapeAttributes = $escapeAttributes;
}

/**
* @inheritdoc
*/
public function modifyData(array $data)
{
if (!empty($data) && !empty($this->escapeAttributes)) {
foreach ($data['items'] as &$item) {
foreach ($this->escapeAttributes as $escapeAttribute) {
if (isset($item[$escapeAttribute])) {
$item[$escapeAttribute] = $this->escaper->escapeHtml($item[$escapeAttribute]);
}
}
}
}
return $data;
}

/**
* @inheritdoc
*/
public function modifyMeta(array $meta)
{
return $meta;
}
}
19 changes: 18 additions & 1 deletion app/code/Magento/Catalog/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,24 @@
<argument name="pool" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool</argument>
</arguments>
</type>
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Listing\Modifier\Pool" type="Magento\Ui\DataProvider\Modifier\Pool"/>
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Listing\Modifier\Pool" type="Magento\Ui\DataProvider\Modifier\Pool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="attributes" xsi:type="array">
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Modifier\Attributes</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</arguments>
</virtualType>
<type name="Magento\Catalog\Ui\DataProvider\Product\Modifier\Attributes">
<arguments>
<argument name="escapeAttributes" xsi:type="array">
<item name="name" xsi:type="string">name</item>
<item name="sku" xsi:type="string">sku</item>
</argument>
</arguments>
</type>
<type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\CustomOptions">
<arguments>
<argument name="scopeName" xsi:type="string">product_form.product_form</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<arguments>
<argument name="catalogRule" defaultValue="_defaultCatalogRule"/>
</arguments>

<click stepKey="addNewRule" selector="{{AdminGridMainControls.add}}"/>
<fillField selector="{{AdminNewCatalogPriceRule.ruleName}}" userInput="{{catalogRule.name}}" stepKey="fillName" />
<click stepKey="selectActive" selector="{{AdminCategoryBasicFieldSection.enableCategoryLabel}}"/>
Expand All @@ -57,8 +56,27 @@
<click stepKey="openActionDropdown" selector="{{AdminNewCatalogPriceRule.actionsTab}}"/>
<fillField stepKey="fillDiscountValue" selector="{{AdminNewCatalogPriceRuleActions.discountAmount}}" userInput="{{catalogRule.discount_amount}}"/>
<scrollToTopOfPage stepKey="scrollToTop"/>
<click selector="{{AdminNewCatalogPriceRule.save}}" stepKey="clickSave"/>
<waitForPageLoad stepKey="waitForApplied"/>
</actionGroup>

<actionGroup name="AdminCreateCatalogPriceRuleWithConditionActionGroup" extends="createCatalogPriceRule">
<arguments>
<argument name="catalogRuleType" type="entity" defaultValue="PriceRuleWithCondition"/>
</arguments>
<waitForPageLoad stepKey="waitForPageLoad" after="addNewRule"/>
<click selector="{{AdminNewCatalogPriceRule.conditionsTab}}" stepKey="expandConditions" before="openActionDropdown"/>
<scrollTo selector="{{AdminNewCatalogPriceRule.conditionsTab}}" stepKey="scrollToConditionsTab" after="expandConditions"/>
<waitForElementVisible selector="{{PriceRuleConditionsSection.createNewRule}}" stepKey="waitForNewRule" after="scrollToConditionsTab"/>
<click selector="{{PriceRuleConditionsSection.createNewRule}}" stepKey="clickNewRule" after="waitForNewRule"/>
<selectOption selector="{{AdminNewCatalogPriceRuleConditions.conditionsDropdown}}" userInput="{{ProductAttributeFrontendLabel.label}}" stepKey="selectProductAttribute" after="clickNewRule"/>
<waitForPageLoad stepKey="waitForAttributeLoad" after="selectProductAttribute"/>
<!--Assert that attribute contains today date without time-->
<comment userInput="Assert that attribute contains today date without time" stepKey="assertDate" after="waitForAttributeLoad"/>
<generateDate date="now" format="Y-m-d" stepKey="today" after="assertDate"/>
<grabTextFrom selector="{{PriceRuleConditionsSection.firstProductAttributeSelected}}" stepKey="grabTextFromSelectedAttribute" after="today"/>
<assertEquals expected="$today" actual="$grabTextFromSelectedAttribute" stepKey="assertTodayDate" after="grabTextFromSelectedAttribute"/>
</actionGroup>
<actionGroup name="AdminCreateMultipleWebsiteCatalogPriceRule" extends="createCatalogPriceRule">
<remove keyForRemoval="selectSite"/>
<selectOption selector="{{AdminNewCatalogPriceRule.websites}}" parameterArray="['FirstWebsite', 'SecondWebsite']" stepKey="selectWebsite"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

<section name="AdminNewCatalogPriceRuleConditions">
<element name="newCondition" type="button" selector=".rule-param.rule-param-new-child"/>
<element name="conditionsDropdown" type="select" selector="select[data-form-part='catalog_rule_form'][data-ui-id='newchild-0-select-rule-conditions-1-new-child']"/>
<element name="conditionSelect" type="select" selector="select#conditions__{{var}}__new_child" parameterized="true"/>
<element name="targetEllipsis" type="button" selector="//li[{{var}}]//a[@class='label'][text() = '...']" parameterized="true"/>
<element name="targetEllipsisValue" type="button" selector="//ul[@id='conditions__{{var}}__children']//a[contains(text(), '{{var1}}')]" parameterized="true" timeout="30"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Observer;

use Magento\Catalog\Model\Category;
Expand All @@ -18,6 +20,14 @@
*/
class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
{

/**
* Reserved endpoint names.
*
* @var string[]
*/
private $invalidValues = [];

/**
* @var \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator
*/
Expand All @@ -38,22 +48,34 @@ class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
*/
private $categoryRepository;

/**
* @var \Magento\Backend\App\Area\FrontNameResolver
*/
private $frontNameResolver;

/**
* @param CategoryUrlPathGenerator $categoryUrlPathGenerator
* @param ChildrenCategoriesProvider $childrenCategoriesProvider
* @param \Magento\CatalogUrlRewrite\Service\V1\StoreViewService $storeViewService
* @param CategoryRepositoryInterface $categoryRepository
* @param \Magento\Backend\App\Area\FrontNameResolver $frontNameResolver
* @param string[] $invalidValues
*/
public function __construct(
CategoryUrlPathGenerator $categoryUrlPathGenerator,
ChildrenCategoriesProvider $childrenCategoriesProvider,
StoreViewService $storeViewService,
CategoryRepositoryInterface $categoryRepository
CategoryRepositoryInterface $categoryRepository,
\Magento\Backend\App\Area\FrontNameResolver $frontNameResolver = null,
array $invalidValues = []
) {
$this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
$this->childrenCategoriesProvider = $childrenCategoriesProvider;
$this->storeViewService = $storeViewService;
$this->categoryRepository = $categoryRepository;
$this->frontNameResolver = $frontNameResolver ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Backend\App\Area\FrontNameResolver::class);
$this->invalidValues = $invalidValues;
}

/**
Expand Down Expand Up @@ -93,6 +115,17 @@ private function updateUrlKey($category, $urlKey)
if (empty($urlKey)) {
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid URL key'));
}

if (in_array($urlKey, $this->getInvalidValues())) {
throw new \Magento\Framework\Exception\LocalizedException(
__(
'URL key "%1" matches a reserved endpoint name (%2). Use another URL key.',
$urlKey,
implode(', ', $this->getInvalidValues())
)
);
}

$category->setUrlKey($urlKey)
->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
if (!$category->isObjectNew()) {
Expand All @@ -103,6 +136,16 @@ private function updateUrlKey($category, $urlKey)
}
}

/**
* Get reserved endpoint names.
*
* @return array
*/
private function getInvalidValues()
{
return array_unique(array_merge($this->invalidValues, [$this->frontNameResolver->getFrontName()]));
}

/**
* Update url path for children category.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
<entity name="AdminCategoryRestrictedUrlErrorMessage">
<data key="urlAdmin">URL key "admin" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.</data>
<data key="urlSoap">URL key "soap" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.</data>
<data key="urlRest">URL key "rest" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.</data>
<data key="urlGraphql">URL key "graphql" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.</data>
</entity>
</entities>
Loading

0 comments on commit 99f206f

Please sign in to comment.