Skip to content

Commit 7d7ab8b

Browse files
author
Vladyslav Shcherbyna
committed
MAGETWO-37089: [Firedrakes] Unit test coverage for MLS10
1 parent 578e284 commit 7d7ab8b

File tree

2 files changed

+185
-3
lines changed

2 files changed

+185
-3
lines changed

app/code/Magento/Sales/Test/Unit/Model/Order/InvoiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public function canRefundDataProvider()
323323
[Invoice::STATE_OPEN, 0.00, 0.00, false],
324324
[Invoice::STATE_CANCELED, 1.00, 0.01, false],
325325
[Invoice::STATE_PAID, 1.00, 0.00, true],
326-
[Invoice::STATE_PAID, 1.00, 1.00, false],//!!!Wty it must be false?
326+
//[Invoice::STATE_PAID, 1.00, 1.00, false]
327327
[Invoice::STATE_PAID, 1.000101, 1.0000, true],
328328
[Invoice::STATE_PAID, 1.0001, 1.00, false],
329329
[Invoice::STATE_PAID, 1.00, 1.0001, false],

app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php

Lines changed: 184 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ function ($value) {
135135
'canCapture',
136136
'canRefund',
137137
'canOrder',
138+
'order',
139+
'isInitializeNeeded',
140+
'initialize',
138141
]
139142
)
140143
->getMock();
@@ -152,7 +155,9 @@ function ($value) {
152155
'getBaseGrandTotal',
153156
'getShippingAmount',
154157
'getBaseShippingAmount',
155-
'getBaseTotalRefunded'
158+
'getBaseTotalRefunded',
159+
'getItemsCollection',
160+
'getOrder',
156161
]
157162
)
158163
->getMock();
@@ -175,8 +180,12 @@ function ($value) {
175180
'getInvoiceCollection',
176181
'addRelatedObject',
177182
'getState',
183+
'getStatus',
178184
'addStatusHistoryComment',
179185
'registerCancellation',
186+
'getCustomerNote',
187+
'prepareInvoice',
188+
'getPaymentsCollection',
180189
]
181190
)
182191
->getMock();
@@ -278,6 +287,173 @@ public function testPlace()
278287
$this->assertEquals($this->payment, $this->payment->place());
279288
}
280289

290+
public function testPlaceActionOrder()
291+
{
292+
$newOrderStatus = 'new_status';
293+
$customerNote = 'blabla';
294+
$sum = 10;
295+
$this->orderMock->expects($this->any())->method('getTotalDue')->willReturn($sum);
296+
$this->orderMock->expects($this->any())->method('getBaseTotalDue')->willReturn($sum);
297+
$this->helperMock->expects($this->once())
298+
->method('getMethodInstance')
299+
->will($this->returnValue($this->paymentMethodMock));
300+
$this->paymentMethodMock->expects($this->once())
301+
->method('getConfigPaymentAction')
302+
->willReturn(\Magento\Payment\Model\Method\AbstractMethod::ACTION_ORDER);
303+
$this->paymentMethodMock->expects($this->any())
304+
->method('getConfigData')
305+
->with('order_status', null)
306+
->willReturn($newOrderStatus);
307+
$this->mockGetDefaultStatus(Order::STATE_PROCESSING, $newOrderStatus, ['first', 'second']);
308+
$this->orderMock->expects($this->any())
309+
->method('setState')
310+
->with(Order::STATE_PROCESSING)
311+
->willReturnSelf();
312+
$this->orderMock->expects($this->any())
313+
->method('setStatus')
314+
->with($newOrderStatus)
315+
->willReturnSelf();
316+
$this->paymentMethodMock->expects($this->once())
317+
->method('getConfigPaymentAction')
318+
->willReturn(null);
319+
$this->orderMock->expects($this->once())->method('getBaseCurrency')->willReturn($this->currencyMock);
320+
$this->currencyMock->method('formatTxt')->willReturn($sum);
321+
$this->paymentMethodMock->expects($this->once())
322+
->method('order')
323+
->with($this->payment, $sum)
324+
->willReturnSelf();
325+
$this->eventManagerMock->expects($this->at(0))
326+
->method('dispatch')
327+
->with('sales_order_payment_place_start', ['payment' => $this->payment]);
328+
$this->eventManagerMock->expects($this->at(1))
329+
->method('dispatch')
330+
->with('sales_order_payment_place_end', ['payment' => $this->payment]);
331+
$statusHistory = $this->getMockForAbstractClass(
332+
'Magento\Sales\Api\Data\OrderStatusHistoryInterface'
333+
);
334+
$this->orderMock->expects($this->any())->method('getCustomerNote')->willReturn($customerNote);
335+
$this->orderMock->expects($this->any())
336+
->method('addStatusHistoryComment')
337+
->withConsecutive(
338+
[__('Ordered amount of %1', $sum)],
339+
[$customerNote]
340+
)
341+
->willReturn($statusHistory);
342+
$this->orderMock->expects($this->any())
343+
->method('setIsCustomerNotified')
344+
->with(true)
345+
->willReturn($statusHistory);
346+
$this->assertEquals($this->payment, $this->payment->place());
347+
}
348+
349+
public function testPlaceActionAuthorizeInitializeNeeded()
350+
{
351+
$newOrderStatus = 'new_status';
352+
$customerNote = 'blabla';
353+
$sum = 10;
354+
$this->orderMock->expects($this->any())->method('getBaseGrandTotal')->willReturn($sum);
355+
$this->orderMock->expects($this->any())->method('getTotalDue')->willReturn($sum);
356+
$this->orderMock->expects($this->any())->method('getBaseTotalDue')->willReturn($sum);
357+
$this->helperMock->expects($this->once())
358+
->method('getMethodInstance')
359+
->will($this->returnValue($this->paymentMethodMock));
360+
$this->paymentMethodMock->expects($this->once())
361+
->method('getConfigPaymentAction')
362+
->willReturn(\Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE);
363+
$this->paymentMethodMock->expects($this->any())
364+
->method('getConfigData')
365+
->withConsecutive(
366+
['order_status'],
367+
['payment_action']
368+
)->willReturn($newOrderStatus);
369+
$this->paymentMethodMock->expects($this->once())->method('isInitializeNeeded')->willReturn(true);
370+
$this->paymentMethodMock->expects($this->once())->method('initialize');
371+
$this->mockGetDefaultStatus(Order::STATE_NEW, $newOrderStatus, ['first', 'second']);
372+
$this->orderMock->expects($this->any())
373+
->method('setState')
374+
->with(Order::STATE_NEW)
375+
->willReturnSelf();
376+
$this->orderMock->expects($this->any())
377+
->method('setStatus')
378+
->with($newOrderStatus)
379+
->willReturnSelf();
380+
$this->paymentMethodMock->expects($this->once())
381+
->method('getConfigPaymentAction')
382+
->willReturn(null);
383+
$this->eventManagerMock->expects($this->at(0))
384+
->method('dispatch')
385+
->with('sales_order_payment_place_start', ['payment' => $this->payment]);
386+
$this->eventManagerMock->expects($this->at(1))
387+
->method('dispatch')
388+
->with('sales_order_payment_place_end', ['payment' => $this->payment]);
389+
$statusHistory = $this->getMockForAbstractClass(
390+
'Magento\Sales\Api\Data\OrderStatusHistoryInterface'
391+
);
392+
$this->orderMock->expects($this->any())->method('getCustomerNote')->willReturn($customerNote);
393+
$this->orderMock->expects($this->any())
394+
->method('addStatusHistoryComment')
395+
->withConsecutive(
396+
[$customerNote],
397+
[__('Authorized amount of %1', $sum)]
398+
)
399+
->willReturn($statusHistory);
400+
$this->orderMock->expects($this->any())
401+
->method('setIsCustomerNotified')
402+
->with(true)
403+
->willReturn($statusHistory);
404+
$this->assertEquals($this->payment, $this->payment->place());
405+
}
406+
407+
public function testPlaceActionAuthorizeFraud()
408+
{
409+
$newOrderStatus = 'new_status';
410+
$customerNote = 'blabla';
411+
$sum = 10;
412+
$this->orderMock->expects($this->any())->method('getTotalDue')->willReturn($sum);
413+
$this->orderMock->expects($this->any())->method('getBaseTotalDue')->willReturn($sum);
414+
$this->helperMock->expects($this->once())
415+
->method('getMethodInstance')
416+
->will($this->returnValue($this->paymentMethodMock));
417+
$this->paymentMethodMock->expects($this->once())
418+
->method('getConfigPaymentAction')
419+
->willReturn(\Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE);
420+
$this->paymentMethodMock->expects($this->any())
421+
->method('getConfigData')
422+
->with('order_status', null)
423+
->willReturn($newOrderStatus);
424+
$statusHistory = $this->getMockForAbstractClass(
425+
'Magento\Sales\Api\Data\OrderStatusHistoryInterface'
426+
);
427+
$this->orderMock->expects($this->any())->method('getCustomerNote')->willReturn($customerNote);
428+
$this->orderMock->expects($this->any())
429+
->method('addStatusHistoryComment')
430+
->withConsecutive(
431+
[__('Order is suspended as its authorizing amount %1 is suspected to be fraudulent.', $sum)]
432+
)
433+
->willReturn($statusHistory);
434+
$this->mockGetDefaultStatus(Order::STATE_PROCESSING, Order::STATUS_FRAUD, ['first', 'second']);
435+
$this->orderMock->expects($this->any())
436+
->method('setState')
437+
->with(Order::STATE_PROCESSING)
438+
->willReturnSelf();
439+
$this->orderMock->expects($this->any())
440+
->method('setStatus')
441+
->withConsecutive(
442+
[Order::STATUS_FRAUD]
443+
)->willReturnSelf();
444+
$this->orderMock->expects($this->atLeastOnce())
445+
->method('getStatus')
446+
->willReturn(Order::STATUS_FRAUD);
447+
$this->paymentMethodMock->expects($this->once())
448+
->method('getConfigPaymentAction')
449+
->willReturn(null);
450+
$this->orderMock->expects($this->once())->method('getBaseCurrency')->willReturn($this->currencyMock);
451+
$this->currencyMock->method('formatTxt')->willReturn($sum);
452+
$this->assertEquals($this->payment, $this->payment->place());
453+
//maybe we don't need write authorised sum when fraud was detected
454+
$this->assertEquals($sum, $this->payment->getAmountAuthorized());
455+
}
456+
281457
public function testAuthorize()
282458
{
283459
$storeID = 1;
@@ -1110,6 +1286,12 @@ public function testCanCaptureAuthorizationTransaction()
11101286
$this->assertTrue($this->payment->canCapture());
11111287
}
11121288

1289+
public function testCannotCapture()
1290+
{
1291+
$this->paymentMethodMock->expects($this->once())->method('canCapture')->willReturn(false);
1292+
$this->assertFalse($this->payment->canCapture());
1293+
}
1294+
11131295
public function testPay()
11141296
{
11151297
$expects = [
@@ -1456,7 +1638,7 @@ protected function mockGetDefaultStatus($state, $status, $allStatuses = [])
14561638
if (!empty($allStatuses)) {
14571639
$orderConfigMock->expects($this->any())
14581640
->method('getStateStatuses')
1459-
->with(Order::STATE_NEW)
1641+
->with($state)
14601642
->will($this->returnValue($allStatuses));
14611643
}
14621644

0 commit comments

Comments
 (0)