Skip to content

Commit 26f6915

Browse files
committed
MCP-584: Disable inventory check on quote load
- Add integration test;
1 parent 5dc2a5a commit 26f6915

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementWithInventoryCheckDisabledTest.php

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
use Magento\Framework\Exception\LocalizedException;
1414
use Magento\Framework\ObjectManagerInterface;
1515
use Magento\Quote\Api\CartManagementInterface;
16+
use Magento\Sales\Api\OrderRepositoryInterface;
1617
use Magento\TestFramework\Helper\Bootstrap;
1718
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
1819
use PHPUnit\Framework\TestCase;
1920

2021
class QuoteManagementWithInventoryCheckDisabledTest extends TestCase
2122
{
23+
private const PURCHASE_ORDER_NUMBER = '12345678';
24+
2225
/**
2326
* @var ObjectManagerInterface
2427
*/
@@ -37,24 +40,34 @@ class QuoteManagementWithInventoryCheckDisabledTest extends TestCase
3740
*/
3841
private $cartManagement;
3942

43+
/**
44+
* @var OrderRepositoryInterface
45+
*/
46+
private $orderRepository;
47+
4048
protected function setUp(): void
4149
{
4250
$this->objectManager = Bootstrap::getObjectManager();
4351
$this->cartManagement = $this->objectManager->get(CartManagementInterface::class);
4452
$this->getQuoteByReservedOrderId = $this->objectManager->get(GetQuoteByReservedOrderId::class);
4553
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
54+
$this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
4655
}
4756

4857
/**
58+
* Test order placement with disabled inventory check, different quantity and out of stock status.
59+
*
60+
* @param int $qty
61+
* @param int $stockStatus
62+
* @return void
4963
* @magentoDataFixture Magento/Sales/_files/quote_with_purchase_order.php
5064
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
51-
* @return void
65+
* @dataProvider getQtyAndStockStatusProvider
5266
*/
53-
public function testSaveWithZeroQuantityAndInventoryCheckDisabled()
67+
public function testPlaceOrderWithDisabledInventoryCheck(int $qty, int $stockStatus): void
5468
{
55-
$poNumber = '12345678';
5669
$quote = $this->getQuoteByReservedOrderId->execute('test_order_1');
57-
$quote->getPayment()->setPoNumber($poNumber);
70+
$quote->getPayment()->setPoNumber(self::PURCHASE_ORDER_NUMBER);
5871
$quote->collectTotals()->save();
5972

6073
/** @var ProductInterface $product */
@@ -63,30 +76,39 @@ public function testSaveWithZeroQuantityAndInventoryCheckDisabled()
6376
$this->productRepository->save($product);
6477

6578
$stockItem = $product->getExtensionAttributes()->getStockItem();
66-
$stockItem->setQty(0);
67-
$stockItem->setIsInStock(0);
79+
$stockItem->setQty($qty);
80+
$stockItem->setIsInStock($stockStatus);
6881

6982
/** @var StockItemRepositoryInterface $stockItemRepository */
7083
$stockItemRepository = $this->objectManager->get(StockItemRepositoryInterface::class);
7184
$stockItemRepository->save($stockItem);
7285

73-
$this->expectExceptionObject(
74-
new LocalizedException(__('Some of the products are out of stock.'))
75-
);
86+
$this->expectException(LocalizedException::class);
7687
$this->cartManagement->placeOrder($quote->getId());
7788
}
7889

90+
/**
91+
* @return array
92+
*/
93+
public function getQtyAndStockStatusProvider(): array
94+
{
95+
return [
96+
[0, 0],
97+
[100, 0],
98+
];
99+
}
79100

80101
/**
102+
* Test order placement with disabled inventory check, positive quantity and in stock status.
103+
*
81104
* @magentoDataFixture Magento/Sales/_files/quote_with_purchase_order.php
82105
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
83106
* @return void
84107
*/
85-
public function testSaveWithPositiveQuantityAndInventoryCheckDisabled()
108+
public function testSaveWithPositiveQuantityAndInStockWithInventoryCheckDisabled(): void
86109
{
87-
$poNumber = '12345678';
88110
$quote = $this->getQuoteByReservedOrderId->execute('test_order_1');
89-
$quote->getPayment()->setPoNumber($poNumber);
111+
$quote->getPayment()->setPoNumber(self::PURCHASE_ORDER_NUMBER);
90112
$quote->collectTotals()->save();
91113

92114
/** @var ProductInterface $product */
@@ -96,15 +118,15 @@ public function testSaveWithPositiveQuantityAndInventoryCheckDisabled()
96118

97119
$stockItem = $product->getExtensionAttributes()->getStockItem();
98120
$stockItem->setQty(100);
99-
$stockItem->setIsInStock(0);
121+
$stockItem->setIsInStock(1);
100122

101123
/** @var StockItemRepositoryInterface $stockItemRepository */
102124
$stockItemRepository = $this->objectManager->get(StockItemRepositoryInterface::class);
103125
$stockItemRepository->save($stockItem);
104126

105-
$this->expectExceptionObject(
106-
new LocalizedException(__('Some of the products are out of stock.'))
107-
);
108-
$this->cartManagement->placeOrder($quote->getId());
127+
$orderId = $this->cartManagement->placeOrder($quote->getId());;
128+
$order = $this->orderRepository->get($orderId);
129+
$orderItems = $order->getItems();
130+
$this->assertCount(1, $orderItems);
109131
}
110132
}

0 commit comments

Comments
 (0)