Skip to content

Commit 7846a3c

Browse files
committed
MCP-584: Disable inventory check on quote load
- Cover checkQty modification with unit test;
1 parent aa136f3 commit 7846a3c

File tree

2 files changed

+83
-4
lines changed

2 files changed

+83
-4
lines changed

app/code/Magento/CatalogInventory/Test/Unit/Model/Spi/StockStateProviderTest.php

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,21 @@ public function testCheckQty(StockItemInterface $stockItem, $expectedResult)
200200
);
201201
}
202202

203+
/**
204+
* Check quantity with out-of-stock status but positive or 0 quantity.
205+
*
206+
* @param StockItemInterface $stockItem
207+
* @param mixed $expectedResult
208+
* @dataProvider checkQtyWithStockStatusDataProvider
209+
*/
210+
public function testCheckQtyWithPositiveQtyAndOutOfStockstatus(StockItemInterface $stockItem, $expectedResult)
211+
{
212+
$this->assertEquals(
213+
$expectedResult,
214+
$this->stockStateProvider->checkQty($stockItem, $this->qty)
215+
);
216+
}
217+
203218
/**
204219
* @param StockItemInterface $stockItem
205220
* @param mixed $expectedResult
@@ -281,6 +296,14 @@ public function checkQtyDataProvider()
281296
return $this->prepareDataForMethod('checkQty');
282297
}
283298

299+
/**
300+
* @return array
301+
*/
302+
public function checkQtyWithStockStatusDataProvider()
303+
{
304+
return $this->prepareDataForMethod('checkQty', $this->getVariationsForQtyAndStock());
305+
}
306+
284307
/**
285308
* @return array
286309
*/
@@ -315,12 +338,16 @@ public function checkQuoteItemQtyDataProvider()
315338

316339
/**
317340
* @param $methodName
341+
* @param array|null $options
318342
* @return array
319343
*/
320-
protected function prepareDataForMethod($methodName)
344+
protected function prepareDataForMethod($methodName, array $options = null)
321345
{
322346
$variations = [];
323-
foreach ($this->getVariations() as $variation) {
347+
if ($options === null) {
348+
$options = $this->getVariations();
349+
}
350+
foreach ($options as $variation) {
324351
$stockItem = $this->getMockBuilder(StockItemInterface::class)
325352
->disableOriginalConstructor()
326353
->setMethods($this->stockItemMethods)
@@ -360,7 +387,7 @@ protected function prepareDataForMethod($methodName)
360387
/**
361388
* @return array
362389
*/
363-
protected function getVariations()
390+
private function getVariations()
364391
{
365392
$stockQty = 100;
366393
return [
@@ -448,6 +475,58 @@ protected function getVariations()
448475
];
449476
}
450477

478+
/**
479+
* @return array
480+
*/
481+
private function getVariationsForQtyAndStock()
482+
{
483+
$stockQty = 100;
484+
return [
485+
[
486+
'values' => [
487+
'getIsInStock' => false,
488+
'getQty' => $stockQty,
489+
'getMinQty' => 60,
490+
'getMinSaleQty' => 1,
491+
'getMaxSaleQty' => 99,
492+
'getNotifyStockQty' => 101,
493+
'getManageStock' => true,
494+
'getBackorders' => 0,
495+
'getQtyIncrements' => 1,
496+
'_stock_qty_' => null,
497+
'_suppress_check_qty_increments_' => false,
498+
'_is_saleable_' => true,
499+
'_ordered_items_' => 0,
500+
'_product_' => 'Test product Name',
501+
],
502+
'results' => [
503+
'checkQty' => false
504+
]
505+
],
506+
[
507+
'values' => [
508+
'getIsInStock' => false,
509+
'getQty' => 0,
510+
'getMinQty' => 60,
511+
'getMinSaleQty' => 1,
512+
'getMaxSaleQty' => 99,
513+
'getNotifyStockQty' => 101,
514+
'getManageStock' => true,
515+
'getBackorders' => 0,
516+
'getQtyIncrements' => 1,
517+
'_stock_qty_' => null,
518+
'_suppress_check_qty_increments_' => false,
519+
'_is_saleable_' => true,
520+
'_ordered_items_' => 0,
521+
'_product_' => 'Test product Name',
522+
],
523+
'results' => [
524+
'checkQty' => false
525+
]
526+
]
527+
];
528+
}
529+
451530
/**
452531
* @param bool $isChildItem
453532
* @param string $expectedMsg

app/code/Magento/CatalogInventory/Test/Unit/Model/StockManagementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function testRegisterProductsSale(
204204
public function testRegisterProductsSaleException(array $items, array $lockedItems)
205205
{
206206
$this->expectException('Magento\Framework\Exception\LocalizedException');
207-
$this->expectExceptionMessage('Not all of your products are available in the requested quantity.');
207+
$this->expectExceptionMessage('Some of the products are out of stock.');
208208
$this->stockResourceMock
209209
->expects($this->once())
210210
->method('beginTransaction');

0 commit comments

Comments
 (0)