25
25
use Magento \SalesRule \Model \Rule ;
26
26
use PHPUnit \Framework \MockObject \MockObject ;
27
27
use PHPUnit \Framework \TestCase ;
28
-
28
+ use Magento \ SalesRule \ Model \ Quote \ ValidateCouponLengthWithQuantityInterface ;
29
29
/**
30
30
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
31
31
*/
@@ -70,6 +70,11 @@ class GenerateTest extends TestCase
70
70
/** @var CouponGenerationSpecInterfaceFactory|MockObject */
71
71
private $ couponGenerationSpec ;
72
72
73
+ /**
74
+ * @var ValidateCouponLengthWithQuantityInterface|MockObject
75
+ */
76
+ private $ validateCouponLengthWithQuantity ;
77
+
73
78
/**
74
79
* Test setup
75
80
*/
@@ -121,6 +126,11 @@ protected function setUp(): void
121
126
$ this ->couponGenerationSpec = $ this ->getMockBuilder (CouponGenerationSpecInterfaceFactory::class)
122
127
->disableOriginalConstructor ()
123
128
->getMock ();
129
+ $ this ->validateCouponLengthWithQuantity = $ this ->getMockBuilder (
130
+ ValidateCouponLengthWithQuantityInterface::class
131
+ )
132
+ ->disableOriginalConstructor ()
133
+ ->getMock ();
124
134
125
135
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
126
136
$ this ->model = $ this ->objectManagerHelper ->getObject (
@@ -131,7 +141,8 @@ protected function setUp(): void
131
141
'fileFactory ' => $ this ->fileFactoryMock ,
132
142
'dateFilter ' => $ this ->dateMock ,
133
143
'couponGenerator ' => $ this ->couponGenerator ,
134
- 'generationSpecFactory ' => $ this ->couponGenerationSpec
144
+ 'generationSpecFactory ' => $ this ->couponGenerationSpec ,
145
+ 'validateCouponLengthWithQuantity ' => $ this ->validateCouponLengthWithQuantity
135
146
]
136
147
);
137
148
}
@@ -170,14 +181,17 @@ public function testExecuteWithCouponTypeAuto()
170
181
$ ruleMock ->expects ($ this ->once ())
171
182
->method ('getCouponType ' )
172
183
->willReturn (\Magento \SalesRule \Model \Rule::COUPON_TYPE_AUTO );
173
- $ this ->requestMock ->expects ($ this ->once ( ))
184
+ $ this ->requestMock ->expects ($ this ->exactly ( 3 ))
174
185
->method ('getParams ' )
175
186
->willReturn ($ requestData );
176
187
$ requestData ['quantity ' ] = isset ($ requestData ['qty ' ]) ? $ requestData ['qty ' ] : null ;
177
188
$ this ->couponGenerationSpec ->expects ($ this ->once ())
178
189
->method ('create ' )
179
190
->with (['data ' => $ requestData ])
180
191
->willReturn (['some_data ' , 'some_data_2 ' ]);
192
+ $ this ->validateCouponLengthWithQuantity ->expects ($ this ->once ())
193
+ ->method ('validateCouponCodeLengthWithQuantity ' )
194
+ ->willReturn (10 );
181
195
$ this ->messageManager ->expects ($ this ->once ())
182
196
->method ('addSuccessMessage ' );
183
197
$ this ->responseMock ->expects ($ this ->once ())
@@ -242,7 +256,10 @@ public function testExecuteWithAutoGenerationEnabled()
242
256
$ ruleMock ->expects ($ this ->once ())
243
257
->method ('getUseAutoGeneration ' )
244
258
->willReturn (1 );
245
- $ this ->requestMock ->expects ($ this ->once ())
259
+ $ this ->validateCouponLengthWithQuantity ->expects ($ this ->once ())
260
+ ->method ('validateCouponCodeLengthWithQuantity ' )
261
+ ->willReturn (10 );
262
+ $ this ->requestMock ->expects ($ this ->exactly (3 ))
246
263
->method ('getParams ' )
247
264
->willReturn ($ requestData );
248
265
$ requestData ['quantity ' ] = isset ($ requestData ['qty ' ]) ? $ requestData ['qty ' ] : null ;
@@ -291,7 +308,7 @@ public function testExecuteWithCouponTypeNotAutoAndAutoGenerationNotEnabled()
291
308
$ this ->objectManagerMock ->expects ($ this ->any ())
292
309
->method ('get ' )
293
310
->with (Data::class)
294
- ->willReturn ($ helperData );
311
+ ->willReturn ($ helperData );
295
312
$ this ->requestMock ->expects ($ this ->once ())
296
313
->method ('isAjax ' )
297
314
->willReturn (true );
0 commit comments