BulkConfigurationTransferTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\InventoryLowQuantityNotification\Test\Integration\Model\ResourceModel;
  8. use Magento\InventoryLowQuantityNotification\Model\ResourceModel\BulkConfigurationTransfer;
  9. use Magento\InventoryLowQuantityNotificationApi\Api\GetSourceItemConfigurationInterface;
  10. use Magento\TestFramework\Helper\Bootstrap;
  11. use PHPUnit\Framework\TestCase;
  12. class BulkConfigurationTransferTest extends TestCase
  13. {
  14. /**
  15. * @var BulkConfigurationTransfer
  16. */
  17. private $bulkConfigurationTransfer;
  18. /**
  19. * @var GetSourceItemConfigurationInterface
  20. */
  21. private $getSourceItemConfiguration;
  22. public function setUp()
  23. {
  24. parent::setUp();
  25. $this->bulkConfigurationTransfer = Bootstrap::getObjectManager()->get(BulkConfigurationTransfer::class);
  26. $this->getSourceItemConfiguration =
  27. Bootstrap::getObjectManager()->create(GetSourceItemConfigurationInterface::class);
  28. }
  29. /**
  30. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  31. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  32. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  33. * @magentoDataFixture ../../../../app/code/Magento/InventoryLowQuantityNotificationApi/Test/_files/source_item_configuration.php
  34. * @magentoDbIsolation enabled
  35. * @throws \Magento\Framework\Exception\LocalizedException
  36. */
  37. public function testTransfer()
  38. {
  39. $sourceConfig = $this->getSourceItemConfiguration->execute('eu-1', 'SKU-1');
  40. $this->bulkConfigurationTransfer->execute(['SKU-1'], 'eu-1', 'eu-2');
  41. $destinationConfig = $this->getSourceItemConfiguration->execute('eu-2', 'SKU-1');
  42. self::assertEquals(
  43. $sourceConfig->getNotifyStockQty(),
  44. $destinationConfig->getNotifyStockQty(),
  45. 'Low stock notification configuration was not transferred on bulk operations'
  46. );
  47. }
  48. /**
  49. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  50. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  51. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  52. * @magentoDataFixture ../../../../app/code/Magento/InventoryLowQuantityNotificationApi/Test/_files/source_item_configuration.php
  53. * @magentoDbIsolation enabled
  54. * @throws \Magento\Framework\Exception\LocalizedException
  55. */
  56. public function testTransferWithUnassign()
  57. {
  58. $sourceConfig = $this->getSourceItemConfiguration->execute('eu-1', 'SKU-1');
  59. $this->bulkConfigurationTransfer->execute(['SKU-1'], 'eu-1', 'eu-2');
  60. $destinationConfig = $this->getSourceItemConfiguration->execute('eu-2', 'SKU-1');
  61. self::assertEquals(
  62. $sourceConfig->getNotifyStockQty(),
  63. $destinationConfig->getNotifyStockQty(),
  64. 'Low stock notification configuration was not transferred on bulk operations'
  65. );
  66. }
  67. /**
  68. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  69. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  70. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  71. * @magentoDataFixture ../../../../app/code/Magento/InventoryLowQuantityNotificationApi/Test/_files/source_item_configuration.php
  72. * @magentoDbIsolation enabled
  73. * @throws \Magento\Framework\Exception\LocalizedException
  74. */
  75. public function testTransferFromUnassignedSource()
  76. {
  77. $this->bulkConfigurationTransfer->execute(['SKU-1'], 'us-1', 'eu-1');
  78. $sourceConfig = $this->getSourceItemConfiguration->execute('eu-1', 'SKU-1');
  79. self::assertEquals(
  80. 5.6,
  81. $sourceConfig->getNotifyStockQty(),
  82. 'Low stock notification was overwritten by an unassigned source'
  83. );
  84. }
  85. /**
  86. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  87. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  88. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  89. * @magentoDataFixture ../../../../app/code/Magento/InventoryLowQuantityNotificationApi/Test/_files/source_item_configuration.php
  90. * @magentoDbIsolation enabled
  91. * @throws \Magento\Framework\Exception\LocalizedException
  92. */
  93. public function testTransferToUnassignedSource()
  94. {
  95. $this->bulkConfigurationTransfer->execute(['SKU-1'], 'eu-1', 'us-1');
  96. $sourceConfig = $this->getSourceItemConfiguration->execute('us-1', 'SKU-1');
  97. self::assertEquals(
  98. 5.6,
  99. $sourceConfig->getNotifyStockQty(),
  100. 'Low stock notification was not transferred to unassigned source'
  101. );
  102. }
  103. }