@@ -200,6 +200,21 @@ public function testCheckQty(StockItemInterface $stockItem, $expectedResult)
200
200
);
201
201
}
202
202
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
+
203
218
/**
204
219
* @param StockItemInterface $stockItem
205
220
* @param mixed $expectedResult
@@ -281,6 +296,14 @@ public function checkQtyDataProvider()
281
296
return $ this ->prepareDataForMethod ('checkQty ' );
282
297
}
283
298
299
+ /**
300
+ * @return array
301
+ */
302
+ public function checkQtyWithStockStatusDataProvider ()
303
+ {
304
+ return $ this ->prepareDataForMethod ('checkQty ' , $ this ->getVariationsForQtyAndStock ());
305
+ }
306
+
284
307
/**
285
308
* @return array
286
309
*/
@@ -315,12 +338,16 @@ public function checkQuoteItemQtyDataProvider()
315
338
316
339
/**
317
340
* @param $methodName
341
+ * @param array|null $options
318
342
* @return array
319
343
*/
320
- protected function prepareDataForMethod ($ methodName )
344
+ protected function prepareDataForMethod ($ methodName, array $ options = null )
321
345
{
322
346
$ variations = [];
323
- foreach ($ this ->getVariations () as $ variation ) {
347
+ if ($ options === null ) {
348
+ $ options = $ this ->getVariations ();
349
+ }
350
+ foreach ($ options as $ variation ) {
324
351
$ stockItem = $ this ->getMockBuilder (StockItemInterface::class)
325
352
->disableOriginalConstructor ()
326
353
->setMethods ($ this ->stockItemMethods )
@@ -360,7 +387,7 @@ protected function prepareDataForMethod($methodName)
360
387
/**
361
388
* @return array
362
389
*/
363
- protected function getVariations ()
390
+ private function getVariations ()
364
391
{
365
392
$ stockQty = 100 ;
366
393
return [
@@ -448,6 +475,58 @@ protected function getVariations()
448
475
];
449
476
}
450
477
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
+
451
530
/**
452
531
* @param bool $isChildItem
453
532
* @param string $expectedMsg
0 commit comments