6
6
7
7
namespace Magento \SalesRule \Test \Unit \Model ;
8
8
9
+ use Magento \Framework \Event \Manager ;
10
+ use Magento \Quote \Model \Quote ;
11
+ use Magento \Quote \Model \Quote \Address ;
12
+ use Magento \Quote \Model \Quote \Item ;
13
+ use Magento \Quote \Model \Quote \Item \AbstractItem ;
14
+ use Magento \Rule \Model \Action \Collection ;
15
+ use Magento \SalesRule \Model \Quote \ChildrenValidationLocator ;
16
+ use Magento \SalesRule \Model \Rule ;
17
+ use Magento \SalesRule \Model \Rule \Action \Discount \CalculatorFactory ;
18
+ use Magento \SalesRule \Model \Rule \Action \Discount \Data ;
19
+ use Magento \SalesRule \Model \Rule \Action \Discount \DiscountInterface ;
20
+ use Magento \SalesRule \Model \RulesApplier ;
21
+ use Magento \SalesRule \Model \Utility ;
22
+ use PHPUnit \Framework \TestCase ;
23
+ use PHPUnit_Framework_MockObject_MockObject ;
24
+
9
25
/**
10
26
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
11
27
*/
12
- class RulesApplierTest extends \ PHPUnit \ Framework \ TestCase
28
+ class RulesApplierTest extends TestCase
13
29
{
14
30
/**
15
- * @var \Magento\SalesRule\Model\ RulesApplier
31
+ * @var RulesApplier
16
32
*/
17
33
protected $ rulesApplier ;
18
34
19
35
/**
20
- * @var \Magento\SalesRule\Model\Rule\Action\Discount\ CalculatorFactory|\ PHPUnit_Framework_MockObject_MockObject
36
+ * @var CalculatorFactory|PHPUnit_Framework_MockObject_MockObject
21
37
*/
22
38
protected $ calculatorFactory ;
23
39
@@ -27,39 +43,39 @@ class RulesApplierTest extends \PHPUnit\Framework\TestCase
27
43
protected $ discountFactory ;
28
44
29
45
/**
30
- * @var \Magento\Framework\Event\ Manager|\ PHPUnit_Framework_MockObject_MockObject
46
+ * @var Manager|PHPUnit_Framework_MockObject_MockObject
31
47
*/
32
48
protected $ eventManager ;
33
49
34
50
/**
35
- * @var \Magento\SalesRule\Model\ Utility|\ PHPUnit_Framework_MockObject_MockObject
51
+ * @var Utility|PHPUnit_Framework_MockObject_MockObject
36
52
*/
37
53
protected $ validatorUtility ;
38
54
39
55
/**
40
- * @var \Magento\SalesRule\Model\Quote\ ChildrenValidationLocator|\ PHPUnit_Framework_MockObject_MockObject
56
+ * @var ChildrenValidationLocator|PHPUnit_Framework_MockObject_MockObject
41
57
*/
42
58
protected $ childrenValidationLocator ;
43
59
44
60
protected function setUp ()
45
61
{
46
62
$ this ->calculatorFactory = $ this ->createMock (
47
- \ Magento \ SalesRule \ Model \ Rule \ Action \ Discount \ CalculatorFactory::class
63
+ CalculatorFactory::class
48
64
);
49
65
$ this ->discountFactory = $ this ->createPartialMock (
50
66
\Magento \SalesRule \Model \Rule \Action \Discount \DataFactory::class,
51
67
['create ' ]
52
68
);
53
69
$ this ->eventManager = $ this ->createPartialMock (\Magento \Framework \Event \Manager::class, ['dispatch ' ]);
54
70
$ this ->validatorUtility = $ this ->createPartialMock (
55
- \ Magento \ SalesRule \ Model \ Utility::class,
71
+ Utility::class,
56
72
['canProcessRule ' , 'minFix ' , 'deltaRoundingFix ' , 'getItemQty ' ]
57
73
);
58
74
$ this ->childrenValidationLocator = $ this ->createPartialMock (
59
- \ Magento \ SalesRule \ Model \ Quote \ ChildrenValidationLocator::class,
75
+ ChildrenValidationLocator::class,
60
76
['isChildrenValidationRequired ' ]
61
77
);
62
- $ this ->rulesApplier = new \ Magento \ SalesRule \ Model \ RulesApplier (
78
+ $ this ->rulesApplier = new RulesApplier (
63
79
$ this ->calculatorFactory ,
64
80
$ this ->eventManager ,
65
81
$ this ->validatorUtility ,
@@ -98,19 +114,21 @@ public function testApplyRulesWhenRuleWithStopRulesProcessingIsUsed($isChildren,
98
114
->with ($ this ->anything ())
99
115
->will ($ this ->returnValue ($ discountData ));
100
116
/**
101
- * @var \Magento\SalesRule\Model\ Rule|\ PHPUnit_Framework_MockObject_MockObject $ruleWithStopFurtherProcessing
117
+ * @var Rule|PHPUnit_Framework_MockObject_MockObject $ruleWithStopFurtherProcessing
102
118
*/
103
119
$ ruleWithStopFurtherProcessing = $ this ->createPartialMock (
104
- \ Magento \ SalesRule \ Model \ Rule::class,
120
+ Rule::class,
105
121
['getStoreLabel ' , 'getCouponType ' , 'getRuleId ' , '__wakeup ' , 'getActions ' ]
106
122
);
107
- /** @var \Magento\SalesRule\Model\Rule|\PHPUnit_Framework_MockObject_MockObject $ruleThatShouldNotBeRun */
123
+ /**
124
+ * @var Rule|PHPUnit_Framework_MockObject_MockObject $ruleThatShouldNotBeRun
125
+ */
108
126
$ ruleThatShouldNotBeRun = $ this ->createPartialMock (
109
- \ Magento \ SalesRule \ Model \ Rule::class,
127
+ Rule::class,
110
128
['getStopRulesProcessing ' , '__wakeup ' ]
111
129
);
112
130
113
- $ actionMock = $ this ->createPartialMock (\ Magento \ Rule \ Model \ Action \ Collection::class, ['validate ' ]);
131
+ $ actionMock = $ this ->createPartialMock (Collection::class, ['validate ' ]);
114
132
115
133
$ ruleWithStopFurtherProcessing ->setName ('ruleWithStopFurtherProcessing ' );
116
134
$ ruleThatShouldNotBeRun ->setName ('ruleThatShouldNotBeRun ' );
@@ -163,6 +181,40 @@ public function testApplyRulesWhenRuleWithStopRulesProcessingIsUsed($isChildren,
163
181
$ this ->assertEquals ($ appliedRuleIds , $ result );
164
182
}
165
183
184
+ public function testAddCouponDescriptionWithRuleDescriptionIsUsed ()
185
+ {
186
+ $ ruleId = 1 ;
187
+ $ ruleDescription = 'Rule description ' ;
188
+
189
+ /**
190
+ * @var Rule|PHPUnit_Framework_MockObject_MockObject $rule
191
+ */
192
+ $ rule = $ this ->createPartialMock (
193
+ Rule::class,
194
+ ['getStoreLabel ' , 'getCouponType ' , 'getRuleId ' , '__wakeup ' , 'getActions ' ]
195
+ );
196
+
197
+ $ rule ->setDescription ($ ruleDescription );
198
+
199
+ /**
200
+ * @var Address|PHPUnit_Framework_MockObject_MockObject $address
201
+ */
202
+ $ address = $ this ->createPartialMock (
203
+ Address::class,
204
+ [
205
+ 'getQuote ' ,
206
+ 'setCouponCode ' ,
207
+ 'setAppliedRuleIds ' ,
208
+ '__wakeup '
209
+ ]
210
+ );
211
+ $ description = $ address ->getDiscountDescriptionArray ();
212
+ $ description [$ ruleId ] = $ rule ->getDescription ();
213
+ $ address ->setDiscountDescriptionArray ($ description [$ ruleId ]);
214
+
215
+ $ this ->assertEquals ($ address ->getDiscountDescriptionArray (), $ description [$ ruleId ]);
216
+ }
217
+
166
218
/**
167
219
* @return array
168
220
*/
@@ -175,23 +227,27 @@ public function dataProviderChildren()
175
227
}
176
228
177
229
/**
178
- * @return \Magento\Quote\Model\Quote\Item\ AbstractItem|\ PHPUnit_Framework_MockObject_MockObject
230
+ * @return AbstractItem|PHPUnit_Framework_MockObject_MockObject
179
231
*/
180
232
protected function getPreparedItem ()
181
233
{
182
- /** @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject $address */
234
+ /**
235
+ * @var Address|PHPUnit_Framework_MockObject_MockObject $address
236
+ */
183
237
$ address = $ this ->createPartialMock (
184
- \ Magento \ Quote \ Model \ Quote \ Address::class,
238
+ Address::class,
185
239
[
186
240
'getQuote ' ,
187
241
'setCouponCode ' ,
188
242
'setAppliedRuleIds ' ,
189
243
'__wakeup '
190
244
]
191
245
);
192
- /** @var \Magento\Quote\Model\Quote\Item\AbstractItem|\PHPUnit_Framework_MockObject_MockObject $item */
246
+ /**
247
+ * @var AbstractItem|PHPUnit_Framework_MockObject_MockObject $item
248
+ */
193
249
$ item = $ this ->createPartialMock (
194
- \ Magento \ Quote \ Model \ Quote \ Item::class,
250
+ Item::class,
195
251
[
196
252
'setDiscountAmount ' ,
197
253
'setBaseDiscountAmount ' ,
@@ -228,10 +284,10 @@ protected function applyRule($item, $rule)
228
284
{
229
285
$ qty = 2 ;
230
286
$ discountCalc = $ this ->createPartialMock (
231
- \ Magento \ SalesRule \ Model \ Rule \ Action \ Discount \ DiscountInterface::class,
287
+ DiscountInterface::class,
232
288
['fixQuantity ' , 'calculate ' ]
233
289
);
234
- $ discountData = $ this ->getMockBuilder (\ Magento \ SalesRule \ Model \ Rule \ Action \ Discount \ Data::class)
290
+ $ discountData = $ this ->getMockBuilder (Data::class)
235
291
->setConstructorArgs (
236
292
[
237
293
'amount ' => 30 ,
0 commit comments