Skip to content

Commit 4969bbb

Browse files
committed
ACP2E-2756: [Cloud] Order Status changed to complete when partially refund of a partially shipped order
- added unit test
1 parent a30f6ab commit 4969bbb

File tree

2 files changed

+29
-3
lines changed
  • app/code/Magento/Sales

2 files changed

+29
-3
lines changed

app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function check(Order $order)
5959
*/
6060
public function isPartiallyRefundedOrderShipped(Order $order): bool
6161
{
62-
//we should also check the number of items that require shipping
6362
$isPartiallyRefundedOrderShipped = false;
6463
if ($this->getShippedItems($order) > 0
6564
&& $order->getTotalQtyOrdered() <= $this->getRefundedItems($order) + $this->getShippedItems($order)) {

app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/StateTest.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Sales\Model\Order;
1111
use Magento\Sales\Model\Order\Address;
12+
use Magento\Sales\Model\Order\Item;
1213
use Magento\Sales\Model\ResourceModel\Order\Address\Collection;
1314
use Magento\Sales\Model\ResourceModel\Order\Handler\State;
1415
use PHPUnit\Framework\MockObject\MockObject;
@@ -45,7 +46,8 @@ protected function setUp(): void
4546
'getIsVirtual',
4647
'getIsNotVirtual',
4748
'getStatus',
48-
'getAllItems'
49+
'getAllItems',
50+
'getTotalQtyOrdered'
4951
]
5052
)
5153
->disableOriginalConstructor()
@@ -105,14 +107,25 @@ public function testCheck(
105107
->willReturn($isInProcess);
106108
$this->orderMock->method('getIsNotVirtual')
107109
->willReturn($isNotVirtual);
110+
$shippedItem = $this->createMock(Item::class);
111+
$shippedItem->expects($this->any())->method('getQtyShipped')->willReturn(1);
112+
$shippedItem->expects($this->any())->method('getQtyRefunded')->willReturn(1);
113+
$shippedItem->expects($this->any())->method('getProductType')->willReturn('simple');
114+
$shippedItem->expects($this->any())->method('canShip')->willReturn(false);
115+
$shippableItem = $this->createMock(Item::class);
116+
$shippableItem->expects($this->any())->method('getQtyShipped')->willReturn(0);
117+
$shippableItem->expects($this->any())->method('getQtyRefunded')->willReturn(0);
118+
$shippableItem->expects($this->any())->method('getProductType')->willReturn('simple');
119+
$shippableItem->expects($this->any())->method('canShip')->willReturn(true);
108120
$this->orderMock->method('getAllItems')
109-
->willReturn([]);
121+
->willReturn([$shippedItem, $shippableItem]);
110122
if (!$isNotVirtual) {
111123
$this->orderMock->method('getIsVirtual')
112124
->willReturn(!$isNotVirtual);
113125
$this->orderMock->method('getStatus')
114126
->willReturn($expectedState);
115127
}
128+
$this->orderMock->expects($this->any())->method('getTotalQtyOrdered')->willReturn(2);
116129
$this->state->check($this->orderMock);
117130
$this->assertEquals($expectedState, $this->orderMock->getState());
118131
}
@@ -126,6 +139,20 @@ public function testCheck(
126139
public function stateCheckDataProvider()
127140
{
128141
return [
142+
'processing - partiallyRefundedOrderShipped = true, hasPendingShipmentItems = true -> processing' => [
143+
'can_credit_memo' => false,
144+
'can_credit_memo_invoke_count' => 1,
145+
'can_ship' => true,
146+
'call_can_skip_num' => 2,
147+
'current_state' => Order::STATE_PROCESSING,
148+
'expected_state' => Order::STATE_PROCESSING,
149+
'is_in_process' => false,
150+
'get_is_in_process_invoke_count' => 0,
151+
'is_canceled' => false,
152+
'can_unhold' => false,
153+
'is_not_virtual' => true,
154+
'isPartiallyRefundedOrderShipped' => false
155+
],
129156
'processing - !canCreditmemo!canShip -> closed' => [
130157
'can_credit_memo' => false,
131158
'can_credit_memo_invoke_count' => 1,

0 commit comments

Comments
 (0)