8
8
namespace Magento \Sales \Test \Unit \Model \Order \Creditmemo \Validation ;
9
9
10
10
use Magento \Framework \Pricing \PriceCurrencyInterface ;
11
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
12
+ use Magento \Sales \Model \Order \Creditmemo ;
11
13
use Magento \Sales \Api \Data \CreditmemoInterface ;
12
14
use Magento \Sales \Api \Data \CreditmemoItemInterface ;
13
15
use Magento \Sales \Api \Data \OrderInterface ;
14
16
use Magento \Sales \Api \InvoiceRepositoryInterface ;
15
17
use Magento \Sales \Api \OrderRepositoryInterface ;
16
18
use Magento \Sales \Model \Order \Creditmemo \Validation \QuantityValidator ;
17
19
use Magento \Sales \Model \Order \Item ;
20
+ use Magento \Store \Api \Data \StoreConfigInterface ;
18
21
use PHPUnit \Framework \MockObject \MockObject ;
19
22
use PHPUnit \Framework \TestCase ;
20
23
@@ -154,6 +157,30 @@ public function testValidateWithWrongItemId()
154
157
);
155
158
}
156
159
160
+ private function getCreditMemoMockParams ()
161
+ {
162
+ return [
163
+ $ this ->createMock (\Magento \Framework \Model \Context::class),
164
+ $ this ->createMock (\Magento \Framework \Registry::class),
165
+ $ this ->createMock (\Magento \Framework \Api \ExtensionAttributesFactory::class),
166
+ $ this ->createMock (\Magento \Framework \Api \AttributeValueFactory::class),
167
+ $ this ->createMock (\Magento \Sales \Model \Order \Creditmemo \Config::class),
168
+ $ this ->createMock (\Magento \Sales \Model \OrderFactory::class),
169
+ $ this ->createMock (\Magento \Sales \Model \ResourceModel \Order \Creditmemo \Item \CollectionFactory::class),
170
+ $ this ->createMock (\Magento \Framework \Math \CalculatorFactory::class),
171
+ $ this ->createMock (\Magento \Store \Model \StoreManagerInterface::class),
172
+ $ this ->createMock ( \Magento \Sales \Model \Order \Creditmemo \CommentFactory::class),
173
+ $ this ->createMock (\Magento \Sales \Model \ResourceModel \Order \Creditmemo \Comment \CollectionFactory::class),
174
+ $ this ->createMock (\Magento \Framework \Pricing \PriceCurrencyInterface::class),
175
+ $ this ->createMock (\Magento \Framework \Model \ResourceModel \AbstractResource::class),
176
+ $ this ->createMock (\Magento \Framework \Data \Collection \AbstractDb::class),
177
+ [],
178
+ $ this ->createMock (\Magento \Sales \Model \Order \InvoiceFactory::class),
179
+ $ this ->createMock (ScopeConfigInterface::class),
180
+ $ this ->createMock (\Magento \Sales \Api \OrderRepositoryInterface::class)
181
+ ];
182
+ }
183
+
157
184
/**
158
185
* @param int $orderId
159
186
* @param int $orderItemId
@@ -163,6 +190,7 @@ public function testValidateWithWrongItemId()
163
190
* @param int $total
164
191
* @param array $expected
165
192
* @param bool $isQtyDecimalAllowed
193
+ * @param bool $isAllowZeroGrandTotal
166
194
* @dataProvider dataProviderForValidateQty
167
195
*/
168
196
public function testValidate (
@@ -174,16 +202,23 @@ public function testValidate(
174
202
$ total ,
175
203
array $ expected ,
176
204
bool $ isQtyDecimalAllowed ,
177
- bool $ isValidGrandTotal
205
+ bool $ isAllowZeroGrandTotal
178
206
) {
179
- $ creditmemoMock = $ this ->getMockBuilder (CreditmemoInterface::class)
180
- ->disableOriginalConstructor ()
181
- ->addMethods (['isValidGrandTotal ' ])
207
+ $ scopeConfig = $ this ->getMockForAbstractClass (ScopeConfigInterface::class);
208
+ $ scopeConfig ->expects ($ this ->any ())->method ('getValue ' )->willReturn ($ isAllowZeroGrandTotal );
209
+ $ creditMemoConstructorParams = $ this ->getCreditMemoMockParams ();
210
+ $ creditMemoConstructorParams [16 ] = $ scopeConfig ;
211
+
212
+ $ creditmemoMock = $ this ->getMockBuilder (Creditmemo::class)
213
+ ->setConstructorArgs ($ creditMemoConstructorParams )
214
+ ->onlyMethods (['getOrderId ' , 'getItems ' , 'getGrandTotal ' , '_construct ' ])
182
215
->getMockForAbstractClass ();
216
+
183
217
$ creditmemoMock ->expects ($ this ->exactly (2 ))->method ('getOrderId ' )
184
218
->willReturn ($ orderId );
185
- $ creditmemoMock ->expects ($ this ->once ())->method ('isValidGrandTotal ' )
186
- ->willReturn ($ isValidGrandTotal );
219
+ $ creditmemoMock ->expects ($ this ->once ())->method ('getGrandTotal ' )
220
+ ->willReturn ($ total );
221
+
187
222
$ creditmemoItemMock = $ this ->getMockBuilder (
188
223
CreditmemoItemInterface::class
189
224
)->disableOriginalConstructor ()
@@ -244,7 +279,7 @@ public function dataProviderForValidateQty()
244
279
'total ' => 15 ,
245
280
'expected ' => [],
246
281
'isQtyDecimalAllowed ' => false ,
247
- 'isValidGrandTotal ' => true
282
+ 'isAllowZeroGrandTotal ' => true
248
283
],
249
284
[
250
285
'orderId ' => 1 ,
@@ -255,7 +290,7 @@ public function dataProviderForValidateQty()
255
290
'total ' => 15 ,
256
291
'expected ' => [],
257
292
'isQtyDecimalAllowed ' => false ,
258
- 'isValidGrandTotal ' => true
293
+ 'isAllowZeroGrandTotal ' => true
259
294
],
260
295
[
261
296
'orderId ' => 1 ,
@@ -271,7 +306,7 @@ public function dataProviderForValidateQty()
271
306
)
272
307
],
273
308
'isQtyDecimalAllowed ' => false ,
274
- 'isValidGrandTotal ' => true
309
+ 'isAllowZeroGrandTotal ' => true
275
310
],
276
311
[
277
312
'orderId ' => 1 ,
@@ -300,7 +335,7 @@ public function dataProviderForValidateQty()
300
335
'total ' => 0 ,
301
336
'expected ' => [],
302
337
'isQtyDecimalAllowed ' => false ,
303
- 'isValidGrandTotal ' => true
338
+ 'isAllowZeroGrandTotal ' => true
304
339
]
305
340
];
306
341
}
0 commit comments