From 79fdffbe72600ccfeb49b7e5b02ea864e6f3baf0 Mon Sep 17 00:00:00 2001 From: Eden Date: Sun, 20 Oct 2019 22:47:45 +0700 Subject: [PATCH 1/2] Add validation in catalog rule and shopping cart rule form --- .../ui_component/catalog_rule_form.xml | 4 ++++ .../ui_component/sales_rule_form.xml | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml b/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml index 2af8bb0770b20..35fd7d8a192f4 100644 --- a/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml +++ b/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml @@ -208,6 +208,10 @@ + + true + true + text sort_order diff --git a/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml b/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml index 639e12006232b..63faf29afd769 100644 --- a/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml +++ b/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml @@ -297,6 +297,9 @@ + + true + text uses_per_coupon @@ -309,6 +312,9 @@ + + true + Usage limit enforced for logged in customers only. @@ -356,6 +362,10 @@ + + true + true + text sort_order @@ -422,6 +432,8 @@ true + true + true text @@ -435,6 +447,10 @@ + + true + true + text discount_qty @@ -447,6 +463,10 @@ + + true + true + text discount_step From 1b66fb468d52868e2c5708fbc6ec7def4acaffc6 Mon Sep 17 00:00:00 2001 From: Eden Date: Wed, 23 Oct 2019 23:23:38 +0700 Subject: [PATCH 2/2] cover issue 25172 with mftf test --- .../CatalogPriceRuleActionGroup.xml | 19 +++++++ .../Test/Mftf/Data/CatalogRuleData.xml | 15 ++++++ .../AdminNewCatalogPriceRuleSection.xml | 2 + .../Test/AdminCreateCatalogPriceRuleTest.xml | 23 ++++++++ .../ui_component/catalog_rule_form.xml | 3 +- .../Test/Mftf/Data/SalesRuleData.xml | 9 ++++ .../AdminCartPriceRulesFormSection.xml | 2 + .../Mftf/Test/AdminCreateInvalidRuleTest.xml | 53 +++++++++++++++++++ .../ui_component/sales_rule_form.xml | 3 +- 9 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 app/code/Magento/SalesRule/Test/Mftf/Test/AdminCreateInvalidRuleTest.xml diff --git a/app/code/Magento/CatalogRule/Test/Mftf/ActionGroup/CatalogPriceRuleActionGroup.xml b/app/code/Magento/CatalogRule/Test/Mftf/ActionGroup/CatalogPriceRuleActionGroup.xml index 09053b5ad14a3..620f61b9ec27a 100644 --- a/app/code/Magento/CatalogRule/Test/Mftf/ActionGroup/CatalogPriceRuleActionGroup.xml +++ b/app/code/Magento/CatalogRule/Test/Mftf/ActionGroup/CatalogPriceRuleActionGroup.xml @@ -208,4 +208,23 @@ + + + + Goes to the Catalog Price Rule grid. Clicks on Add. Fills in the provided Catalog Rule details with invalid data. + + + + + + + + + + + + + + + diff --git a/app/code/Magento/CatalogRule/Test/Mftf/Data/CatalogRuleData.xml b/app/code/Magento/CatalogRule/Test/Mftf/Data/CatalogRuleData.xml index 75a7484324576..2920a895f607d 100644 --- a/app/code/Magento/CatalogRule/Test/Mftf/Data/CatalogRuleData.xml +++ b/app/code/Magento/CatalogRule/Test/Mftf/Data/CatalogRuleData.xml @@ -173,4 +173,19 @@ Free Shipping in conditions Free Shipping in conditions + + + CatalogPriceRule + Catalog Price Rule Description + 1 + + 0 + + + 1 + + by_percent + 10 + ten + diff --git a/app/code/Magento/CatalogRule/Test/Mftf/Section/AdminNewCatalogPriceRuleSection.xml b/app/code/Magento/CatalogRule/Test/Mftf/Section/AdminNewCatalogPriceRuleSection.xml index c736dd8dde2cb..61f2e7ac55ef7 100644 --- a/app/code/Magento/CatalogRule/Test/Mftf/Section/AdminNewCatalogPriceRuleSection.xml +++ b/app/code/Magento/CatalogRule/Test/Mftf/Section/AdminNewCatalogPriceRuleSection.xml @@ -37,6 +37,8 @@ + +
diff --git a/app/code/Magento/CatalogRule/Test/Mftf/Test/AdminCreateCatalogPriceRuleTest.xml b/app/code/Magento/CatalogRule/Test/Mftf/Test/AdminCreateCatalogPriceRuleTest.xml index 09b924603c54a..ee61af180d350 100644 --- a/app/code/Magento/CatalogRule/Test/Mftf/Test/AdminCreateCatalogPriceRuleTest.xml +++ b/app/code/Magento/CatalogRule/Test/Mftf/Test/AdminCreateCatalogPriceRuleTest.xml @@ -196,4 +196,27 @@ + + + + + + + <description value="Admin can not create catalog price rule with the invalid data"/> + <severity value="MAJOR"/> + <group value="CatalogRule"/> + </annotations> + <before> + <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/> + </before> + <after> + <amOnPage url="{{AdminLogoutPage.url}}" stepKey="amOnLogoutPage"/> + </after> + + <actionGroup ref="newCatalogPriceRuleWithInvalidData" stepKey="createNewPriceRule"> + <argument name="catalogRule" value="catalogRuleWithInvalid"/> + </actionGroup> + + <see selector="{{AdminNewCatalogPriceRule.fieldError('sort_order')}}" userInput="Please enter a valid number in this field." stepKey="seeSortOrderError"/> + </test> </tests> diff --git a/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml b/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml index 35fd7d8a192f4..59e3c4668e8a4 100644 --- a/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml +++ b/app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml @@ -209,8 +209,7 @@ </argument> <settings> <validation> - <rule name="validate-number" xsi:type="boolean">true</rule> - <rule name="validate-zero-or-greater" xsi:type="boolean">true</rule> + <rule name="validate-digits" xsi:type="boolean">true</rule> </validation> <dataType>text</dataType> <label translate="true">Priority</label> diff --git a/app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml b/app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml index c1ec728a6cfb9..8b1f27812b6cd 100644 --- a/app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml +++ b/app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml @@ -457,4 +457,13 @@ <requiredEntity type="SalesRuleLabel">SalesRuleLabelDefault</requiredEntity> <requiredEntity type="SalesRuleLabel">SalesRuleLabelStore1</requiredEntity> </entity> + + <entity name="TestSalesRuleWithInvalidData" type="SalesRule"> + <data key="userPerCustomer">one</data> + <data key="userPerCoupon">one</data> + <data key="priority">one</data> + <data key="discountStep">one</data> + <data key="discountAmount">one</data> + <data key="maximumQtyDiscount">one</data> + </entity> </entities> diff --git a/app/code/Magento/SalesRule/Test/Mftf/Section/AdminCartPriceRulesFormSection.xml b/app/code/Magento/SalesRule/Test/Mftf/Section/AdminCartPriceRulesFormSection.xml index 3849d153be465..a45baad7f0910 100644 --- a/app/code/Magento/SalesRule/Test/Mftf/Section/AdminCartPriceRulesFormSection.xml +++ b/app/code/Magento/SalesRule/Test/Mftf/Section/AdminCartPriceRulesFormSection.xml @@ -98,5 +98,7 @@ <element name="couponQty" type="input" selector="#coupons_qty"/> <element name="generateCouponsButton" type="button" selector="#coupons_generate_button" timeout="30"/> <element name="generatedCouponByIndex" type="text" selector="#couponCodesGrid_table > tbody > tr:nth-child({{var}}) > td.col-code" parameterized="true"/> + + <element name="fieldError" type="text" selector="//input[@name='{{fieldName}}']/following-sibling::label[@class='admin__field-error']" parameterized="true"/> </section> </sections> diff --git a/app/code/Magento/SalesRule/Test/Mftf/Test/AdminCreateInvalidRuleTest.xml b/app/code/Magento/SalesRule/Test/Mftf/Test/AdminCreateInvalidRuleTest.xml new file mode 100644 index 0000000000000..620112e323ff5 --- /dev/null +++ b/app/code/Magento/SalesRule/Test/Mftf/Test/AdminCreateInvalidRuleTest.xml @@ -0,0 +1,53 @@ +<?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="AdminCreateInvalidRuleTest"> + <annotations> + <features value="SalesRule"/> + <stories value="Create cart price rule with invalid data"/> + <title value="Admin can not create rule with invalid data"/> + <description value="Admin can not create rule with invalid data"/> + <severity value="MAJOR"/> + <group value="SalesRule"/> + </annotations> + + <before> + <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/> + </before> + + <after> + <actionGroup ref="logout" stepKey="adminLogout"/> + </after> + + <amOnPage url="{{AdminCartPriceRulesPage.url}}" stepKey="amOnCartPriceList"/> + <waitForPageLoad stepKey="waitForRulesPage"/> + <click selector="{{AdminCartPriceRulesSection.addNewRuleButton}}" stepKey="clickAddNewRule"/> + + <click selector="{{AdminCartPriceRulesFormSection.actionsHeader}}" stepKey="clickToExpandActions"/> + <selectOption selector="{{AdminCartPriceRulesFormSection.apply}}" userInput="Buy X get Y free (discount amount is Y)" stepKey="selectActionType"/> + <fillField selector="{{AdminCartPriceRulesFormSection.discountAmount}}" userInput="{{TestSalesRuleWithInvalidData.discountAmount}}" stepKey="fillDiscountAmount"/> + <fillField selector="{{AdminCartPriceRulesFormSection.maximumQtyDiscount}}" userInput="{{TestSalesRuleWithInvalidData.maximumQtyDiscount}}" stepKey="fillDiscountQty"/> + <fillField selector="{{AdminCartPriceRulesFormSection.discountStep}}" userInput="{{TestSalesRuleWithInvalidData.discountStep}}" stepKey="fillDiscountStep"/> + + <fillField selector="{{AdminCartPriceRulesFormSection.userPerCustomer}}" userInput="{{TestSalesRuleWithInvalidData.userPerCustomer}}" stepKey="fillUsePerCustomer"/> + <selectOption selector="{{AdminCartPriceRulesFormSection.coupon}}" userInput="Specific Coupon" stepKey="selectCouponType"/> + <fillField selector="{{AdminCartPriceRulesFormSection.userPerCoupon}}" userInput="{{TestSalesRuleWithInvalidData.userPerCoupon}}" stepKey="fillUsePerCoupon"/> + <fillField selector="{{AdminCartPriceRulesFormSection.priority}}" userInput="{{TestSalesRuleWithInvalidData.priority}}" stepKey="fillPriority"/> + + <click selector="{{AdminCartPriceRulesFormSection.save}}" stepKey="clickSaveButton"/> + + <see selector="{{AdminNewCatalogPriceRule.fieldError('uses_per_coupon')}}" userInput="Please enter a valid number in this field." stepKey="seePerCouponError"/> + <see selector="{{AdminNewCatalogPriceRule.fieldError('uses_per_customer')}}" userInput="Please enter a valid number in this field." stepKey="seePerCustomerError"/> + <see selector="{{AdminNewCatalogPriceRule.fieldError('sort_order')}}" userInput="Please enter a valid number in this field." stepKey="seePriorityError"/> + <see selector="{{AdminNewCatalogPriceRule.fieldError('discount_amount')}}" userInput="Please enter a valid number in this field." stepKey="seeDiscountAmountError"/> + <see selector="{{AdminNewCatalogPriceRule.fieldError('discount_qty')}}" userInput="Please enter a valid number in this field." stepKey="seeMaximumQtyError"/> + <see selector="{{AdminNewCatalogPriceRule.fieldError('discount_step')}}" userInput="Please enter a valid number in this field." stepKey="seeDiscountStepError"/> + </test> +</tests> diff --git a/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml b/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml index 63faf29afd769..e1c12f45012ee 100644 --- a/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml +++ b/app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml @@ -363,8 +363,7 @@ </argument> <settings> <validation> - <rule name="validate-number" xsi:type="boolean">true</rule> - <rule name="validate-zero-or-greater" xsi:type="boolean">true</rule> + <rule name="validate-digits" xsi:type="boolean">true</rule> </validation> <dataType>text</dataType> <label translate="true">Priority</label>