/** * @param float $ratio * @dataProvider collectWithSpecifiedShippingAmountDataProvider */ public function testCollectWithSpecifiedShippingAmount($ratio) { $orderShippingAmount = 10; $orderShippingAmountRefunded = 5; $baseOrderShippingAmount = 20; $baseOrderShippingAmountRefunded = 10; $shippingTaxAmount = 2; $baseShippingTaxAmount = 4; $orderShippingInclTax = $orderShippingAmount + $shippingTaxAmount; $baseOrderShippingInclTax = $baseOrderShippingAmount + $baseShippingTaxAmount; //refund half $creditmemoBaseShippingAmount = $ratio * $baseOrderShippingAmount; $expectedShippingAmount = $orderShippingAmount * $ratio; $expectedShippingAmountInclTax = $orderShippingInclTax * $ratio; $expectedBaseShippingAmount = $baseOrderShippingAmount * $ratio; $expectedBaseShippingAmountInclTax = $baseOrderShippingInclTax * $ratio; $grandTotalBefore = 100; $baseGrandTotalBefore = 200; $expectedGrandTotal = $grandTotalBefore + $expectedShippingAmount; $expectedBaseGrandTtoal = $baseGrandTotalBefore + $expectedBaseShippingAmount; $order = new \Magento\Framework\Object(['shipping_amount' => $orderShippingAmount, 'shipping_refunded' => $orderShippingAmountRefunded, 'base_shipping_amount' => $baseOrderShippingAmount, 'base_shipping_refunded' => $baseOrderShippingAmountRefunded, 'shipping_incl_tax' => $orderShippingInclTax, 'base_shipping_incl_tax' => $baseOrderShippingInclTax]); $this->creditmemoMock->expects($this->once())->method('getOrder')->willReturn($order); $this->creditmemoMock->expects($this->once())->method('hasBaseShippingAmount')->willReturn(true); $this->creditmemoMock->expects($this->once())->method('getBaseShippingAmount')->willReturn($creditmemoBaseShippingAmount); $this->creditmemoMock->expects($this->once())->method('getGrandTotal')->willReturn($grandTotalBefore); $this->creditmemoMock->expects($this->once())->method('getBaseGrandTotal')->willReturn($baseGrandTotalBefore); //verify $this->creditmemoMock->expects($this->once())->method('setShippingAmount')->with($expectedShippingAmount)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setBaseShippingAmount')->with($expectedBaseShippingAmount)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setShippingInclTax')->with($expectedShippingAmountInclTax)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setBaseShippingInclTax')->with($expectedBaseShippingAmountInclTax)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setGrandTotal')->with($expectedGrandTotal)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setBaseGrandTotal')->with($expectedBaseGrandTtoal)->willReturnSelf(); $this->shippingCollector->collect($this->creditmemoMock); }
/** * situation: The admin user specified the desired refund amount that has taxes embedded within it * * @throws \Magento\Framework\Exception\LocalizedException */ public function testCollectUsingTaxInclShippingAmount() { $this->taxConfig->expects($this->any())->method('displaySalesShippingInclTax')->willReturn(true); $orderShippingAmount = 15; $shippingTaxAmount = 3; $orderShippingInclTax = $orderShippingAmount + $shippingTaxAmount; $orderShippingAmountRefunded = 5; $shippingTaxRefunded = 1; $refundedInclTax = $orderShippingAmountRefunded + $shippingTaxRefunded; $currencyMultiple = 2; $baseOrderShippingAmount = $orderShippingAmount * $currencyMultiple; $baseShippingTaxAmount = $shippingTaxAmount * $currencyMultiple; $baseOrderShippingInclTax = $orderShippingInclTax * $currencyMultiple; $baseOrderShippingAmountRefunded = $orderShippingAmountRefunded * $currencyMultiple; $baseShippingTaxRefunded = $shippingTaxRefunded * $currencyMultiple; $baseRefundedInclTax = $refundedInclTax * $currencyMultiple; //determine expected amounts $desiredRefundAmount = $baseOrderShippingInclTax - $baseRefundedInclTax; $expectedShippingAmount = $orderShippingAmount - $orderShippingAmountRefunded; $expectedShippingAmountInclTax = $orderShippingInclTax - $refundedInclTax; $expectedBaseShippingAmount = $expectedShippingAmount * $currencyMultiple; $expectedBaseShippingAmountInclTax = $expectedShippingAmountInclTax * $currencyMultiple; $grandTotalBefore = 100; $baseGrandTotalBefore = 200; $expectedGrandTotal = $grandTotalBefore + $expectedShippingAmount; $expectedBaseGrandTtoal = $baseGrandTotalBefore + $expectedBaseShippingAmount; $order = new \Magento\Framework\DataObject(['shipping_amount' => $orderShippingAmount, 'base_shipping_amount' => $baseOrderShippingAmount, 'shipping_refunded' => $orderShippingAmountRefunded, 'base_shipping_refunded' => $baseOrderShippingAmountRefunded, 'shipping_incl_tax' => $orderShippingInclTax, 'base_shipping_incl_tax' => $baseOrderShippingInclTax, 'shipping_tax_amount' => $shippingTaxAmount, 'shipping_tax_refunded' => $shippingTaxRefunded, 'base_shipping_tax_amount' => $baseShippingTaxAmount, 'base_shipping_tax_refunded' => $baseShippingTaxRefunded]); $this->creditmemoMock->expects($this->once())->method('getOrder')->willReturn($order); $this->creditmemoMock->expects($this->once())->method('hasBaseShippingAmount')->willReturn(true); $this->creditmemoMock->expects($this->once())->method('getBaseShippingAmount')->willReturn($desiredRefundAmount); $this->creditmemoMock->expects($this->once())->method('getGrandTotal')->willReturn($grandTotalBefore); $this->creditmemoMock->expects($this->once())->method('getBaseGrandTotal')->willReturn($baseGrandTotalBefore); //verify $this->creditmemoMock->expects($this->once())->method('setShippingAmount')->with($expectedShippingAmount)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setBaseShippingAmount')->with($expectedBaseShippingAmount)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setShippingInclTax')->with($expectedShippingAmountInclTax)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setBaseShippingInclTax')->with($expectedBaseShippingAmountInclTax)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setGrandTotal')->with($expectedGrandTotal)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setBaseGrandTotal')->with($expectedBaseGrandTtoal)->willReturnSelf(); $this->shippingCollector->collect($this->creditmemoMock); }