Skip to content

Commit ca3af73

Browse files
authored
Merge pull request #100 from magento-tsg/2.4-develop-sidecar-pr18
[Sidecar] Integration tests delivery
2 parents 7b5d93c + 9716a68 commit ca3af73

File tree

6 files changed

+745
-91
lines changed

6 files changed

+745
-91
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventoryCatalog\Test\Integration;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Framework\MessageQueue\MessageEncoder;
12+
use Magento\Framework\MessageQueue\QueueFactoryInterface;
13+
use Magento\Framework\MessageQueue\QueueInterface;
14+
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\InventoryApi\Api\GetSourceItemsBySkuInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use Magento\TestFramework\MysqlMq\DeleteTopicRelatedMessages;
18+
use PHPUnit\Framework\TestCase;
19+
use Magento\InventoryCatalog\Model\DeleteSourceItemsBySkus;
20+
use Magento\InventoryLowQuantityNotification\Model\ResourceModel\SourceItemConfiguration\GetBySku;
21+
22+
/**
23+
* Test for delete product source
24+
*
25+
* @magentoAppArea adminhtml
26+
*/
27+
class DeleteProductTest extends TestCase
28+
{
29+
/**
30+
* @var ObjectManagerInterface
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* @var QueueInterface
36+
*/
37+
private $queue;
38+
39+
/**
40+
* @var MessageEncoder
41+
*/
42+
private $messageEncoder;
43+
44+
/**
45+
* @var DeleteSourceItemsBySkus
46+
*/
47+
private $handler;
48+
49+
/**
50+
* @var DeleteTopicRelatedMessages
51+
*/
52+
private $deleteTopicMessages;
53+
54+
/**
55+
* @var GetBySku
56+
*/
57+
private $getBySku;
58+
59+
/**
60+
* @var ProductRepositoryInterface
61+
*/
62+
private $productRepository;
63+
64+
/**
65+
* @var GetSourceItemsBySkuInterface
66+
*/
67+
private $getSourceItemsBySku;
68+
69+
/**
70+
* @inheritdoc
71+
*/
72+
public function setUp(): void
73+
{
74+
parent::setUp();
75+
76+
$this->objectManager = Bootstrap::getObjectManager();
77+
$this->queue = $this->objectManager->get(QueueFactoryInterface::class)->create(
78+
'inventory.source.items.cleanup',
79+
'db'
80+
);
81+
$this->messageEncoder = $this->objectManager->get(MessageEncoder::class);
82+
$this->handler = $this->objectManager->get(DeleteSourceItemsBySkus::class);
83+
$this->deleteTopicMessages = $this->objectManager->get(DeleteTopicRelatedMessages::class);
84+
$this->getBySku = $this->objectManager->get(GetBySku::class);
85+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
86+
$this->productRepository->cleanCache();
87+
$this->getSourceItemsBySku = $this->objectManager->get(GetSourceItemsBySkuInterface::class);
88+
}
89+
90+
/**
91+
* @magentoConfigFixture default/cataloginventory/options/synchronize_with_catalog 1
92+
*
93+
* @magentoDataFixture Magento_InventoryApi::Test/_files/products.php
94+
* @magentoDataFixture Magento_InventoryApi::Test/_files/sources.php
95+
* @magentoDataFixture Magento_InventoryApi::Test/_files/source_items.php
96+
* @magentoDataFixture Magento_InventoryLowQuantityNotificationApi::Test/_files/source_item_configuration.php
97+
*
98+
* @return void
99+
*/
100+
public function testSourceItemDeletedOnProductImport(): void
101+
{
102+
$this->deleteTopicMessages->execute('inventory.source.items.cleanup');
103+
$productSku = 'SKU-1';
104+
$this->productRepository->deleteById($productSku);
105+
$this->processMessages('inventory.source.items.cleanup');
106+
107+
$sourceItems = $this->getSourceItemsBySku->execute($productSku);
108+
self::assertEmpty($sourceItems);
109+
110+
$sourceItemConfigurations = $this->getBySku->execute('SKU-1');
111+
self::assertEmpty($sourceItemConfigurations);
112+
}
113+
114+
/**
115+
* Process topic messages
116+
*
117+
* @param string $topicName
118+
* @return void
119+
*/
120+
private function processMessages(string $topicName): void
121+
{
122+
$envelope = $this->queue->dequeue();
123+
$decodedMessage = $this->messageEncoder->decode($topicName, $envelope->getBody());
124+
$this->handler->execute($decodedMessage);
125+
}
126+
}

InventoryGroupedProduct/Test/Integration/Order/PlaceOrderOnDefaultStockTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class PlaceOrderOnDefaultStockTest extends PlaceOrderTest
1818
* @magentoDataFixture Magento_InventoryIndexer::Test/_files/reindex_inventory.php
1919
* @see https://app.hiptest.com/projects/69435/test-plan/folders/419537/scenarios/1620162
2020
*/
21-
public function testPlaceOrderWithInStockProduct()
21+
public function testPlaceOrderWithInStockProduct(): void
2222
{
2323
$groupedSku = 'grouped_in_stock';
2424
$simpleSku = 'simple_11';
@@ -48,7 +48,7 @@ public function testPlaceOrderWithInStockProduct()
4848
* @magentoDataFixture Magento_InventorySalesApi::Test/_files/quote.php
4949
* @magentoDataFixture Magento_InventoryIndexer::Test/_files/reindex_inventory.php
5050
*/
51-
public function testPlaceOrderWithOutOffStockProduct()
51+
public function testPlaceOrderWithOutOffStockProduct(): void
5252
{
5353
$groupedSku = 'grouped_out_of_stock';
5454
$simpleSku = 'simple_11';
@@ -77,7 +77,7 @@ public function testPlaceOrderWithOutOffStockProduct()
7777
* @magentoDataFixture Magento_InventoryIndexer::Test/_files/reindex_inventory.php
7878
* @magentoConfigFixture current_store cataloginventory/item_options/backorders 1
7979
*/
80-
public function testPlaceOrderWithOutOffStockProductAndBackOrdersTurnedOn()
80+
public function testPlaceOrderWithOutOffStockProductAndBackOrdersTurnedOn(): void
8181
{
8282
$groupedSku = 'grouped_out_of_stock';
8383
$simpleSku = 'simple_11';
@@ -109,7 +109,7 @@ public function testPlaceOrderWithOutOffStockProductAndBackOrdersTurnedOn()
109109
* @magentoDataFixture Magento_InventoryIndexer::Test/_files/reindex_inventory.php
110110
* @magentoConfigFixture current_store cataloginventory/item_options/manage_stock 0
111111
*/
112-
public function testPlaceOrderWithOutOffStockProductAndManageStockTurnedOff()
112+
public function testPlaceOrderWithOutOffStockProductAndManageStockTurnedOff(): void
113113
{
114114
$groupedSku = 'grouped_out_of_stock';
115115
$simpleSku = 'simple_11';

InventoryImportExport/Test/Integration/Model/Import/ProductTest.php

Lines changed: 98 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@
1616
use Magento\Framework\App\Filesystem\DirectoryList;
1717
use Magento\Framework\Exception\NoSuchEntityException;
1818
use Magento\Framework\Filesystem;
19+
use Magento\Framework\MessageQueue\MessageEncoder;
20+
use Magento\Framework\MessageQueue\QueueFactoryInterface;
21+
use Magento\Framework\ObjectManagerInterface;
1922
use Magento\ImportExport\Model\Import;
2023
use Magento\ImportExport\Model\Import\Source\Csv;
24+
use Magento\ImportExport\Model\Import\Source\CsvFactory;
2125
use Magento\InventoryApi\Api\Data\SourceItemInterface;
2226
use Magento\InventoryApi\Api\Data\SourceItemSearchResultsInterface;
2327
use Magento\InventoryApi\Api\SourceItemRepositoryInterface;
28+
use Magento\InventoryCatalog\Model\DeleteSourceItemsBySkus;
2429
use Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface;
30+
use Magento\InventoryLowQuantityNotification\Model\ResourceModel\SourceItemConfiguration\GetBySku;
31+
use Magento\MysqlMq\Model\Driver\Queue;
2532
use Magento\TestFramework\Helper\Bootstrap;
33+
use Magento\TestFramework\MysqlMq\DeleteTopicRelatedMessages;
2634
use PHPUnit\Framework\TestCase;
2735

2836
/**
@@ -33,6 +41,11 @@
3341
*/
3442
class ProductTest extends TestCase
3543
{
44+
/**
45+
* @var ObjectManagerInterface
46+
*/
47+
private $objectManager;
48+
3649
/**
3750
* @var DefaultSourceProviderInterface
3851
*/
@@ -63,26 +76,50 @@ class ProductTest extends TestCase
6376
*/
6477
private $importedProducts;
6578

79+
/**
80+
* @var Queue
81+
*/
82+
private $queue;
83+
84+
/**
85+
* @var MessageEncoder
86+
*/
87+
private $messageEncoder;
88+
89+
/**
90+
* @var DeleteSourceItemsBySkus
91+
*/
92+
private $consumer;
93+
94+
/**
95+
* @var DeleteTopicRelatedMessages
96+
*/
97+
private $deleteTopicMessages;
98+
99+
/**
100+
* @var GetBySku
101+
*/
102+
private $getBySku;
103+
66104
/**
67105
* Setup Test for Product Import
68106
*/
69107
public function setUp(): void
70108
{
71-
$this->defaultSourceProvider = Bootstrap::getObjectManager()->get(
72-
DefaultSourceProviderInterface::class
73-
);
74-
$this->filesystem = Bootstrap::getObjectManager()->get(
75-
Filesystem::class
76-
);
77-
$this->productImporterFactory = Bootstrap::getObjectManager()->get(
78-
ProductFactory::class
79-
);
80-
$this->searchCriteriaBuilderFactory = Bootstrap::getObjectManager()->get(
81-
SearchCriteriaBuilderFactory::class
82-
);
83-
$this->sourceItemRepository = Bootstrap::getObjectManager()->get(
84-
SourceItemRepositoryInterface::class
109+
$this->objectManager = Bootstrap::getObjectManager();
110+
$this->defaultSourceProvider = $this->objectManager->get(DefaultSourceProviderInterface::class);
111+
$this->filesystem = $this->objectManager->get(Filesystem::class);
112+
$this->productImporterFactory = $this->objectManager->get(ProductFactory::class);
113+
$this->searchCriteriaBuilderFactory = $this->objectManager->get(SearchCriteriaBuilderFactory::class);
114+
$this->sourceItemRepository = $this->objectManager->get(SourceItemRepositoryInterface::class);
115+
$this->queue = $this->objectManager->get(QueueFactoryInterface::class)->create(
116+
'inventory.source.items.cleanup',
117+
'db'
85118
);
119+
$this->messageEncoder = $this->objectManager->get(MessageEncoder::class);
120+
$this->consumer = $this->objectManager->get(DeleteSourceItemsBySkus::class);
121+
$this->deleteTopicMessages = $this->objectManager->get(DeleteTopicRelatedMessages::class);
122+
$this->getBySku = $this->objectManager->get(GetBySku::class);
86123
}
87124

88125
/**
@@ -100,7 +137,7 @@ public function testSourceItemCreatedOnProductImport(): void
100137
$productImporterModel->importData();
101138
$sku = 'example_simple_for_source_item';
102139
$compareData = $this->buildDataArray(
103-
$this->getSourceItemList()->getItems()
140+
$this->getSourceItemList('example_simple_for_source_item')->getItems()
104141
);
105142
$expectedData = [
106143
SourceItemInterface::SKU => $sku,
@@ -134,7 +171,7 @@ public function testSourceItemUpdatedOnProductImport(): void
134171
$productImporterModel->importData();
135172
$sku = 'example_simple_for_source_item';
136173
$compareData = $this->buildDataArray(
137-
$this->getSourceItemList()->getItems()
174+
$this->getSourceItemList('example_simple_for_source_item')->getItems()
138175
);
139176
$expectedData = [
140177
SourceItemInterface::SKU => $sku,
@@ -153,19 +190,59 @@ public function testSourceItemUpdatedOnProductImport(): void
153190
$this->importedProducts = [$sku];
154191
}
155192

193+
/**
194+
* @magentoConfigFixture default/cataloginventory/options/synchronize_with_catalog 1
195+
*
196+
* @magentoDataFixture Magento_InventoryApi::Test/_files/products.php
197+
* @magentoDataFixture Magento_InventoryApi::Test/_files/sources.php
198+
* @magentoDataFixture Magento_InventoryApi::Test/_files/source_items.php
199+
* @magentoDataFixture Magento_InventoryLowQuantityNotificationApi::Test/_files/source_item_configuration.php
200+
*
201+
* @return void
202+
*/
203+
public function testSourceItemDeletedOnProductImport(): void
204+
{
205+
$this->deleteTopicMessages->execute('inventory.source.items.cleanup');
206+
$pathToFile = __DIR__ . '/_files/product_import_SKU-1.csv';
207+
$productSku = 'SKU-1';
208+
$productImporterModel = $this->getProductImporterModel($pathToFile, Import::BEHAVIOR_DELETE);
209+
$errors = $productImporterModel->validateData();
210+
$this->assertTrue($errors->getErrorsCount() == 0);
211+
$productImporterModel->importData();
212+
$this->importedProducts[] = $productSku;
213+
$this->processMessages('inventory.source.items.cleanup');
214+
215+
$this->assertEmpty($this->getSourceItemList($productSku)->getItems());
216+
$this->assertEmpty($this->getBySku->execute($productSku));
217+
}
218+
219+
/**
220+
* Process topic messages
221+
*
222+
* @param string $topicName
223+
* @return void
224+
*/
225+
private function processMessages(string $topicName): void
226+
{
227+
$envelope = $this->queue->dequeue();
228+
$decodedMessage = $this->messageEncoder->decode($topicName, $envelope->getBody());
229+
$this->consumer->execute($decodedMessage);
230+
}
231+
156232
/**
157233
* Get List of Source Items which match SKU and Source ID of dummy data
158234
*
235+
* @param string $sku
159236
* @return SourceItemSearchResultsInterface
160237
*/
161-
private function getSourceItemList(): SourceItemSearchResultsInterface
238+
private function getSourceItemList(string $sku): SourceItemSearchResultsInterface
162239
{
163240
/** @var SearchCriteriaBuilder $searchCriteria */
164241
$searchCriteriaBuilder = $this->searchCriteriaBuilderFactory->create();
165242

166243
$searchCriteriaBuilder->addFilter(
167244
SourceItemInterface::SKU,
168-
'example_simple_for_source_item'
245+
$sku
169246
);
170247

171248
$searchCriteriaBuilder->addFilter(
@@ -206,15 +283,14 @@ private function buildDataArray(array $sourceItems): array
206283
* @return Product
207284
*/
208285
private function getProductImporterModel(
209-
$pathToFile,
210-
$behavior = Import::BEHAVIOR_ADD_UPDATE
286+
string $pathToFile,
287+
string $behavior = Import::BEHAVIOR_ADD_UPDATE
211288
): Product {
212289
/** @var Filesystem\Directory\WriteInterface $directory */
213290
$directory = $this->filesystem
214291
->getDirectoryWrite(DirectoryList::ROOT);
215292
/** @var Csv $source */
216-
$source = Bootstrap::getObjectManager()->create(
217-
Csv::class,
293+
$source = $this->objectManager->get(CsvFactory::class)->create(
218294
[
219295
'file' => $pathToFile,
220296
'directory' => $directory
@@ -234,7 +310,6 @@ private function getProductImporterModel(
234310
/**
235311
* Cleanup test by removing products.
236312
*
237-
* @param string[] $skus
238313
* @return void
239314
*/
240315
protected function tearDown(): void
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,swatch_image,swatch_image_label,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,deferred_stock_update,use_config_deferred_stock_update,related_skus,related_position,crosssell_skus,crosssell_position,upsell_skus,upsell_position,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,bundle_shipment_type,use_config_is_redeemable,use_config_lifetime,use_config_allow_message,use_config_email_template,associated_skus,downloadable_links,downloadable_samples,configurable_variations,configurable_variation_labels
2+
SKU-1,,Default,simple,,base,"Simple Product 1 Orange",,,,1,"Taxable Goods","Catalog, Search",10.000000,,,,simple-product-1-orange,,,,,,,,,,,,"3/16/21, 10:24 AM","3/16/21, 10:24 AM",,,"Block after Info Column",,,,,,,,,,,"Use config",,,0.0000,0.0000,1,1,0,1,1.0000,1,0.0000,1,0,,1,1,1,1,0.0000,1,0,0,0,0,1,,,,,,,,,,,,,,,,,,,,,,,,,

0 commit comments

Comments
 (0)