NegativeMinQtyTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryCatalog\Test\Integration;
  8. use Magento\InventoryConfigurationApi\Api\Data\StockItemConfigurationInterface;
  9. use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface;
  10. use Magento\InventoryConfigurationApi\Api\SaveStockItemConfigurationInterface;
  11. use Magento\InventorySalesApi\Api\IsProductSalableForRequestedQtyInterface;
  12. use Magento\TestFramework\Helper\Bootstrap;
  13. use PHPUnit\Framework\TestCase;
  14. class NegativeMinQtyTest extends TestCase
  15. {
  16. /**
  17. * @var IsProductSalableForRequestedQtyInterface
  18. */
  19. private $isProductSalableForRequestedQty;
  20. /**
  21. * @var GetStockItemConfigurationInterface
  22. */
  23. private $getStockItemConfiguration;
  24. /**
  25. * @var SaveStockItemConfigurationInterface
  26. */
  27. private $saveStockItemConfiguration;
  28. /**
  29. * @inheritdoc
  30. */
  31. protected function setUp()
  32. {
  33. parent::setUp();
  34. $this->isProductSalableForRequestedQty = Bootstrap::getObjectManager()->get(
  35. IsProductSalableForRequestedQtyInterface::class
  36. );
  37. $this->getStockItemConfiguration = Bootstrap::getObjectManager()->get(
  38. GetStockItemConfigurationInterface::class
  39. );
  40. $this->saveStockItemConfiguration = Bootstrap::getObjectManager()->get(
  41. SaveStockItemConfigurationInterface::class
  42. );
  43. }
  44. /**
  45. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  46. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  47. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
  48. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
  49. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  50. * @dataProvider isProductSalableForRequestedQtyWithBackordersEnabledAtProductLevelDataProvider
  51. *
  52. * @magentoDbIsolation disabled
  53. */
  54. public function testIsProductSalableForRequestedQtyWithBackordersEnabledAtProductLevel(
  55. $sku,
  56. $stockId,
  57. $minQty,
  58. $requestedQty,
  59. $expectedSalability
  60. ) {
  61. $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
  62. $stockItemConfiguration->setUseConfigBackorders(false);
  63. $stockItemConfiguration->setBackorders(StockItemConfigurationInterface::BACKORDERS_YES_NONOTIFY);
  64. $stockItemConfiguration->setUseConfigMinQty(false);
  65. $stockItemConfiguration->setMinQty($minQty);
  66. $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration);
  67. $this->assertEquals(
  68. $expectedSalability,
  69. $this->isProductSalableForRequestedQty->execute($sku, $stockId, $requestedQty)->isSalable()
  70. );
  71. }
  72. public function isProductSalableForRequestedQtyWithBackordersEnabledAtProductLevelDataProvider()
  73. {
  74. return [
  75. 'salable_qty' => ['SKU-1', 10, -4.5, 13, true],
  76. 'not_salable_qty' => ['SKU-1', 10, -4.5, 14, false],
  77. ];
  78. }
  79. /**
  80. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  81. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  82. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
  83. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
  84. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  85. * @magentoConfigFixture default_store cataloginventory/item_options/min_qty -4.5
  86. * @magentoConfigFixture default_store cataloginventory/item_options/backorders 1
  87. * @dataProvider isProductSalableForRequestedQtyWithBackordersEnabledGloballyDataProvider
  88. *
  89. * @magentoDbIsolation disabled
  90. */
  91. public function testIsProductSalableForRequestedQtyWithBackordersEnabledGlobally(
  92. $sku,
  93. $stockId,
  94. $requestedQty,
  95. $expectedSalability
  96. ) {
  97. $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
  98. $stockItemConfiguration->setUseConfigBackorders(true);
  99. $stockItemConfiguration->setUseConfigMinQty(true);
  100. $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration);
  101. $this->assertEquals(
  102. $expectedSalability,
  103. $this->isProductSalableForRequestedQty->execute($sku, $stockId, $requestedQty)->isSalable()
  104. );
  105. }
  106. public function isProductSalableForRequestedQtyWithBackordersEnabledGloballyDataProvider()
  107. {
  108. return [
  109. 'salable_qty' => ['SKU-1', 10, 13, true],
  110. 'not_salable_qty' => ['SKU-1', 10, 14, false],
  111. ];
  112. }
  113. }