Skip to content

Commit 001543f

Browse files
committed
AC-1479: Incorrect qty to ship after few creditmemos
Added integration test coverage
1 parent cf5dbc6 commit 001543f

File tree

1 file changed

+94
-3
lines changed
  • dev/tests/integration/testsuite/Magento/Sales/Model/Order

1 file changed

+94
-3
lines changed

dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemTest.php

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2017 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Sales\Model\Order;
79

8-
class ItemTest extends \PHPUnit\Framework\TestCase
10+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
11+
use Magento\Catalog\Test\Fixture\ProductStock as ProductStockFixture;
12+
use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture;
13+
use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture;
14+
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
15+
use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture;
16+
use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddressFixture;
17+
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
18+
use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
19+
use Magento\Sales\Model\Order;
20+
use Magento\Sales\Test\Fixture\Creditmemo as CreditmemoFixture;
21+
use Magento\Sales\Test\Fixture\Invoice as InvoiceFixture;
22+
use Magento\Sales\Test\Fixture\Shipment as ShipmentFixture;
23+
use Magento\TestFramework\Fixture\DataFixture;
24+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
25+
use PHPUnit\Framework\TestCase;
26+
27+
/**
28+
* Test for the Order Item model
29+
*
30+
* @suppressWarnings(PHPMD.CouplingBetweenObjects)
31+
*/
32+
class ItemTest extends TestCase
933
{
1034
/**
1135
* @param string $options
@@ -35,4 +59,71 @@ public static function getProductOptionsDataProvider()
3559
],
3660
];
3761
}
62+
63+
/**
64+
* Test getSimpleQtyToShip method
65+
*
66+
* @magentoDbIsolation disabled
67+
* @magentoAppArea adminhtml
68+
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 0
69+
*/
70+
#[
71+
DataFixture(ProductFixture::class, as: 'product'),
72+
DataFixture(ProductStockFixture::class, ['prod_id' => '$product.id$', 'prod_qty' => 100, 'is_in_stock' => 1]),
73+
DataFixture(GuestCartFixture::class, as: 'cart'),
74+
DataFixture(
75+
AddProductToCartFixture::class,
76+
['cart_id' => '$cart.id$', 'product_id' => '$product.id$', 'qty' => 10]
77+
),
78+
DataFixture(
79+
SetBillingAddressFixture::class,
80+
['cart_id' => '$cart.id$', 'address' => ['email' => 'guest@example.com']]
81+
),
82+
DataFixture(
83+
SetShippingAddressFixture::class,
84+
['cart_id' => '$cart.id$', 'address' => ['email' => 'guest@example.com']]
85+
),
86+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$cart.id$']),
87+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$cart.id$']),
88+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$cart.id$'], 'order'),
89+
DataFixture(InvoiceFixture::class, ['order_id' => '$order.id$'], 'invoice'),
90+
DataFixture(
91+
ShipmentFixture::class,
92+
['order_id' => '$order.id$', 'items' => [['product_id' => '$product.id$', 'qty' => 1]]]
93+
),
94+
DataFixture(
95+
CreditmemoFixture::class,
96+
['order_id' => '$order.id$', 'items' => [['product_id' => '$product.id$', 'qty' => 2]]]
97+
),
98+
DataFixture(
99+
ShipmentFixture::class,
100+
['order_id' => '$order.id$', 'items' => [['product_id' => '$product.id$', 'qty' => 1]]]
101+
),
102+
DataFixture(
103+
CreditmemoFixture::class,
104+
['order_id' => '$order.id$', 'items' => [['product_id' => '$product.id$', 'qty' => 2]]]
105+
)
106+
]
107+
public function testGetSimpleQtyToShip()
108+
{
109+
$fixtures = DataFixtureStorageManager::getStorage();
110+
111+
/** @var Order $order */
112+
$order = $fixtures->get('order');
113+
114+
// Get order item
115+
$orderItems = $order->getItems();
116+
/** @var Item $orderItem */
117+
$orderItem = reset($orderItems);
118+
119+
// Verify quantities
120+
$this->assertEquals(10, $orderItem->getQtyOrdered(), 'Qty ordered should be 10');
121+
$this->assertEquals(10, $orderItem->getQtyInvoiced(), 'Qty invoiced should be 10');
122+
$this->assertEquals(2, $orderItem->getQtyShipped(), 'Qty shipped should be 2');
123+
$this->assertEquals(4, $orderItem->getQtyRefunded(), 'Qty refunded should be 4');
124+
125+
// Assert getSimpleQtyToShip value
126+
// Qty to ship = Qty ordered (10) - Qty shipped (2) - Qty refunded (4) = 4
127+
$this->assertEquals(4, $orderItem->getSimpleQtyToShip(), 'Simple qty to ship should be 3');
128+
}
38129
}

0 commit comments

Comments
 (0)