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
24
40
/**
25
- * @var \Magento\Framework\Event\ Manager|\ PHPUnit_Framework_MockObject_MockObject
41
+ * @var Manager|PHPUnit_Framework_MockObject_MockObject
26
42
*/
27
43
protected $ eventManager ;
28
44
29
45
/**
30
- * @var \Magento\SalesRule\Model\ Utility|\ PHPUnit_Framework_MockObject_MockObject
46
+ * @var Utility|PHPUnit_Framework_MockObject_MockObject
31
47
*/
32
48
protected $ validatorUtility ;
33
49
34
50
/**
35
- * @var \Magento\SalesRule\Model\Quote\ ChildrenValidationLocator|\ PHPUnit_Framework_MockObject_MockObject
51
+ * @var ChildrenValidationLocator|PHPUnit_Framework_MockObject_MockObject
36
52
*/
37
53
protected $ childrenValidationLocator ;
38
54
39
55
protected function setUp ()
40
56
{
41
57
$ this ->calculatorFactory = $ this ->createMock (
42
- \ Magento \ SalesRule \ Model \ Rule \ Action \ Discount \ CalculatorFactory::class
58
+ CalculatorFactory::class
43
59
);
44
- $ this ->eventManager = $ this ->createPartialMock (\ Magento \ Framework \ Event \ Manager::class, ['dispatch ' ]);
60
+ $ this ->eventManager = $ this ->createPartialMock (Manager::class, ['dispatch ' ]);
45
61
$ this ->validatorUtility = $ this ->createPartialMock (
46
- \ Magento \ SalesRule \ Model \ Utility::class,
62
+ Utility::class,
47
63
['canProcessRule ' , 'minFix ' , 'deltaRoundingFix ' , 'getItemQty ' ]
48
64
);
49
65
$ this ->childrenValidationLocator = $ this ->createPartialMock (
50
- \ Magento \ SalesRule \ Model \ Quote \ ChildrenValidationLocator::class,
66
+ ChildrenValidationLocator::class,
51
67
['isChildrenValidationRequired ' ]
52
68
);
53
- $ this ->rulesApplier = new \ Magento \ SalesRule \ Model \ RulesApplier (
69
+ $ this ->rulesApplier = new RulesApplier (
54
70
$ this ->calculatorFactory ,
55
71
$ this ->eventManager ,
56
72
$ this ->validatorUtility ,
@@ -75,19 +91,21 @@ public function testApplyRulesWhenRuleWithStopRulesProcessingIsUsed($isChildren,
75
91
$ appliedRuleIds = [$ ruleId => $ ruleId ];
76
92
77
93
/**
78
- * @var \Magento\SalesRule\Model\ Rule|\ PHPUnit_Framework_MockObject_MockObject $ruleWithStopFurtherProcessing
94
+ * @var Rule|PHPUnit_Framework_MockObject_MockObject $ruleWithStopFurtherProcessing
79
95
*/
80
96
$ ruleWithStopFurtherProcessing = $ this ->createPartialMock (
81
- \ Magento \ SalesRule \ Model \ Rule::class,
97
+ Rule::class,
82
98
['getStoreLabel ' , 'getCouponType ' , 'getRuleId ' , '__wakeup ' , 'getActions ' ]
83
99
);
84
- /** @var \Magento\SalesRule\Model\Rule|\PHPUnit_Framework_MockObject_MockObject $ruleThatShouldNotBeRun */
100
+ /**
101
+ * @var Rule|PHPUnit_Framework_MockObject_MockObject $ruleThatShouldNotBeRun
102
+ */
85
103
$ ruleThatShouldNotBeRun = $ this ->createPartialMock (
86
- \ Magento \ SalesRule \ Model \ Rule::class,
104
+ Rule::class,
87
105
['getStopRulesProcessing ' , '__wakeup ' ]
88
106
);
89
107
90
- $ actionMock = $ this ->createPartialMock (\ Magento \ Rule \ Model \ Action \ Collection::class, ['validate ' ]);
108
+ $ actionMock = $ this ->createPartialMock (Collection::class, ['validate ' ]);
91
109
92
110
$ ruleWithStopFurtherProcessing ->setName ('ruleWithStopFurtherProcessing ' );
93
111
$ ruleThatShouldNotBeRun ->setName ('ruleThatShouldNotBeRun ' );
@@ -140,6 +158,40 @@ public function testApplyRulesWhenRuleWithStopRulesProcessingIsUsed($isChildren,
140
158
$ this ->assertEquals ($ appliedRuleIds , $ result );
141
159
}
142
160
161
+ public function testAddCouponDescriptionWithRuleDescriptionIsUsed ()
162
+ {
163
+ $ ruleId = 1 ;
164
+ $ ruleDescription = 'Rule description ' ;
165
+
166
+ /**
167
+ * @var Rule|PHPUnit_Framework_MockObject_MockObject $rule
168
+ */
169
+ $ rule = $ this ->createPartialMock (
170
+ Rule::class,
171
+ ['getStoreLabel ' , 'getCouponType ' , 'getRuleId ' , '__wakeup ' , 'getActions ' ]
172
+ );
173
+
174
+ $ rule ->setDescription ($ ruleDescription );
175
+
176
+ /**
177
+ * @var Address|PHPUnit_Framework_MockObject_MockObject $address
178
+ */
179
+ $ address = $ this ->createPartialMock (
180
+ Address::class,
181
+ [
182
+ 'getQuote ' ,
183
+ 'setCouponCode ' ,
184
+ 'setAppliedRuleIds ' ,
185
+ '__wakeup '
186
+ ]
187
+ );
188
+ $ description = $ address ->getDiscountDescriptionArray ();
189
+ $ description [$ ruleId ] = $ rule ->getDescription ();
190
+ $ address ->setDiscountDescriptionArray ($ description [$ ruleId ]);
191
+
192
+ $ this ->assertEquals ($ address ->getDiscountDescriptionArray (), $ description [$ ruleId ]);
193
+ }
194
+
143
195
/**
144
196
* @return array
145
197
*/
@@ -152,28 +204,38 @@ public function dataProviderChildren()
152
204
}
153
205
154
206
/**
155
- * @return \Magento\Quote\Model\Quote\Item\ AbstractItem|\ PHPUnit_Framework_MockObject_MockObject
207
+ * @return AbstractItem|PHPUnit_Framework_MockObject_MockObject
156
208
*/
157
209
protected function getPreparedItem ()
158
210
{
159
- /** @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject $address */
160
- $ address = $ this ->createPartialMock (\Magento \Quote \Model \Quote \Address::class, [
211
+ /**
212
+ * @var Address|PHPUnit_Framework_MockObject_MockObject $address
213
+ */
214
+ $ address = $ this ->createPartialMock (
215
+ Address::class,
216
+ [
161
217
'getQuote ' ,
162
218
'setCouponCode ' ,
163
219
'setAppliedRuleIds ' ,
164
220
'__wakeup '
165
- ]);
166
- /** @var \Magento\Quote\Model\Quote\Item\AbstractItem|\PHPUnit_Framework_MockObject_MockObject $item */
167
- $ item = $ this ->createPartialMock (\Magento \Quote \Model \Quote \Item::class, [
221
+ ]
222
+ );
223
+ /**
224
+ * @var AbstractItem|PHPUnit_Framework_MockObject_MockObject $item
225
+ */
226
+ $ item = $ this ->createPartialMock (
227
+ Item::class,
228
+ [
168
229
'setDiscountAmount ' ,
169
230
'setBaseDiscountAmount ' ,
170
231
'setDiscountPercent ' ,
171
232
'getAddress ' ,
172
233
'setAppliedRuleIds ' ,
173
234
'__wakeup ' ,
174
235
'getChildren '
175
- ]);
176
- $ quote = $ this ->createPartialMock (\Magento \Quote \Model \Quote::class, ['getStore ' , '__wakeUp ' ]);
236
+ ]
237
+ );
238
+ $ quote = $ this ->createPartialMock (Quote::class, ['getStore ' , '__wakeUp ' ]);
177
239
$ item ->expects ($ this ->any ())->method ('getAddress ' )->will ($ this ->returnValue ($ address ));
178
240
$ address ->expects ($ this ->any ())
179
241
->method ('getQuote ' )
@@ -190,10 +252,10 @@ protected function applyRule($item, $rule)
190
252
{
191
253
$ qty = 2 ;
192
254
$ discountCalc = $ this ->createPartialMock (
193
- \ Magento \ SalesRule \ Model \ Rule \ Action \ Discount \ DiscountInterface::class,
255
+ DiscountInterface::class,
194
256
['fixQuantity ' , 'calculate ' ]
195
257
);
196
- $ discountData = $ this ->getMockBuilder (\ Magento \ SalesRule \ Model \ Rule \ Action \ Discount \ Data::class)
258
+ $ discountData = $ this ->getMockBuilder (Data::class)
197
259
->setConstructorArgs (
198
260
[
199
261
'amount ' => 30 ,
0 commit comments