Skip to content

Commit 3790c96

Browse files
committed
ACP2E-1053: Generate coupon codes ignores Code Length
- Added the test coverage.
1 parent 48a0ff8 commit 3790c96

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@
102102
<element name="manageCouponCodesHeader" type="button" selector="div[data-index='manage_coupon_codes']" timeout="30"/>
103103
<element name="successMessage" type="text" selector="div.message.message-success.success"/>
104104
<element name="couponQty" type="input" selector="#coupons_qty"/>
105+
<element name="couponLength" type="input" selector="#coupons_length"/>
106+
<element name="couponFormat" type="select" selector="select[name='format']"/>
105107
<element name="generateCouponsButton" type="button" selector="#coupons_generate_button" timeout="30"/>
106108
<element name="generatedCouponByIndex" type="text" selector="#couponCodesGrid_table > tbody > tr:nth-child({{var}}) > td.col-code" parameterized="true"/>
107109
<element name="generatedCouponTimesUsed" type="text" selector="#couponCodesGrid_table > tbody > tr:nth-child({{var}}) > td.col-times_used" parameterized="true"/>
108110
<element name="couponGridUsedHeader" type="text" selector="#couponCodesGrid thead th[data-sort='used']"/>
109111
<element name="fieldError" type="text" selector="//input[@name='{{fieldName}}']/following-sibling::label[@class='admin__field-error']" parameterized="true"/>
110112
<element name="modalMessage" type="text" selector="aside.modal-popup div.modal-content div"/>
113+
<element name="errorMessage" type="text" selector="div.message.message-error.error"/>
111114
</section>
112115
</sections>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminValidateCouponCodeLengthWithQuantityTest">
11+
<annotations>
12+
<stories value="Generate coupon codes ignores Code Length"/>
13+
<title value="Admin to validate coupon code length with quantity in cart price rule."/>
14+
<description value="Admin to validate coupon code length with quantity in cart price rule."/>
15+
<severity value="CRITICAL"/>
16+
<useCaseId value="ACP2E-1053"/>
17+
<testCaseId value="AC-6642"/>
18+
<group value="SalesRule"/>
19+
</annotations>
20+
<before>
21+
<!--Login to backend-->
22+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
23+
</before>
24+
<after>
25+
<actionGroup ref="AdminDeleteCartPriceRuleActionGroup" stepKey="deleteCartPriceRule">
26+
<argument name="ruleName" value="ApiSalesRule"/>
27+
</actionGroup>
28+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
29+
</after>
30+
<actionGroup ref="AdminOpenCartPriceRulesPageActionGroup" stepKey="amOnCartPriceList"/>
31+
<click selector="{{AdminCartPriceRulesSection.addNewRuleButton}}" stepKey="clickAddNewRule"/>
32+
<fillField selector="{{AdminCartPriceRulesFormSection.ruleName}}" userInput="{{ApiSalesRule.name}}" stepKey="fillRuleName"/>
33+
<selectOption selector="{{AdminCartPriceRulesFormSection.websites}}" userInput="Main Website" stepKey="selectWebsite"/>
34+
<selectOption selector="{{AdminCartPriceRulesFormSection.customerGroups}}" parameterArray="[{{'NOT LOGGED IN','General','Wholesale','Retailer'}}]" stepKey="selectSpecifiedCustomerGroups"/>
35+
<!-- Choose coupon type specific coupon and tick auto generation checkbox -->
36+
<selectOption selector="{{AdminCartPriceRulesFormSection.coupon}}" userInput="Specific Coupon" stepKey="selectCouponType"/>
37+
<checkOption selector="{{AdminCartPriceRulesFormSection.useAutoGeneration}}" stepKey="tickAutoGeneration"/>
38+
<!-- Navigate to action tab section to fill the apply and discount amount -->
39+
<conditionalClick selector="{{AdminCartPriceRulesFormSection.actionsTab}}"
40+
dependentSelector="{{AdminCartPriceRulesFormSection.actionsTab}}" visible="true"
41+
stepKey="clickActionsTab"/>
42+
<selectOption selector="{{AdminCartPriceRulesFormSection.apply}}" userInput="Percent of product price discount" stepKey="selectActionType"/>
43+
<fillField selector="{{AdminCartPriceRulesFormSection.discountAmount}}" userInput="10" stepKey="fillDiscountAmount"/>
44+
<click selector="{{AdminCartPriceRulesFormSection.saveAndContinue}}" stepKey="ClickSaveAndContinue"/>
45+
<waitForPageLoad stepKey="WaitForRuleSaved"/>
46+
<see userInput="You saved the rule." stepKey="verifyRuleSaved"/>
47+
<!-- Navigate to Manage Coupon Codes section to validate coupon code length and quantity -->
48+
<conditionalClick selector="{{AdminCartPriceRulesFormSection.manageCouponCodesHeader}}"
49+
dependentSelector="{{AdminCartPriceRulesFormSection.manageCouponCodesHeader}}" visible="true"
50+
stepKey="clickManageCouponCodes"/>
51+
<fillField selector="{{AdminCartPriceRulesFormSection.couponQty}}" userInput="2501" stepKey="fillFieldCouponQty"/>
52+
<fillField selector="{{AdminCartPriceRulesFormSection.couponLength}}" userInput="4" stepKey="fillFieldCouponLength"/>
53+
<selectOption selector="{{AdminCartPriceRulesFormSection.couponFormat}}" userInput="Numeric" stepKey="selectCouponFormat"/>
54+
<click selector="{{AdminCartPriceRulesFormSection.generateCouponsButton}}" stepKey="clickGenerateCoupon"/>
55+
<see selector="{{AdminCartPriceRulesFormSection.errorMessage}}" userInput="When coupon quantity exceeds 2501, the coupon code length must be minimum 5" stepKey="seeGenerationValidationError"/>
56+
</test>
57+
</tests>

app/code/Magento/SalesRule/Test/Unit/Controller/Adminhtml/Promo/Quote/GenerateTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use PHPUnit\Framework\MockObject\MockObject;
2727
use PHPUnit\Framework\TestCase;
2828
use Magento\SalesRule\Model\Quote\ValidateCouponLengthWithQuantityInterface;
29+
2930
/**
3031
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3132
*/

0 commit comments

Comments
 (0)