RssFeedTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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;
  8. use Magento\InventoryLowQuantityNotificationAdminUi\Block\Adminhtml\Rss\NotifyStock;
  9. use Magento\InventoryLowQuantityNotificationApi\Api\GetSourceItemConfigurationInterface;
  10. use Magento\InventoryLowQuantityNotificationApi\Api\SourceItemConfigurationsSaveInterface;
  11. use Magento\Store\Model\Store;
  12. use Magento\Store\Model\StoreManagerInterface;
  13. use Magento\TestFramework\Helper\Bootstrap;
  14. use PHPUnit\Framework\TestCase;
  15. /**
  16. * Test getRssData with different configuration on multi source inventory.
  17. */
  18. class RssFeedTest extends TestCase
  19. {
  20. /**
  21. * @var NotifyStock
  22. */
  23. private $dataProvider;
  24. /**
  25. * @var StoreManagerInterface
  26. */
  27. private $storeManager;
  28. /**
  29. * @var string
  30. */
  31. private $storeCodeBefore;
  32. /**
  33. * @var SourceItemConfigurationsSaveInterface
  34. */
  35. private $sourceItemConfigurationsSave;
  36. /**
  37. * @var GetSourceItemConfigurationInterface
  38. */
  39. private $getSourceItemConfiguration;
  40. /**
  41. * @inheritdoc
  42. */
  43. protected function setUp()
  44. {
  45. parent::setUp();
  46. $this->dataProvider = Bootstrap::getObjectManager()->create(NotifyStock::class);
  47. $this->storeManager = Bootstrap::getObjectManager()->create(StoreManagerInterface::class);
  48. $this->sourceItemConfigurationsSave = Bootstrap::getObjectManager()
  49. ->create(SourceItemConfigurationsSaveInterface::class);
  50. $this->getSourceItemConfiguration = Bootstrap::getObjectManager()
  51. ->create(GetSourceItemConfigurationInterface::class);
  52. $this->storeCodeBefore = $this->storeManager->getStore()->getCode();
  53. $this->storeManager->setCurrentStore(Store::ADMIN_CODE);
  54. }
  55. /**
  56. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  57. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  58. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
  59. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  60. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
  61. * @codingStandardsIgnoreLine
  62. * @magentoDataFixture ../../../../app/code/Magento/InventoryLowQuantityNotificationApi/Test/_files/source_item_configuration.php
  63. * @magentoConfigFixture default_store cataloginventory/item_options/notify_stock_qty 7
  64. *
  65. * @param string $sku
  66. * @param string $sourceCode
  67. * @param float $notifyQty
  68. * @param int $expectedCount
  69. * @return void
  70. *
  71. * @dataProvider getRssDataDataProvider
  72. */
  73. public function testGetRssData(
  74. string $sku,
  75. string $sourceCode,
  76. $notifyQty,
  77. int $expectedCount
  78. ) {
  79. $sourceItemConfiguration = $this->getSourceItemConfiguration->execute($sourceCode, $sku);
  80. $sourceItemConfiguration->setNotifyStockQty($notifyQty);
  81. $this->sourceItemConfigurationsSave->execute([$sourceItemConfiguration]);
  82. $data = $this->dataProvider->getRssData();
  83. $this->assertEquals($expectedCount, count($data['entries']));
  84. }
  85. /**
  86. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
  87. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  88. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
  89. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
  90. * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
  91. * @codingStandardsIgnoreLine
  92. * @magentoDataFixture ../../../../app/code/Magento/InventoryLowQuantityNotificationApi/Test/_files/source_item_configuration.php
  93. * @codingStandardsIgnoreLine
  94. * @magentoDataFixture ../../../../app/code/Magento/InventoryLowQuantityNotificationApi/Test/_files/enable_manage_stock_for_products.php
  95. * @magentoConfigFixture default_store cataloginventory/item_options/notify_stock_qty 7
  96. * @magentoConfigFixture default_store cataloginventory/item_options/manage_stock 0
  97. *
  98. * @param string $sku
  99. * @param string $sourceCode
  100. * @param float $notifyQty
  101. * @param int $expectedCount
  102. * @return void
  103. *
  104. * @dataProvider getRssDataDataProvider
  105. */
  106. public function testGetRssDataDisabledManageStock(
  107. string $sku,
  108. string $sourceCode,
  109. $notifyQty,
  110. int $expectedCount
  111. ) {
  112. $sourceItemConfiguration = $this->getSourceItemConfiguration->execute($sourceCode, $sku);
  113. $sourceItemConfiguration->setNotifyStockQty($notifyQty);
  114. $this->sourceItemConfigurationsSave->execute([$sourceItemConfiguration]);
  115. $data = $this->dataProvider->getRssData();
  116. $this->assertEquals($expectedCount, count($data['entries']));
  117. }
  118. /**
  119. * @return array
  120. */
  121. public function getRssDataDataProvider(): array
  122. {
  123. return [
  124. ['SKU-1', 'eu-disabled', 12, 3],
  125. ['SKU-1', 'eu-disabled', 6, 2],
  126. ['SKU-1', 'eu-disabled', null, 2],
  127. ['SKU-1', 'eu-1', 6, 3],
  128. ['SKU-1', 'eu-1', 5.4, 2],
  129. ['SKU-1', 'eu-1', null, 3],
  130. ['SKU-2', 'us-1', 8, 4],
  131. ['SKU-2', 'us-1', 1, 3],
  132. ['SKU-2', 'us-1', null, 4],
  133. ['SKU-3', 'eu-2', 10, 3],
  134. ['SKU-3', 'eu-2', 5, 2],
  135. ['SKU-3', 'eu-2', null, 3],
  136. ];
  137. }
  138. /**
  139. * @inheritdoc
  140. */
  141. protected function tearDown()
  142. {
  143. parent::tearDown();
  144. if (null !== $this->storeCodeBefore) {
  145. $this->storeManager->setCurrentStore($this->storeCodeBefore);
  146. }
  147. }
  148. }