Skip to content

Commit 176ba2b

Browse files
🔃 [Magento Community Engineering] Community Contributions
Accepted Community Pull Requests: - #27371: [Admin] Do not allow HTML tags for the Product Attribute labels on save (by @vasilii-b)
2 parents 2f1b1d6 + 4f8da50 commit 176ba2b

15 files changed

+210
-6
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminFillProductAttributeDefaultStoreViewActionGroup">
11+
<arguments>
12+
<argument name="value" type="string"/>
13+
</arguments>
14+
<fillField selector="{{AdminProductAttributeManageLabelsSection.DefaultStoreLabel}}" userInput="{{value}}" stepKey="fillDefaultStoreViewLabel"/>
15+
</actionGroup>
16+
</actionGroups>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminNavigateToNewProductAttributePageActionGroup">
12+
<annotations>
13+
<description>Go to the create new product attribute page</description>
14+
</annotations>
15+
16+
<amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/>
17+
<waitForPageLoad stepKey="waitForAttributePageLoad"/>
18+
</actionGroup>
19+
</actionGroups>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminProductAttributePageSwitchTabActionGroup">
12+
<annotations>
13+
<description>Switches the active tab on the Product Attribute New/Edit Page</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="tabName" type="string"/>
17+
</arguments>
18+
19+
<click selector="{{AdminEditProductAttributesSection.tabButton(tabName)}}" stepKey="changeProductAttributeActiveTab"/>
20+
</actionGroup>
21+
</actionGroups>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminSaveProductAttributeActionGroup">
12+
<annotations>
13+
<description>Clicks on Save button to save the attribute.</description>
14+
</annotations>
15+
16+
<waitForElementVisible selector="{{AttributePropertiesSection.Save}}" stepKey="waitForSaveButton"/>
17+
<click selector="{{AttributePropertiesSection.Save}}" stepKey="clickSaveButton"/>
18+
<waitForPageLoad stepKey="waitForAttributeToSave"/>
19+
</actionGroup>
20+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertSeeProductAttributeValidationErrorOnManageLabelsTabActionGroup">
12+
<annotations>
13+
<description>Check whenever the validation error is present for the product attribute in the "Manage Labels" Tab</description>
14+
</annotations>
15+
16+
<arguments>
17+
<argument name="message" type="string"/>
18+
</arguments>
19+
20+
<see userInput="{{message}}" selector="{{AdminProductAttributeManageLabelsSection.attributeStoreLabelValidationError}}" stepKey="seeValidationMessage"/>
21+
</actionGroup>
22+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertSeeProductAttributeValidationErrorOnPropertiesTabActionGroup">
12+
<annotations>
13+
<description>Check whenever the validation error is present for the product attribute in the "Properties" Tab</description>
14+
</annotations>
15+
16+
<arguments>
17+
<argument name="message" type="string"/>
18+
</arguments>
19+
20+
<see userInput="{{message}}" selector="{{AttributePropertiesSection.attributeLabelValidationError}}" stepKey="seeValidationMessage"/>
21+
</actionGroup>
22+
</actionGroups>

app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@
402402
<data key="frontend_label">Size</data>
403403
<data key="attribute_code" unique="suffix">size_attr</data>
404404
</entity>
405+
<entity name="productAttributeWithHtmlTagsInLabel" extends="newProductAttribute" type="ProductAttribute">
406+
<data key="default_label" unique="suffix">Attribute Default label &lt;span&gt;</data>
407+
<data key="default_store_label" unique="suffix">Attribute Store label &lt;span&gt; </data>
408+
<data key="frontend_input">text</data>
409+
</entity>
405410
<!-- Product attribute from file "export_import_configurable_product.csv" -->
406411
<entity name="ProductAttributeWithTwoOptionsForExportImport" extends="productAttributeDropdownTwoOptions" type="ProductAttribute">
407412
<data key="attribute_code">attribute</data>

app/code/Magento/Catalog/Test/Mftf/Page/AdminProductAttributeFormPage.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
1010
<page name="ProductAttributePage" url="catalog/product_attribute/new/" area="admin" module="Catalog">
1111
<section name="AdminCreateProductAttributeSection"/>
12+
<section name="AdminProductAttributeManageLabelsSection"/>
1213
</page>
1314
</pages>

app/code/Magento/Catalog/Test/Mftf/Section/AdminCreateProductAttributeSection/AttributePropertiesSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
<element name="dropdownNthOptionAdmin" type="textarea" selector="tbody[data-role='options-container'] tr:nth-child({{var}}) td:nth-child(3) input" parameterized="true"/>
3030
<element name="dropdownNthOptionDefaultStoreView" type="textarea" selector="tbody[data-role='options-container'] tr:nth-child({{var}}) td:nth-child(4) input" parameterized="true"/>
3131
<element name="dropdownNthOptionDelete" type="button" selector="tbody[data-role='options-container'] tr:nth-child({{var}}) button[title='Delete']" parameterized="true"/>
32+
<element name="attributeLabelValidationError" type="text" selector=".field-attribute_label .mage-error"/>
3233
</section>
3334
</sections>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
<element name="ProductDataMayBeLostConfirmButton" type="button" selector="//aside[contains(@class,'_show')]//button[.='Change Input Type']"/>
2323
<element name="defaultLabel" type="text" selector="//td[contains(text(), '{{attributeName}}')]/following-sibling::td[contains(@class, 'col-frontend_label')]" parameterized="true"/>
2424
<element name="formByStoreId" type="block" selector="//form[contains(@action,'store/{{store_id}}')]" parameterized="true"/>
25+
<element name="tabButton" type="text" selector="#product_attribute_tabs a[title='{{tabName}}']" parameterized="true"/>
2526
</section>
2627
</sections>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminProductAttributeManageLabelsSection">
12+
<element name="DefaultStoreLabel" type="input" selector="#attribute-labels-table [name='frontend_label[1]']"/>
13+
<element name="attributeStoreLabelValidationError" type="text" selector="#attribute-labels-table .mage-error"/>
14+
</section>
15+
</sections>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminProductAttributeLabelDontAllowHtmlTagsTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<stories value="Product Attribute label must not contain HTML tags"/>
15+
<title value="Product Attribute label musts not contain HTML tags"/>
16+
<description value="Test whenever HTML tags are allowed for a product attribute label"/>
17+
<severity value="CRITICAL"/>
18+
<group value="catalog"/>
19+
</annotations>
20+
<before>
21+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
22+
</before>
23+
<after>
24+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutAdmin"/>
25+
</after>
26+
27+
<actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="openProductAttributePage"/>
28+
29+
<actionGroup ref="AdminFillProductAttributePropertiesActionGroup" stepKey="fillAttributeDefaultLabel">
30+
<argument name="attributeName" value="{{productAttributeWithHtmlTagsInLabel.default_label}}"/>
31+
<argument name="attributeType" value="{{productAttributeWithHtmlTagsInLabel.frontend_input}}" />
32+
</actionGroup>
33+
34+
<actionGroup ref="AdminProductAttributePageSwitchTabActionGroup" stepKey="makeManageLabelsTabActive">
35+
<argument name="tabName" value="Manage Labels"/>
36+
</actionGroup>
37+
38+
<actionGroup ref="AdminFillProductAttributeDefaultStoreViewActionGroup" stepKey="fillAttributeDefaultStoreViewLabel">
39+
<argument name="value" value="{{productAttributeWithHtmlTagsInLabel.default_store_label}}"/>
40+
</actionGroup>
41+
42+
<actionGroup ref="AdminSaveProductAttributeActionGroup" stepKey="saveAttribute"/>
43+
44+
<actionGroup ref="AssertSeeProductAttributeValidationErrorOnManageLabelsTabActionGroup" stepKey="validateAttributeStoreViewLabelForHtmlTags">
45+
<argument name="message" value="HTML tags are not allowed"/>
46+
</actionGroup>
47+
48+
<actionGroup ref="AdminProductAttributePageSwitchTabActionGroup" stepKey="makePropertiesTabActive">
49+
<argument name="tabName" value="Properties"/>
50+
</actionGroup>
51+
52+
<actionGroup ref="AssertSeeProductAttributeValidationErrorOnPropertiesTabActionGroup" stepKey="validateAttributeLabelForHtmlTags">
53+
<argument name="message" value="HTML tags are not allowed"/>
54+
</actionGroup>
55+
</test>
56+
</tests>

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/labels.phtml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,23 @@
1919
<table class="admin__control-table" id="attribute-labels-table">
2020
<thead>
2121
<tr>
22-
<?php foreach ($block->getStores() as $_store) :?>
22+
<?php foreach ($block->getStores() as $_store): ?>
2323
<th class="col-store-view"><?= $block->escapeHtml($_store->getName()) ?></th>
2424
<?php endforeach; ?>
2525
</tr>
2626
</thead>
2727
<tbody>
2828
<tr>
2929
<?php $_labels = $block->getLabelValues() ?>
30-
<?php foreach ($block->getStores() as $_store) :?>
30+
<?php foreach ($block->getStores() as $_store): ?>
3131
<td class="col-store-view">
32-
<input class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID) :?> required-option<?php endif; ?>"
32+
<?php $isRequired = $_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID; ?>
33+
<?php $isRequiredClass = $isRequired ? 'required-option' : ''; ?>
34+
<input class="input-text validate-no-html-tags <?= /* @noEscape */ $isRequiredClass ?>"
3335
type="text"
3436
name="frontend_label[<?= $block->escapeHtmlAttr($_store->getId()) ?>]"
3537
value="<?= $block->escapeHtmlAttr($_labels[$_store->getId()]) ?>"
36-
<?php if ($block->getReadOnly()) :?>
38+
<?php if ($block->getReadOnly()): ?>
3739
disabled="disabled"
3840
<?php endif;?>/>
3941
</td>

app/code/Magento/Catalog/view/adminhtml/ui_component/product_attribute_add_form.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<required>true</required>
6464
<validation>
6565
<rule name="required-entry" xsi:type="boolean">true</rule>
66+
<rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
6667
</validation>
6768
<dataType>string</dataType>
6869
<label translate="true">Attribute Label</label>

app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ protected function _prepareForm()
130130
'label' => __('Default Label'),
131131
'title' => __('Default label'),
132132
'required' => true,
133-
'value' => is_array($labels) ? $labels[0] : $labels
133+
'value' => is_array($labels) ? $labels[0] : $labels,
134+
'class' => 'validate-no-html-tags',
134135
]
135136
);
136137

@@ -282,7 +283,8 @@ protected function _initFormValues()
282283
* Adding js block to the end of this block
283284
*
284285
* @param string $html
285-
* @return string
286+
*
287+
* @return string
286288
*/
287289
protected function _afterToHtml($html)
288290
{

0 commit comments

Comments
 (0)