@@ -405,4 +405,88 @@ public function testCollectUsingTaxInclShippingAmount()
405
405
406
406
$ this ->shippingCollector ->collect ($ this ->creditmemoMock );
407
407
}
408
+ /**
409
+ * situation: The admin user did *not* specify any desired refund amount
410
+ *
411
+ * @throws LocalizedException
412
+ */
413
+ public function testCollectRefundShippingAmountIncTax ()
414
+ {
415
+ $ orderShippingAmount = 7.2300 ;
416
+ $ orderShippingRefunded = 7.2300 ;
417
+ $ allowedShippingAmount = $ orderShippingAmount - $ orderShippingRefunded ;
418
+ $ baseOrderShippingAmount = 7.9500 ;
419
+ $ baseOrderShippingRefunded = 7.2300 ;
420
+ $ baseAllowedShippingAmount = $ baseOrderShippingAmount - $ baseOrderShippingRefunded ;
421
+ $ shippingTaxAmount = 0 ;
422
+ $ shippingTaxAmountRefunded = 7.9500 ;
423
+ $ baseShippingTaxAmount = 0 ;
424
+ $ baseShippingTaxAmountRefunded = 0.7300 ;
425
+
426
+ $ expectedShippingAmountInclTax = $ allowedShippingAmount + $ shippingTaxAmount - $ shippingTaxAmountRefunded ;
427
+ $ expectedBaseShippingAmountInclTax =
428
+ $ baseAllowedShippingAmount + $ baseShippingTaxAmount - $ baseShippingTaxAmountRefunded ;
429
+ $ grandTotalBefore = 14.35 ;
430
+ $ baseGrandTotalBefore = 14.35 ;
431
+ $ expectedGrandTotal = $ grandTotalBefore + $ allowedShippingAmount ;
432
+ $ expectedBaseGrandTotal = $ baseGrandTotalBefore + $ baseAllowedShippingAmount ;
433
+
434
+ $ this ->taxConfig ->expects ($ this ->any ())->method ('displaySalesShippingInclTax ' )->willReturn (false );
435
+
436
+ $ order = new DataObject (
437
+ [
438
+ 'shipping_amount ' => $ orderShippingAmount ,
439
+ 'shipping_refunded ' => $ orderShippingRefunded ,
440
+ 'base_shipping_amount ' => $ baseOrderShippingAmount ,
441
+ 'base_shipping_refunded ' => $ baseOrderShippingRefunded ,
442
+ 'shipping_incl_tax ' => $ orderShippingAmount + $ shippingTaxAmount ,
443
+ 'base_shipping_incl_tax ' => $ baseOrderShippingAmount + $ baseShippingTaxAmount ,
444
+ 'shipping_tax_amount ' => $ shippingTaxAmount ,
445
+ 'shipping_tax_refunded ' => $ shippingTaxAmountRefunded ,
446
+ 'base_shipping_tax_amount ' => $ baseShippingTaxAmount ,
447
+ 'base_shipping_tax_refunded ' => $ baseShippingTaxAmountRefunded ,
448
+ ]
449
+ );
450
+
451
+ $ this ->creditmemoMock ->expects ($ this ->once ())
452
+ ->method ('getOrder ' )
453
+ ->willReturn ($ order );
454
+ $ this ->creditmemoMock ->expects ($ this ->once ())
455
+ ->method ('hasBaseShippingAmount ' )
456
+ ->willReturn (false );
457
+ $ this ->creditmemoMock ->expects ($ this ->once ())
458
+ ->method ('getGrandTotal ' )
459
+ ->willReturn ($ grandTotalBefore );
460
+ $ this ->creditmemoMock ->expects ($ this ->once ())
461
+ ->method ('getBaseGrandTotal ' )
462
+ ->willReturn ($ baseGrandTotalBefore );
463
+
464
+ //verify
465
+ $ this ->creditmemoMock ->expects ($ this ->once ())
466
+ ->method ('setShippingAmount ' )
467
+ ->with ($ allowedShippingAmount )
468
+ ->willReturnSelf ();
469
+ $ this ->creditmemoMock ->expects ($ this ->once ())
470
+ ->method ('setBaseShippingAmount ' )
471
+ ->with ($ baseAllowedShippingAmount )
472
+ ->willReturnSelf ();
473
+ $ this ->creditmemoMock ->expects ($ this ->once ())
474
+ ->method ('setShippingInclTax ' )
475
+ ->with ($ expectedShippingAmountInclTax )
476
+ ->willReturnSelf ();
477
+ $ this ->creditmemoMock ->expects ($ this ->once ())
478
+ ->method ('setBaseShippingInclTax ' )
479
+ ->with ($ this ->shippingCollector ->getBaseAllowedAmountInclTax ($ expectedBaseShippingAmountInclTax ))
480
+ ->willReturnSelf ();
481
+ $ this ->creditmemoMock ->expects ($ this ->once ())
482
+ ->method ('setGrandTotal ' )
483
+ ->with ($ expectedGrandTotal )
484
+ ->willReturnSelf ();
485
+ $ this ->creditmemoMock ->expects ($ this ->once ())
486
+ ->method ('setBaseGrandTotal ' )
487
+ ->with ($ expectedBaseGrandTotal )
488
+ ->willReturnSelf ();
489
+ $ this ->assertEquals (0 , $ this ->shippingCollector ->getBaseAllowedAmountInclTax ($ expectedBaseShippingAmountInclTax ));
490
+ $ this ->shippingCollector ->collect ($ this ->creditmemoMock );
491
+ }
408
492
}
0 commit comments