From 35757801a67c9c3a62c019c1e23e650f2c973a36 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Wed, 25 Apr 2018 11:58:17 +0300 Subject: [PATCH] MSI-724: Implement IsCorrectQtyConditionTest::testExecuteWithQtyIncrements --- .../IsCorrectQtyConditionTest.php | 78 ++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/InventorySales/Test/Integration/IsProductSalableForRequestedQty/IsCorrectQtyConditionTest.php b/app/code/Magento/InventorySales/Test/Integration/IsProductSalableForRequestedQty/IsCorrectQtyConditionTest.php index 009f05bd968fe..99131725e1867 100644 --- a/app/code/Magento/InventorySales/Test/Integration/IsProductSalableForRequestedQty/IsCorrectQtyConditionTest.php +++ b/app/code/Magento/InventorySales/Test/Integration/IsProductSalableForRequestedQty/IsCorrectQtyConditionTest.php @@ -7,6 +7,7 @@ namespace Magento\InventorySales\Test\Integration\IsProductSalableForRequestedQty; +use Magento\InventoryConfigurationApi\Api\Data\StockItemConfigurationInterface; use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface; use Magento\InventoryConfigurationApi\Api\SaveStockItemConfigurationInterface; use Magento\InventorySalesApi\Api\IsProductSalableForRequestedQtyInterface; @@ -30,6 +31,16 @@ class IsCorrectQtyConditionTest extends TestCase */ private $isProductSalableForRequestedQty; + /** + * @var GetStockItemConfigurationInterface + */ + private $getStockItemConfiguration; + + /** + * @var SaveStockItemConfigurationInterface + */ + private $saveStockItemConfiguration; + /** * @inheritdoc */ @@ -41,6 +52,12 @@ protected function setUp() $this->saveStockItemConfig = Bootstrap::getObjectManager()->get(SaveStockItemConfigurationInterface::class); $this->isProductSalableForRequestedQty = Bootstrap::getObjectManager()->get(IsProductSalableForRequestedQtyInterface::class); + $this->getStockItemConfiguration = Bootstrap::getObjectManager()->get( + GetStockItemConfigurationInterface::class + ); + $this->saveStockItemConfiguration = Bootstrap::getObjectManager()->get( + SaveStockItemConfigurationInterface::class + ); } /** @@ -85,8 +102,65 @@ public function testExecuteWithMaxSaleQty() $this->markTestIncomplete('Still to implement'); } - public function testExecuteWithQtyIncrements() + /** + * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php + * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php + * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php + * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php + * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php + * @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php + * + * @param string $sku + * @param int $stockId + * @param int $requestedQty + * @param bool $expectedResult + * + * @return void + * + * @dataProvider executeWithQtyIncrementsDataProvider + */ + public function testExecuteWithQtyIncrements( + string $sku, + int $stockId, + int $requestedQty, + bool $expectedResult + ): void { + /** @var StockItemConfigurationInterface $stockItemConfiguration */ + $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId); + $stockItemConfiguration->setUseConfigEnableQtyInc(false); + $stockItemConfiguration->setEnableQtyIncrements(true); + $stockItemConfiguration->setUseConfigQtyIncrements(false); + $stockItemConfiguration->setQtyIncrements(3); + $this->saveStockItemConfiguration->execute($sku, $stockId, $stockItemConfiguration); + + $result = $this->isProductSalableForRequestedQty->execute($sku, $stockId, $requestedQty); + $this->assertEquals($expectedResult, $result->isSalable()); + } + + /** + * @return array + */ + public function executeWithQtyIncrementsDataProvider(): array { - $this->markTestIncomplete('Still to implement'); + return [ + ['SKU-1', 10, 1, false], + ['SKU-1', 10, 3, true], + ['SKU-1', 10, 6, true], + ['SKU-1', 10, 9, false], + ['SKU-3', 10, 1, false], + ['SKU-3', 10, 3, false], + ['SKU-2', 20, 1, false], + ['SKU-2', 20, 3, true], + ['SKU-2', 20, 6, false], + ['SKU-1', 30, 1, false], + ['SKU-1', 30, 3, true], + ['SKU-1', 30, 6, true], + ['SKU-1', 30, 9, false], + ['SKU-2', 30, 1, false], + ['SKU-2', 30, 3, true], + ['SKU-2', 30, 6, false], + ['SKU-3', 30, 1, false], + ['SKU-3', 30, 3, false], + ]; } }