diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminFillProductAttributeDefaultStoreViewActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminFillProductAttributeDefaultStoreViewActionGroup.xml new file mode 100644 index 0000000000000..42d205f0fb397 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminFillProductAttributeDefaultStoreViewActionGroup.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminNavigateToNewProductAttributePageActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminNavigateToNewProductAttributePageActionGroup.xml new file mode 100644 index 0000000000000..b7dbcc2c86dc4 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminNavigateToNewProductAttributePageActionGroup.xml @@ -0,0 +1,19 @@ + + + + + + + Go to the create new product attribute page + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminProductAttributePageSwitchTabActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminProductAttributePageSwitchTabActionGroup.xml new file mode 100644 index 0000000000000..cbef1b61fe44c --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminProductAttributePageSwitchTabActionGroup.xml @@ -0,0 +1,21 @@ + + + + + + + Switches the active tab on the Product Attribute New/Edit Page + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminSaveProductAttributeActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminSaveProductAttributeActionGroup.xml new file mode 100644 index 0000000000000..956dc3bf6fa52 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminSaveProductAttributeActionGroup.xml @@ -0,0 +1,20 @@ + + + + + + + Clicks on Save button to save the attribute. + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertSeeProductAttributeValidationErrorOnManageLabelsTabActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertSeeProductAttributeValidationErrorOnManageLabelsTabActionGroup.xml new file mode 100644 index 0000000000000..370d30003baf8 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertSeeProductAttributeValidationErrorOnManageLabelsTabActionGroup.xml @@ -0,0 +1,22 @@ + + + + + + + Check whenever the validation error is present for the product attribute in the "Manage Labels" Tab + + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertSeeProductAttributeValidationErrorOnPropertiesTabActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertSeeProductAttributeValidationErrorOnPropertiesTabActionGroup.xml new file mode 100644 index 0000000000000..5e0da379bdccb --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertSeeProductAttributeValidationErrorOnPropertiesTabActionGroup.xml @@ -0,0 +1,22 @@ + + + + + + + Check whenever the validation error is present for the product attribute in the "Properties" Tab + + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml b/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml index abb4301fd8f9f..a2561e00a0e24 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml @@ -402,6 +402,11 @@ Size size_attr + + Attribute Default label <span> + Attribute Store label <span> + text + attribute diff --git a/app/code/Magento/Catalog/Test/Mftf/Page/AdminProductAttributeFormPage.xml b/app/code/Magento/Catalog/Test/Mftf/Page/AdminProductAttributeFormPage.xml index fab87f90f86dd..3acaaf4e1775d 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Page/AdminProductAttributeFormPage.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Page/AdminProductAttributeFormPage.xml @@ -9,5 +9,6 @@ xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
+
diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminCreateProductAttributeSection/AttributePropertiesSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminCreateProductAttributeSection/AttributePropertiesSection.xml index df5ebab9c9b2b..e3a59b37ab146 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/AdminCreateProductAttributeSection/AttributePropertiesSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminCreateProductAttributeSection/AttributePropertiesSection.xml @@ -29,5 +29,6 @@ +
diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminEditProductAttributesSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminEditProductAttributesSection.xml index b243fbfd6034a..ad4ab57f8de2c 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/AdminEditProductAttributesSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminEditProductAttributesSection.xml @@ -22,5 +22,6 @@ +
diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductAttributeManageLabelsSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductAttributeManageLabelsSection.xml new file mode 100644 index 0000000000000..e1863576b8ecf --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductAttributeManageLabelsSection.xml @@ -0,0 +1,15 @@ + + + + +
+ + +
+
diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminProductAttributeLabelDontAllowHtmlTagsTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminProductAttributeLabelDontAllowHtmlTagsTest.xml new file mode 100644 index 0000000000000..f3981e7b8f76a --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminProductAttributeLabelDontAllowHtmlTagsTest.xml @@ -0,0 +1,56 @@ + + + + + + + + + + <description value="Test whenever HTML tags are allowed for a product attribute label"/> + <severity value="CRITICAL"/> + <group value="catalog"/> + </annotations> + <before> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + </before> + <after> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logoutAdmin"/> + </after> + + <actionGroup ref="AdminNavigateToNewProductAttributePageActionGroup" stepKey="openProductAttributePage"/> + + <actionGroup ref="AdminFillProductAttributePropertiesActionGroup" stepKey="fillAttributeDefaultLabel"> + <argument name="attributeName" value="{{productAttributeWithHtmlTagsInLabel.default_label}}"/> + <argument name="attributeType" value="{{productAttributeWithHtmlTagsInLabel.frontend_input}}" /> + </actionGroup> + + <actionGroup ref="AdminProductAttributePageSwitchTabActionGroup" stepKey="makeManageLabelsTabActive"> + <argument name="tabName" value="Manage Labels"/> + </actionGroup> + + <actionGroup ref="AdminFillProductAttributeDefaultStoreViewActionGroup" stepKey="fillAttributeDefaultStoreViewLabel"> + <argument name="value" value="{{productAttributeWithHtmlTagsInLabel.default_store_label}}"/> + </actionGroup> + + <actionGroup ref="AdminSaveProductAttributeActionGroup" stepKey="saveAttribute"/> + + <actionGroup ref="AssertSeeProductAttributeValidationErrorOnManageLabelsTabActionGroup" stepKey="validateAttributeStoreViewLabelForHtmlTags"> + <argument name="message" value="HTML tags are not allowed"/> + </actionGroup> + + <actionGroup ref="AdminProductAttributePageSwitchTabActionGroup" stepKey="makePropertiesTabActive"> + <argument name="tabName" value="Properties"/> + </actionGroup> + + <actionGroup ref="AssertSeeProductAttributeValidationErrorOnPropertiesTabActionGroup" stepKey="validateAttributeLabelForHtmlTags"> + <argument name="message" value="HTML tags are not allowed"/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/labels.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/labels.phtml index 1d5d251f00de9..85a6b347f2feb 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/labels.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/labels.phtml @@ -19,7 +19,7 @@ <table class="admin__control-table" id="attribute-labels-table"> <thead> <tr> - <?php foreach ($block->getStores() as $_store) :?> + <?php foreach ($block->getStores() as $_store): ?> <th class="col-store-view"><?= $block->escapeHtml($_store->getName()) ?></th> <?php endforeach; ?> </tr> @@ -27,13 +27,15 @@ <tbody> <tr> <?php $_labels = $block->getLabelValues() ?> - <?php foreach ($block->getStores() as $_store) :?> + <?php foreach ($block->getStores() as $_store): ?> <td class="col-store-view"> - <input class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID) :?> required-option<?php endif; ?>" + <?php $isRequired = $_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID; ?> + <?php $isRequiredClass = $isRequired ? 'required-option' : ''; ?> + <input class="input-text validate-no-html-tags <?= /* @noEscape */ $isRequiredClass ?>" type="text" name="frontend_label[<?= $block->escapeHtmlAttr($_store->getId()) ?>]" value="<?= $block->escapeHtmlAttr($_labels[$_store->getId()]) ?>" - <?php if ($block->getReadOnly()) :?> + <?php if ($block->getReadOnly()): ?> disabled="disabled" <?php endif;?>/> </td> diff --git a/app/code/Magento/Catalog/view/adminhtml/ui_component/product_attribute_add_form.xml b/app/code/Magento/Catalog/view/adminhtml/ui_component/product_attribute_add_form.xml index 3a6621137ed5a..7f87eb0cdd391 100644 --- a/app/code/Magento/Catalog/view/adminhtml/ui_component/product_attribute_add_form.xml +++ b/app/code/Magento/Catalog/view/adminhtml/ui_component/product_attribute_add_form.xml @@ -63,6 +63,7 @@ <required>true</required> <validation> <rule name="required-entry" xsi:type="boolean">true</rule> + <rule name="validate-no-html-tags" xsi:type="boolean">true</rule> </validation> <dataType>string</dataType> <label translate="true">Attribute Label</label> diff --git a/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.php b/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.php index be9d2700664c7..fe660f01c8244 100644 --- a/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.php +++ b/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.php @@ -130,7 +130,8 @@ protected function _prepareForm() 'label' => __('Default Label'), 'title' => __('Default label'), 'required' => true, - 'value' => is_array($labels) ? $labels[0] : $labels + 'value' => is_array($labels) ? $labels[0] : $labels, + 'class' => 'validate-no-html-tags', ] ); @@ -282,7 +283,8 @@ protected function _initFormValues() * Adding js block to the end of this block * * @param string $html - * @return string + * + * @return string */ protected function _afterToHtml($html) {