Skip to content

Commit cfa6c57

Browse files
ENGCOM-6143: Add validation in catalog rule and shopping cart rule form #25172
- Merge Pull Request #25172 from edenduong/magento2:2.3-bugfix/validate_catalog_cart_rule - Merged commits: 1. 79fdffb 2. 1b66fb4 3. 4dae23b
2 parents e34c795 + 4dae23b commit cfa6c57

File tree

9 files changed

+144
-0
lines changed

9 files changed

+144
-0
lines changed

app/code/Magento/CatalogRule/Test/Mftf/ActionGroup/CatalogPriceRuleActionGroup.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,23 @@
233233
<click selector="{{AdminNewCatalogPriceRuleConditions.activeConditionApplyButton}}" stepKey="clickApply"/>
234234
<waitForElementNotVisible selector="{{AdminNewCatalogPriceRuleConditions.activeConditionApplyButton}}" stepKey="waitForApplyButtonInvisibility"/>
235235
</actionGroup>
236+
237+
<actionGroup name="newCatalogPriceRuleWithInvalidData">
238+
<annotations>
239+
<description>Goes to the Catalog Price Rule grid. Clicks on Add. Fills in the provided Catalog Rule details with invalid data.</description>
240+
</annotations>
241+
<arguments>
242+
<argument name="catalogRule" defaultValue="catalogRuleWithInvalid"/>
243+
</arguments>
244+
245+
<!-- Go to the admin Catalog rule grid and add a new one -->
246+
<amOnPage stepKey="goToPriceRulePage" url="{{CatalogRulePage.url}}"/>
247+
<waitForPageLoad stepKey="waitForPriceRulePage"/>
248+
249+
<click stepKey="addNewRule" selector="{{AdminGridMainControls.add}}"/>
250+
<fillField stepKey="fillPriority" selector="{{AdminNewCatalogPriceRule.priority}}" userInput="{{catalogRule.priority}}"/>
251+
<scrollToTopOfPage stepKey="scrollToTop"/>
252+
<click selector="{{AdminNewCatalogPriceRule.save}}" stepKey="clickSave"/>
253+
<waitForPageLoad stepKey="waitForApplied"/>
254+
</actionGroup>
236255
</actionGroups>

app/code/Magento/CatalogRule/Test/Mftf/Data/CatalogRuleData.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,19 @@
173173
<data key="defaultRuleLabelAllStoreViews">Free Shipping in conditions</data>
174174
<data key="defaultStoreView">Free Shipping in conditions</data>
175175
</entity>
176+
177+
<entity name="catalogRuleWithInvalid" type="catalogRule">
178+
<data key="name" unique="suffix">CatalogPriceRule</data>
179+
<data key="description">Catalog Price Rule Description</data>
180+
<data key="is_active">1</data>
181+
<array key="customer_group_ids">
182+
<item>0</item>
183+
</array>
184+
<array key="website_ids">
185+
<item>1</item>
186+
</array>
187+
<data key="simple_action">by_percent</data>
188+
<data key="discount_amount">10</data>
189+
<data key="priority">ten</data>
190+
</entity>
176191
</entities>

app/code/Magento/CatalogRule/Test/Mftf/Section/AdminNewCatalogPriceRuleSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
<element name="priority" type="input" selector="[name='sort_order']"/>
3838
<element name="conditionsTab" type="block" selector="[data-index='block_promo_catalog_edit_tab_conditions']"/>
3939
<element name="actionsTab" type="block" selector="[data-index='actions']"/>
40+
41+
<element name="fieldError" type="text" selector="//input[@name='{{fieldName}}']/following-sibling::label[@class='admin__field-error']" parameterized="true"/>
4042
</section>
4143

4244
<section name="AdminNewCatalogPriceRuleActions">

app/code/Magento/CatalogRule/Test/Mftf/Test/AdminCreateCatalogPriceRuleTest.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,27 @@
196196
<see selector="{{StorefrontCategoryProductSection.ProductInfoByNumber('1')}}" userInput="$$createProduct.name$$" stepKey="seeProduct2"/>
197197
<see selector="{{StorefrontCategoryProductSection.ProductInfoByNumber('1')}}" userInput="$123.00" stepKey="seeDiscountedPrice2"/>
198198
</test>
199+
200+
<test name="AdminCreateCatalogPriceRuleWithInvalidDataTest">
201+
<annotations>
202+
<features value="CatalogRule"/>
203+
<stories value="Create Catalog Price Rule"/>
204+
<title value="Admin can not create catalog price rule with the invalid data"/>
205+
<description value="Admin can not create catalog price rule with the invalid data"/>
206+
<severity value="MAJOR"/>
207+
<group value="CatalogRule"/>
208+
</annotations>
209+
<before>
210+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
211+
</before>
212+
<after>
213+
<amOnPage url="{{AdminLogoutPage.url}}" stepKey="amOnLogoutPage"/>
214+
</after>
215+
216+
<actionGroup ref="newCatalogPriceRuleWithInvalidData" stepKey="createNewPriceRule">
217+
<argument name="catalogRule" value="catalogRuleWithInvalid"/>
218+
</actionGroup>
219+
220+
<see selector="{{AdminNewCatalogPriceRule.fieldError('sort_order')}}" userInput="Please enter a valid number in this field." stepKey="seeSortOrderError"/>
221+
</test>
199222
</tests>

app/code/Magento/CatalogRule/view/adminhtml/ui_component/catalog_rule_form.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@
208208
</item>
209209
</argument>
210210
<settings>
211+
<validation>
212+
<rule name="validate-digits" xsi:type="boolean">true</rule>
213+
</validation>
211214
<dataType>text</dataType>
212215
<label translate="true">Priority</label>
213216
<dataScope>sort_order</dataScope>

app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,4 +464,13 @@
464464
<requiredEntity type="SalesRuleLabel">SalesRuleLabelDefault</requiredEntity>
465465
<requiredEntity type="SalesRuleLabel">SalesRuleLabelStore1</requiredEntity>
466466
</entity>
467+
468+
<entity name="TestSalesRuleWithInvalidData" type="SalesRule">
469+
<data key="userPerCustomer">one</data>
470+
<data key="userPerCoupon">one</data>
471+
<data key="priority">one</data>
472+
<data key="discountStep">one</data>
473+
<data key="discountAmount">one</data>
474+
<data key="maximumQtyDiscount">one</data>
475+
</entity>
467476
</entities>

app/code/Magento/SalesRule/Test/Mftf/Section/AdminCartPriceRulesFormSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@
9999
<element name="generateCouponsButton" type="button" selector="#coupons_generate_button" timeout="30"/>
100100
<element name="generatedCouponByIndex" type="text" selector="#couponCodesGrid_table > tbody > tr:nth-child({{var}}) > td.col-code" parameterized="true"/>
101101
<element name="couponGridUsedHeader" type="text" selector="#couponCodesGrid thead th[data-sort='used']"/>
102+
<element name="fieldError" type="text" selector="//input[@name='{{fieldName}}']/following-sibling::label[@class='admin__field-error']" parameterized="true"/>
102103
</section>
103104
</sections>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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="AdminCreateInvalidRuleTest">
12+
<annotations>
13+
<features value="SalesRule"/>
14+
<stories value="Create cart price rule with invalid data"/>
15+
<title value="Admin can not create rule with invalid data"/>
16+
<description value="Admin can not create rule with invalid data"/>
17+
<severity value="MAJOR"/>
18+
<group value="SalesRule"/>
19+
</annotations>
20+
21+
<before>
22+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
23+
</before>
24+
25+
<after>
26+
<actionGroup ref="logout" stepKey="adminLogout"/>
27+
</after>
28+
29+
<amOnPage url="{{AdminCartPriceRulesPage.url}}" stepKey="amOnCartPriceList"/>
30+
<waitForPageLoad stepKey="waitForRulesPage"/>
31+
<click selector="{{AdminCartPriceRulesSection.addNewRuleButton}}" stepKey="clickAddNewRule"/>
32+
33+
<click selector="{{AdminCartPriceRulesFormSection.actionsHeader}}" stepKey="clickToExpandActions"/>
34+
<selectOption selector="{{AdminCartPriceRulesFormSection.apply}}" userInput="Buy X get Y free (discount amount is Y)" stepKey="selectActionType"/>
35+
<fillField selector="{{AdminCartPriceRulesFormSection.discountAmount}}" userInput="{{TestSalesRuleWithInvalidData.discountAmount}}" stepKey="fillDiscountAmount"/>
36+
<fillField selector="{{AdminCartPriceRulesFormSection.maximumQtyDiscount}}" userInput="{{TestSalesRuleWithInvalidData.maximumQtyDiscount}}" stepKey="fillDiscountQty"/>
37+
<fillField selector="{{AdminCartPriceRulesFormSection.discountStep}}" userInput="{{TestSalesRuleWithInvalidData.discountStep}}" stepKey="fillDiscountStep"/>
38+
39+
<fillField selector="{{AdminCartPriceRulesFormSection.userPerCustomer}}" userInput="{{TestSalesRuleWithInvalidData.userPerCustomer}}" stepKey="fillUsePerCustomer"/>
40+
<selectOption selector="{{AdminCartPriceRulesFormSection.coupon}}" userInput="Specific Coupon" stepKey="selectCouponType"/>
41+
<fillField selector="{{AdminCartPriceRulesFormSection.userPerCoupon}}" userInput="{{TestSalesRuleWithInvalidData.userPerCoupon}}" stepKey="fillUsePerCoupon"/>
42+
<fillField selector="{{AdminCartPriceRulesFormSection.priority}}" userInput="{{TestSalesRuleWithInvalidData.priority}}" stepKey="fillPriority"/>
43+
44+
<click selector="{{AdminCartPriceRulesFormSection.save}}" stepKey="clickSaveButton"/>
45+
46+
<see selector="{{AdminNewCatalogPriceRule.fieldError('uses_per_coupon')}}" userInput="Please enter a valid number in this field." stepKey="seePerCouponError"/>
47+
<see selector="{{AdminNewCatalogPriceRule.fieldError('uses_per_customer')}}" userInput="Please enter a valid number in this field." stepKey="seePerCustomerError"/>
48+
<see selector="{{AdminNewCatalogPriceRule.fieldError('sort_order')}}" userInput="Please enter a valid number in this field." stepKey="seePriorityError"/>
49+
<see selector="{{AdminNewCatalogPriceRule.fieldError('discount_amount')}}" userInput="Please enter a valid number in this field." stepKey="seeDiscountAmountError"/>
50+
<see selector="{{AdminNewCatalogPriceRule.fieldError('discount_qty')}}" userInput="Please enter a valid number in this field." stepKey="seeMaximumQtyError"/>
51+
<see selector="{{AdminNewCatalogPriceRule.fieldError('discount_step')}}" userInput="Please enter a valid number in this field." stepKey="seeDiscountStepError"/>
52+
</test>
53+
</tests>

app/code/Magento/SalesRule/view/adminhtml/ui_component/sales_rule_form.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@
297297
</item>
298298
</argument>
299299
<settings>
300+
<validation>
301+
<rule name="validate-digits" xsi:type="boolean">true</rule>
302+
</validation>
300303
<dataType>text</dataType>
301304
<label translate="true">Uses per Coupon</label>
302305
<dataScope>uses_per_coupon</dataScope>
@@ -309,6 +312,9 @@
309312
</item>
310313
</argument>
311314
<settings>
315+
<validation>
316+
<rule name="validate-digits" xsi:type="boolean">true</rule>
317+
</validation>
312318
<notice translate="true">
313319
Usage limit enforced for logged in customers only.
314320
</notice>
@@ -356,6 +362,9 @@
356362
</item>
357363
</argument>
358364
<settings>
365+
<validation>
366+
<rule name="validate-digits" xsi:type="boolean">true</rule>
367+
</validation>
359368
<dataType>text</dataType>
360369
<label translate="true">Priority</label>
361370
<dataScope>sort_order</dataScope>
@@ -422,6 +431,8 @@
422431
<settings>
423432
<validation>
424433
<rule name="required-entry" xsi:type="boolean">true</rule>
434+
<rule name="validate-number" xsi:type="boolean">true</rule>
435+
<rule name="validate-zero-or-greater" xsi:type="boolean">true</rule>
425436
</validation>
426437
<dataType>text</dataType>
427438
<label translate="true">Discount Amount</label>
@@ -435,6 +446,10 @@
435446
</item>
436447
</argument>
437448
<settings>
449+
<validation>
450+
<rule name="validate-number" xsi:type="boolean">true</rule>
451+
<rule name="validate-zero-or-greater" xsi:type="boolean">true</rule>
452+
</validation>
438453
<dataType>text</dataType>
439454
<label translate="true">Maximum Qty Discount is Applied To</label>
440455
<dataScope>discount_qty</dataScope>
@@ -447,6 +462,10 @@
447462
</item>
448463
</argument>
449464
<settings>
465+
<validation>
466+
<rule name="validate-number" xsi:type="boolean">true</rule>
467+
<rule name="validate-zero-or-greater" xsi:type="boolean">true</rule>
468+
</validation>
450469
<dataType>text</dataType>
451470
<label translate="true">Discount Qty Step (Buy X)</label>
452471
<dataScope>discount_step</dataScope>

0 commit comments

Comments
 (0)