@@ -351,7 +351,7 @@ public function testRefundExpectsMoneyAvailableToReturn()
351
351
$order->method('getBaseTotalPaid')
352
352
->willReturn($baseTotalPaid);
353
353
$baseAvailableRefund = $baseTotalPaid - $baseTotalRefunded;
354
- $order->method('formatPriceTxt ')
354
+ $order->method('formatBasePriceTxt ')
355
355
->with($baseAvailableRefund)
356
356
->willReturn($baseAvailableRefund);
357
357
$this->creditmemoService->refund($creditMemo, true);
@@ -369,4 +369,51 @@ public function testRefundDoNotExpectsId()
369
369
$creditMemoMock->expects($this->once())->method('getId')->willReturn(444);
370
370
$this->creditmemoService->refund($creditMemoMock, true);
371
371
}
372
+
373
+ /**
374
+ * @expectedExceptionMessage The most money available to refund is $1.00.
375
+ * @expectedException \Magento\Framework\Exception\LocalizedException
376
+ */
377
+ public function testMultiCurrencyRefundExpectsMoneyAvailableToReturn()
378
+ {
379
+ $baseGrandTotal = 10.00;
380
+ $baseTotalRefunded = 9.00;
381
+ $baseTotalPaid = 10;
382
+ $grandTotal = 8.81;
383
+ $totalRefunded = 7.929;
384
+ $totalPaid = 8.81;
385
+
386
+ /** @var CreditmemoInterface|MockObject $creditMemo */
387
+ $creditMemo = $this->getMockBuilder(CreditmemoInterface::class)
388
+ ->setMethods(['getId', 'getOrder'])
389
+ ->getMockForAbstractClass();
390
+ $creditMemo->method('getId')
391
+ ->willReturn(null);
392
+ /** @var Order|MockObject $order */
393
+ $order = $this->getMockBuilder(Order::class)
394
+ ->disableOriginalConstructor()
395
+ ->getMock();
396
+ $creditMemo->method('getOrder')
397
+ ->willReturn($order);
398
+ $creditMemo->method('getBaseGrandTotal')
399
+ ->willReturn($baseGrandTotal);
400
+ $creditMemo->method('getGrandTotal')
401
+ ->willReturn($grandTotal);
402
+ $order->method('getBaseTotalRefunded')
403
+ ->willReturn($baseTotalRefunded);
404
+ $order->method('getTotalRefunded')
405
+ ->willReturn($totalRefunded);
406
+ $this->priceCurrency->method('round')
407
+ ->withConsecutive([$baseTotalRefunded + $baseGrandTotal], [$baseTotalPaid])
408
+ ->willReturnOnConsecutiveCalls($baseTotalRefunded + $baseGrandTotal, $baseTotalPaid);
409
+ $order->method('getBaseTotalPaid')
410
+ ->willReturn($baseTotalPaid);
411
+ $order->method('getTotalPaid')
412
+ ->willReturn($totalPaid);
413
+ $baseAvailableRefund = $baseTotalPaid - $baseTotalRefunded;
414
+ $order->method('formatBasePriceTxt')
415
+ ->with($baseAvailableRefund)
416
+ ->willReturn(sprintf('$%.2f', $baseAvailableRefund));
417
+ $this->creditmemoService->refund($creditMemo, true);
418
+ }
372
419
}
0 commit comments