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