13
13
use Magento \Framework \Exception \LocalizedException ;
14
14
use Magento \Framework \ObjectManagerInterface ;
15
15
use Magento \Quote \Api \CartManagementInterface ;
16
+ use Magento \Sales \Api \OrderRepositoryInterface ;
16
17
use Magento \TestFramework \Helper \Bootstrap ;
17
18
use Magento \TestFramework \Quote \Model \GetQuoteByReservedOrderId ;
18
19
use PHPUnit \Framework \TestCase ;
19
20
20
21
class QuoteManagementWithInventoryCheckDisabledTest extends TestCase
21
22
{
23
+ private const PURCHASE_ORDER_NUMBER = '12345678 ' ;
24
+
22
25
/**
23
26
* @var ObjectManagerInterface
24
27
*/
@@ -37,24 +40,34 @@ class QuoteManagementWithInventoryCheckDisabledTest extends TestCase
37
40
*/
38
41
private $ cartManagement ;
39
42
43
+ /**
44
+ * @var OrderRepositoryInterface
45
+ */
46
+ private $ orderRepository ;
47
+
40
48
protected function setUp (): void
41
49
{
42
50
$ this ->objectManager = Bootstrap::getObjectManager ();
43
51
$ this ->cartManagement = $ this ->objectManager ->get (CartManagementInterface::class);
44
52
$ this ->getQuoteByReservedOrderId = $ this ->objectManager ->get (GetQuoteByReservedOrderId::class);
45
53
$ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
54
+ $ this ->orderRepository = $ this ->objectManager ->get (OrderRepositoryInterface::class);
46
55
}
47
56
48
57
/**
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
49
63
* @magentoDataFixture Magento/Sales/_files/quote_with_purchase_order.php
50
64
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
51
- * @return void
65
+ * @dataProvider getQtyAndStockStatusProvider
52
66
*/
53
- public function testSaveWithZeroQuantityAndInventoryCheckDisabled ()
67
+ public function testPlaceOrderWithDisabledInventoryCheck ( int $ qty , int $ stockStatus ): void
54
68
{
55
- $ poNumber = '12345678 ' ;
56
69
$ quote = $ this ->getQuoteByReservedOrderId ->execute ('test_order_1 ' );
57
- $ quote ->getPayment ()->setPoNumber ($ poNumber );
70
+ $ quote ->getPayment ()->setPoNumber (self :: PURCHASE_ORDER_NUMBER );
58
71
$ quote ->collectTotals ()->save ();
59
72
60
73
/** @var ProductInterface $product */
@@ -63,30 +76,39 @@ public function testSaveWithZeroQuantityAndInventoryCheckDisabled()
63
76
$ this ->productRepository ->save ($ product );
64
77
65
78
$ stockItem = $ product ->getExtensionAttributes ()->getStockItem ();
66
- $ stockItem ->setQty (0 );
67
- $ stockItem ->setIsInStock (0 );
79
+ $ stockItem ->setQty ($ qty );
80
+ $ stockItem ->setIsInStock ($ stockStatus );
68
81
69
82
/** @var StockItemRepositoryInterface $stockItemRepository */
70
83
$ stockItemRepository = $ this ->objectManager ->get (StockItemRepositoryInterface::class);
71
84
$ stockItemRepository ->save ($ stockItem );
72
85
73
- $ this ->expectExceptionObject (
74
- new LocalizedException (__ ('Some of the products are out of stock. ' ))
75
- );
86
+ $ this ->expectException (LocalizedException::class);
76
87
$ this ->cartManagement ->placeOrder ($ quote ->getId ());
77
88
}
78
89
90
+ /**
91
+ * @return array
92
+ */
93
+ public function getQtyAndStockStatusProvider (): array
94
+ {
95
+ return [
96
+ [0 , 0 ],
97
+ [100 , 0 ],
98
+ ];
99
+ }
79
100
80
101
/**
102
+ * Test order placement with disabled inventory check, positive quantity and in stock status.
103
+ *
81
104
* @magentoDataFixture Magento/Sales/_files/quote_with_purchase_order.php
82
105
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
83
106
* @return void
84
107
*/
85
- public function testSaveWithPositiveQuantityAndInventoryCheckDisabled ()
108
+ public function testSaveWithPositiveQuantityAndInStockWithInventoryCheckDisabled (): void
86
109
{
87
- $ poNumber = '12345678 ' ;
88
110
$ quote = $ this ->getQuoteByReservedOrderId ->execute ('test_order_1 ' );
89
- $ quote ->getPayment ()->setPoNumber ($ poNumber );
111
+ $ quote ->getPayment ()->setPoNumber (self :: PURCHASE_ORDER_NUMBER );
90
112
$ quote ->collectTotals ()->save ();
91
113
92
114
/** @var ProductInterface $product */
@@ -96,15 +118,15 @@ public function testSaveWithPositiveQuantityAndInventoryCheckDisabled()
96
118
97
119
$ stockItem = $ product ->getExtensionAttributes ()->getStockItem ();
98
120
$ stockItem ->setQty (100 );
99
- $ stockItem ->setIsInStock (0 );
121
+ $ stockItem ->setIsInStock (1 );
100
122
101
123
/** @var StockItemRepositoryInterface $stockItemRepository */
102
124
$ stockItemRepository = $ this ->objectManager ->get (StockItemRepositoryInterface::class);
103
125
$ stockItemRepository ->save ($ stockItem );
104
126
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 );
109
131
}
110
132
}
0 commit comments