77 'getShowDefaultNotificationMessage',
80 'getUseConfigMinSaleQty',
82 'getUseConfigMaxSaleQty',
84 'getUseConfigBackorders',
86 'getUseConfigNotifyStockQty',
88 'getUseConfigQtyIncrements',
90 'getUseConfigEnableQtyInc',
91 'getEnableQtyIncrements',
92 'getUseConfigManageStock',
95 'getIsDecimalDivided',
96 'getStockStatusChangedAuto',
100 'getSuppressCheckQtyIncrements',
110 $this->objectManagerHelper =
new ObjectManagerHelper($this);
112 $this->mathDivision = $this->createPartialMock(\
Magento\Framework\Math\Division::class, [
'getExactDivision']);
114 $this->localeFormat = $this->getMockForAbstractClass(
115 \
Magento\Framework\Locale\FormatInterface::class,
118 $this->localeFormat->expects($this->any())
119 ->method(
'getNumber')
120 ->willReturn($this->qty);
122 $this->
object = $this->objectManagerHelper->getObject(\
Magento\Framework\DataObject::class);
123 $this->objectFactory = $this->createPartialMock(\
Magento\Framework\DataObject\Factory::class, [
'create']);
124 $this->objectFactory->expects($this->any())->method(
'create')->willReturn($this->
object);
126 $this->product = $this->createPartialMock(
127 \
Magento\Catalog\Model\Product::class,
128 [
'load',
'isComposite',
'__wakeup',
'isSaleable']
130 $this->productFactory = $this->createPartialMock(\
Magento\Catalog\Model\ProductFactory::class, [
'create']);
131 $this->productFactory->expects($this->any())->method(
'create')->willReturn($this->product);
133 $this->stockStateProvider = $this->objectManagerHelper->getObject(
134 \
Magento\CatalogInventory\Model\StockStateProvider::class,
136 'mathDivision' => $this->mathDivision,
137 'localeFormat' => $this->localeFormat,
138 'objectFactory' => $this->objectFactory,
139 'productFactory' => $this->productFactory,
140 'qtyCheckApplicable' => $this->qtyCheckApplicable
147 $this->stockStateProvider =
null;
159 $this->stockStateProvider->verifyStock(
$stockItem)
172 $this->stockStateProvider->verifyNotification(
$stockItem)
185 $this->stockStateProvider->checkQty(
$stockItem, $this->qty)
198 $this->stockStateProvider->suggestQty(
$stockItem, $this->qty)
211 $this->stockStateProvider->getStockQty(
$stockItem)
224 $this->stockStateProvider->checkQtyIncrements(
$stockItem, $this->qty)->getHasError()
237 $this->stockStateProvider->checkQuoteItemQty(
310 $stockItem = $this->getMockBuilder(\
Magento\CatalogInventory\Api\Data\StockItemInterface::class)
311 ->disableOriginalConstructor()
312 ->setMethods($this->stockItemMethods)
313 ->getMockForAbstractClass();
314 $stockItem->expects($this->any())->method(
'getSuppressCheckQtyIncrements')->willReturn(
315 $variation[
'values'][
'_suppress_check_qty_increments_']
317 $stockItem->expects($this->any())->method(
'getIsSaleable')->willReturn(
318 $variation[
'values'][
'_is_saleable_']
320 $stockItem->expects($this->any())->method(
'getOrderedItems')->willReturn(
321 $variation[
'values'][
'_ordered_items_']
324 $stockItem->expects($this->any())->method(
'getProductName')->willReturn($variation[
'values'][
'_product_']);
325 $stockItem->expects($this->any())->method(
'getIsChildItem')->willReturn(
false);
326 $stockItem->expects($this->any())->method(
'hasStockQty')->willReturn(
false);
327 $stockItem->expects($this->any())->method(
'setStockQty')->willReturnSelf();
328 $stockItem->expects($this->any())->method(
'setOrderedItems')->willReturnSelf();
329 $stockItem->expects($this->any())->method(
'getData')
331 ->willReturn($variation[
'values'][
'_stock_qty_']);
333 foreach ($this->stockItemMethods as
$method) {
337 $expectedResult = isset($variation[
'results'][$methodName]) ? $variation[
'results'][$methodName] :
null;
340 'expectedResult' => $expectedResult,
355 'getIsInStock' =>
true,
356 'getQty' => $stockQty,
358 'getMinSaleQty' => 0,
359 'getMaxSaleQty' => 99,
360 'getNotifyStockQty' => 10,
361 'getManageStock' =>
true,
362 'getBackorders' => 1,
363 'getQtyIncrements' => 3,
364 '_stock_qty_' => $stockQty,
365 '_suppress_check_qty_increments_' =>
false,
366 '_is_saleable_' =>
true,
367 '_ordered_items_' => 0,
368 '_product_' =>
'Test product Name',
371 'verifyStock' =>
true,
372 'verifyNotification' =>
false,
375 'getStockQty' => $stockQty,
376 'checkQtyIncrements' =>
false,
377 'checkQuoteItemQty' =>
false,
382 'getIsInStock' =>
true,
383 'getQty' => $stockQty,
385 'getMinSaleQty' => 0,
386 'getMaxSaleQty' => 99,
387 'getNotifyStockQty' => 101,
388 'getManageStock' =>
true,
389 'getBackorders' => 3,
390 'getQtyIncrements' => 1,
391 '_stock_qty_' => $stockQty,
392 '_suppress_check_qty_increments_' =>
false,
393 '_is_saleable_' =>
true,
394 '_ordered_items_' => 0,
395 '_product_' =>
'Test product Name',
398 'verifyStock' =>
true,
399 'verifyNotification' =>
true,
401 'suggestQty' => 50.5,
402 'getStockQty' => $stockQty,
403 'checkQtyIncrements' =>
false,
404 'checkQuoteItemQty' =>
true,
409 'getIsInStock' =>
true,
412 'getMinSaleQty' => 1,
413 'getMaxSaleQty' => 99,
414 'getNotifyStockQty' => 101,
415 'getManageStock' =>
true,
416 'getBackorders' => 0,
417 'getQtyIncrements' => 1,
418 '_stock_qty_' =>
null,
419 '_suppress_check_qty_increments_' =>
false,
420 '_is_saleable_' =>
true,
421 '_ordered_items_' => 0,
422 '_product_' =>
'Test product Name',
425 'verifyStock' =>
false,
426 'verifyNotification' =>
true,
428 'suggestQty' => 50.5,
429 'getStockQty' =>
null,
430 'checkQtyIncrements' =>
false,
431 'checkQuoteItemQty' =>
true,
446 $stockItem = $this->getMockBuilder(\
Magento\CatalogInventory\Api\Data\StockItemInterface::class)
447 ->disableOriginalConstructor()
448 ->setMethods($this->stockItemMethods)
449 ->getMockForAbstractClass();
450 $stockItem->expects($this->any())->method(
'getSuppressCheckQtyIncrements')->willReturn(
false);
451 $stockItem->expects($this->any())->method(
'getQtyIncrements')->willReturn($qtyIncrements);
452 $stockItem->expects($this->any())->method(
'getIsChildItem')->willReturn($isChildItem);
453 $stockItem->expects($this->any())->method(
'getProductName')->willReturn(
'Simple Product');
454 $this->mathDivision->expects($this->any())->method(
'getExactDivision')->willReturn(1);
457 $this->assertTrue(
$result->getHasError());
458 $this->assertEquals($expectedMsg,
$result->getMessage()->render());
467 [
true,
'You can buy Simple Product only in quantities of 5 at a time.'],
468 [
false,
'You can buy this product only in quantities of 5 at a time.'],
testGetStockQty(StockItemInterface $stockItem, $expectedResult)
verifyNotificationDataProvider()
testVerifyNotification(StockItemInterface $stockItem, $expectedResult)
testCheckQtyIncrements(StockItemInterface $stockItem, $expectedResult)
testVerifyStock(StockItemInterface $stockItem, $expectedResult)
checkQtyIncrementsMsgDataProvider()
checkQtyIncrementsDataProvider()
testCheckQtyIncrementsMsg($isChildItem, $expectedMsg)
testSuggestQty(StockItemInterface $stockItem, $expectedResult)
testCheckQty(StockItemInterface $stockItem, $expectedResult)
checkQuoteItemQtyDataProvider()
prepareDataForMethod($methodName)
verifyStockDataProvider()
testCheckQuoteItemQty(StockItemInterface $stockItem, $expectedResult)
getStockQtyDataProvider()