@@ -343,20 +343,74 @@ public function testRefundExpectsMoneyAvailableToReturn()
343
343
->willReturn ($ order );
344
344
$ creditMemo ->method ('getBaseGrandTotal ' )
345
345
->willReturn ($ baseGrandTotal );
346
+ $ creditMemo ->method ('getGrandTotal ' )
347
+ ->willReturn ($ baseGrandTotal );
346
348
$ order ->method ('getBaseTotalRefunded ' )
347
349
->willReturn ($ baseTotalRefunded );
350
+ $ order ->method ('getTotalRefunded ' )
351
+ ->willReturn ($ baseTotalRefunded );
348
352
$ this ->priceCurrency ->method ('round ' )
349
353
->withConsecutive ([$ baseTotalRefunded + $ baseGrandTotal ], [$ baseTotalPaid ])
350
354
->willReturnOnConsecutiveCalls ($ baseTotalRefunded + $ baseGrandTotal , $ baseTotalPaid );
351
355
$ order ->method ('getBaseTotalPaid ' )
352
356
->willReturn ($ baseTotalPaid );
357
+ $ order ->method ('getTotalPaid ' )
358
+ ->willReturn ($ baseTotalPaid );
353
359
$ baseAvailableRefund = $ baseTotalPaid - $ baseTotalRefunded ;
354
360
$ order ->method ('formatPriceTxt ' )
355
361
->with ($ baseAvailableRefund )
356
362
->willReturn ($ baseAvailableRefund );
357
363
$ this ->creditmemoService ->refund ($ creditMemo , true );
358
364
}
359
365
366
+ /**
367
+ * @expectedExceptionMessage The most money available to refund is €0.88.
368
+ * @expectedException \Magento\Framework\Exception\LocalizedException
369
+ */
370
+ public function testMultiCurrencyRefundExpectsMoneyAvailableToReturn ()
371
+ {
372
+ $ baseGrandTotal = 10.00 ;
373
+ $ baseTotalRefunded = 9.00 ;
374
+ $ baseTotalPaid = 10 ;
375
+
376
+ $ grandTotal = 8.81 ;
377
+ $ totalRefunded = 7.929 ;
378
+ $ totalPaid = 8.81 ;
379
+
380
+ /** @var CreditmemoInterface|MockObject $creditMemo */
381
+ $ creditMemo = $ this ->getMockBuilder (CreditmemoInterface::class)
382
+ ->setMethods (['getId ' , 'getOrder ' ])
383
+ ->getMockForAbstractClass ();
384
+ $ creditMemo ->method ('getId ' )
385
+ ->willReturn (null );
386
+ /** @var Order|MockObject $order */
387
+ $ order = $ this ->getMockBuilder (Order::class)
388
+ ->disableOriginalConstructor ()
389
+ ->getMock ();
390
+ $ creditMemo ->method ('getOrder ' )
391
+ ->willReturn ($ order );
392
+ $ creditMemo ->method ('getBaseGrandTotal ' )
393
+ ->willReturn ($ baseGrandTotal );
394
+ $ creditMemo ->method ('getGrandTotal ' )
395
+ ->willReturn ($ grandTotal );
396
+ $ order ->method ('getBaseTotalRefunded ' )
397
+ ->willReturn ($ baseTotalRefunded );
398
+ $ order ->method ('getTotalRefunded ' )
399
+ ->willReturn ($ totalRefunded );
400
+ $ this ->priceCurrency ->method ('round ' )
401
+ ->withConsecutive ([$ baseTotalRefunded + $ baseGrandTotal ], [$ baseTotalPaid ])
402
+ ->willReturnOnConsecutiveCalls ($ baseTotalRefunded + $ baseGrandTotal , $ baseTotalPaid );
403
+ $ order ->method ('getBaseTotalPaid ' )
404
+ ->willReturn ($ baseTotalPaid );
405
+ $ order ->method ('getTotalPaid ' )
406
+ ->willReturn ($ totalPaid );
407
+ $ availableRefund = $ totalPaid - $ totalRefunded ;
408
+ $ order ->method ('formatPriceTxt ' )
409
+ ->with ($ availableRefund )
410
+ ->willReturn (sprintf ('€%.2f ' , $ availableRefund ));
411
+ $ this ->creditmemoService ->refund ($ creditMemo , true );
412
+ }
413
+
360
414
/**
361
415
* @expectedExceptionMessage We cannot register an existing credit memo.
362
416
* @expectedException \Magento\Framework\Exception\LocalizedException
0 commit comments