Ejemplo n.º 1
0
 /**
  * @dataProvider calcRowTotalDataProvider
  */
 public function testCalcRowTotal($qty)
 {
     $creditmemoMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Creditmemo')->disableOriginalConstructor()->getMock();
     $creditmemoMock->expects($this->exactly(4))->method('roundPrice')->will($this->returnCallback(function ($arg) {
         return round($arg, 2);
     }));
     $qtyInvoiced = 10;
     $qtyRefunded = 2;
     $qtyAvailable = $qtyInvoiced - $qtyRefunded;
     $rowInvoiced = 5;
     $amountRefunded = 2;
     $expectedRowTotal = ($rowInvoiced - $amountRefunded) / $qtyAvailable * $qty;
     $expectedRowTotal = round($expectedRowTotal, 2);
     $orderItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->getMock();
     $orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn($qtyInvoiced);
     $orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn($qtyRefunded);
     $orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn($rowInvoiced);
     $orderItemMock->expects($this->once())->method('getAmountRefunded')->willReturn($amountRefunded);
     $orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn($rowInvoiced);
     $orderItemMock->expects($this->once())->method('getBaseAmountRefunded')->willReturn($amountRefunded);
     $orderItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1);
     $orderItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1);
     $orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(1);
     $orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn(1);
     $orderItemMock->expects($this->any())->method('getQtyToRefund')->willReturn($qtyAvailable);
     $this->item->setData('qty', $qty);
     $this->item->setCreditmemo($creditmemoMock);
     $this->item->setOrderItem($orderItemMock);
     $result = $this->item->calcRowTotal();
     $this->assertInstanceOf('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', $result);
     $this->assertEquals($expectedRowTotal, $this->item->getData('row_total'));
     $this->assertEquals($expectedRowTotal, $this->item->getData('base_row_total'));
 }
Ejemplo n.º 2
0
 public function testCalcRowTotal()
 {
     $creditmemoMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Creditmemo')->disableOriginalConstructor()->getMock();
     $creditmemoMock->expects($this->exactly(4))->method('roundPrice')->willReturnMap([[0.375, 'regular', false, 0.4], [0.375, 'base', false, 0.4], [1, 'including', false, 1.0], [1, 'including_base', false, 1.0]]);
     $orderItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->getMock();
     $orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(10);
     $orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(2);
     $orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn(5);
     $orderItemMock->expects($this->once())->method('getAmountRefunded')->willReturn(2);
     $orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn(5);
     $orderItemMock->expects($this->once())->method('getBaseAmountRefunded')->willReturn(2);
     $orderItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1);
     $orderItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1);
     $orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(1);
     $orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn(1);
     $this->item->setData('qty', 1);
     $this->item->setCreditmemo($creditmemoMock);
     $this->item->setOrderItem($orderItemMock);
     $result = $this->item->calcRowTotal();
     $this->assertInstanceOf('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', $result);
 }