Skip to content

Commit 0e34d7c

Browse files
committed
MAGETWO-53060: Cannot refund order partially
1 parent 906dd7a commit 0e34d7c

File tree

1 file changed

+20
-96
lines changed
  • app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo

1 file changed

+20
-96
lines changed

app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/ItemTest.php

Lines changed: 20 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -92,71 +92,9 @@ public function testGetOrderItemFromFactory()
9292
$this->assertInstanceOf('Magento\Sales\Model\Order\Item', $result);
9393
}
9494

95-
/**
96-
* @expectedException \Magento\Framework\Exception\LocalizedException
97-
* @expectedExceptionMessage We found an invalid quantity to refund item "test_item_name".
98-
*/
99-
public function testSetQtyDecimalException()
100-
{
101-
$qty = 100;
102-
$orderItemQty = 10;
103-
$name = 'test_item_name';
104-
105-
$orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item')
106-
->disableOriginalConstructor()
107-
->getMock();
108-
$orderItemMock->expects($this->once())
109-
->method('getIsQtyDecimal')
110-
->willReturn(true);
111-
$orderItemMock->expects($this->once())
112-
->method('getQtyToRefund')
113-
->willReturn($orderItemQty);
114-
$this->item->setData(CreditmemoItemInterface::NAME, $name);
115-
$this->item->setOrderItem($orderItemMock);
116-
$this->item->setQty($qty);
117-
$this->item->getQty();
118-
}
119-
120-
/**
121-
* @expectedException \Magento\Framework\Exception\LocalizedException
122-
* @expectedExceptionMessage We found an invalid quantity to refund item "test_item_name2".
123-
*/
124-
public function testSetQtyNumericException()
125-
{
126-
$qty = 100;
127-
$orderItemQty = 10;
128-
$name = 'test_item_name2';
129-
130-
$orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item')
131-
->disableOriginalConstructor()
132-
->getMock();
133-
$orderItemMock->expects($this->once())
134-
->method('getIsQtyDecimal')
135-
->willReturn(false);
136-
$orderItemMock->expects($this->once())
137-
->method('getQtyToRefund')
138-
->willReturn($orderItemQty);
139-
$this->item->setData(CreditmemoItemInterface::NAME, $name);
140-
$this->item->setOrderItem($orderItemMock);
141-
$this->item->setQty($qty);
142-
$this->item->getQty();
143-
}
144-
14595
public function testSetQty()
14696
{
14797
$qty = 10;
148-
$orderItemQty = 100;
149-
150-
$orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item')
151-
->disableOriginalConstructor()
152-
->getMock();
153-
$orderItemMock->expects($this->once())
154-
->method('getIsQtyDecimal')
155-
->willReturn(false);
156-
$orderItemMock->expects($this->once())
157-
->method('getQtyToRefund')
158-
->willReturn($orderItemQty);
159-
$this->item->setOrderItem($orderItemMock);
16098
$this->item->setQty($qty);
16199
$this->assertEquals($qty, $this->item->getQty());
162100
}
@@ -210,6 +148,26 @@ public function testRegister()
210148
$this->assertInstanceOf('Magento\Sales\Model\Order\Creditmemo\Item', $result);
211149
}
212150

151+
/**
152+
* @expectedException \Magento\Framework\Exception\LocalizedException
153+
* @expectedExceptionMessage We found an invalid quantity to refund item "test".
154+
*/
155+
public function testRegisterWithException()
156+
{
157+
$orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item')
158+
->disableOriginalConstructor()
159+
->setMethods(['getQtyRefunded'])
160+
->getMock();
161+
$orderItemMock->expects($this->once())
162+
->method('getQtyRefunded')
163+
->willReturn(1);
164+
$this->item->setQty(2);
165+
$this->item->setOrderItem($orderItemMock);
166+
$this->item->setName('test');
167+
$result = $this->item->register();
168+
$this->assertInstanceOf('Magento\Sales\Model\Order\Creditmemo\Item', $result);
169+
}
170+
213171
public function testCancel()
214172
{
215173
$orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item')
@@ -336,38 +294,4 @@ public function calcRowTotalDataProvider()
336294
'qty 0' => [0],
337295
];
338296
}
339-
340-
public function testSetQtyWithProcess()
341-
{
342-
$orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item')
343-
->disableOriginalConstructor()
344-
->setMethods(['getQtyToRefund'])
345-
->getMock();
346-
$orderItemMock->expects($this->once())
347-
->method('getQtyToRefund')
348-
->willReturn(2);
349-
350-
$this->item->setOrderItem($orderItemMock);
351-
352-
$this->item->setQty(2);
353-
$this->assertEquals(2, $this->item->getQty());
354-
}
355-
356-
public function testSetQtyWithProcessDecimal()
357-
{
358-
$orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item')
359-
->disableOriginalConstructor()
360-
->setMethods(['getQtyToRefund', 'getIsQtyDecimal'])
361-
->getMock();
362-
$orderItemMock->expects($this->once())
363-
->method('getQtyToRefund')
364-
->willReturn(3.3);
365-
$orderItemMock->expects($this->once())
366-
->method('getIsQtyDecimal')
367-
->willReturn(true);
368-
$this->item->setOrderItem($orderItemMock);
369-
370-
$this->item->setQty(3.3);
371-
$this->assertEquals(3.3, $this->item->getQty());
372-
}
373297
}

0 commit comments

Comments
 (0)