|
13 | 13 | use Magento\Catalog\Helper\Data as CatalogConfig;
|
14 | 14 | use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
15 | 15 | use Magento\CatalogImportExport\Model\Import\ProductTestBase;
|
| 16 | +use Magento\Framework\Exception\LocalizedException; |
| 17 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 18 | +use Magento\Framework\Exception\StateException; |
16 | 19 | use Magento\ImportExport\Helper\Data as ImportExportConfig;
|
| 20 | +use Magento\ImportExport\Model\Import; |
17 | 21 | use Magento\Store\Model\ScopeInterface;
|
18 | 22 | use Magento\Store\Model\StoreManagerInterface;
|
19 | 23 | use Magento\Store\Test\Fixture\Store as StoreFixture;
|
20 | 24 | use Magento\TestFramework\Fixture\AppIsolation;
|
21 | 25 | use Magento\TestFramework\Fixture\Config;
|
22 | 26 | use Magento\TestFramework\Fixture\DataFixture;
|
| 27 | +use Magento\TestFramework\Helper\Bootstrap; |
23 | 28 |
|
24 | 29 | /**
|
25 | 30 | * Integration test for \Magento\CatalogImportExport\Model\Import\Product class.
|
@@ -90,7 +95,7 @@ public function testSaveCustomOptions(string $importFile, string $sku, int $expe
|
90 | 95 | $importModel->importData();
|
91 | 96 |
|
92 | 97 | /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
93 |
| - $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( |
| 98 | + $productRepository = Bootstrap::getObjectManager()->create( |
94 | 99 | \Magento\Catalog\Api\ProductRepositoryInterface::class
|
95 | 100 | );
|
96 | 101 | $product = $productRepository->get($sku);
|
@@ -187,17 +192,17 @@ public function testSaveCustomOptionsWithMultipleStoreViews(
|
187 | 192 | array $expected
|
188 | 193 | ) {
|
189 | 194 | $expected = $this->getFullExpectedOptions($expected);
|
190 |
| - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 195 | + $objectManager = Bootstrap::getObjectManager(); |
191 | 196 | /** @var StoreManagerInterface $storeManager */
|
192 | 197 | $storeManager = $objectManager->get(StoreManagerInterface::class);
|
193 | 198 | $pathToFile = __DIR__ . '/../_files/' . $importFile;
|
194 | 199 | $importModel = $this->createImportModel($pathToFile);
|
195 | 200 | $errors = $importModel->validateData();
|
196 | 201 | $this->assertTrue($errors->getErrorsCount() == 0, 'Import File Validation Failed');
|
197 | 202 | $importModel->importData();
|
198 |
| - /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ |
| 203 | + /** @var ProductRepositoryInterface $productRepository */ |
199 | 204 | $productRepository = $objectManager->get(
|
200 |
| - \Magento\Catalog\Api\ProductRepositoryInterface::class |
| 205 | + ProductRepositoryInterface::class |
201 | 206 | );
|
202 | 207 | $actual = [];
|
203 | 208 | foreach ($expected as $sku => $storesData) {
|
@@ -982,9 +987,9 @@ public function testImportCustomOptions(string $importFile, string $sku1, string
|
982 | 987 | $this->assertTrue($errors->getErrorsCount() == 0);
|
983 | 988 | $importModel->importData();
|
984 | 989 |
|
985 |
| - /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ |
986 |
| - $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( |
987 |
| - \Magento\Catalog\Api\ProductRepositoryInterface::class |
| 990 | + /** @var ProductRepositoryInterface $productRepository */ |
| 991 | + $productRepository = Bootstrap::getObjectManager()->create( |
| 992 | + ProductRepositoryInterface::class |
988 | 993 | );
|
989 | 994 | $product1 = $productRepository->get($sku1);
|
990 | 995 |
|
@@ -1025,4 +1030,65 @@ public function getCustomOptionDataProvider(): array
|
1025 | 1030 | ],
|
1026 | 1031 | ];
|
1027 | 1032 | }
|
| 1033 | + |
| 1034 | + /** |
| 1035 | + * Tests import product custom options with multiple uploads. |
| 1036 | + * |
| 1037 | + * @dataProvider getProductCustomOptionDataProvider |
| 1038 | + * @param string $importFile |
| 1039 | + * @param string $sku |
| 1040 | + * @param int $uploadCount |
| 1041 | + * @throws LocalizedException |
| 1042 | + * @throws NoSuchEntityException |
| 1043 | + * @throws StateException |
| 1044 | + */ |
| 1045 | + #[ |
| 1046 | + Config(CatalogConfig::XML_PATH_PRICE_SCOPE, CatalogConfig::PRICE_SCOPE_WEBSITE, ScopeInterface::SCOPE_STORE), |
| 1047 | + DataFixture(StoreFixture::class, ['code' => 'secondstore']), |
| 1048 | + ] |
| 1049 | + public function testImportProductCustomOptionsOnMultipleUploads(string $importFile, string $sku, int $uploadCount): void |
| 1050 | + { |
| 1051 | + $pathToFile = __DIR__ . '/../_files/' . $importFile; |
| 1052 | + |
| 1053 | + for($count = 0; $count < $uploadCount; $count++) { |
| 1054 | + $productImportModel = $this->createImportModel($pathToFile); |
| 1055 | + $errors = $productImportModel->validateData(); |
| 1056 | + $this->assertTrue($errors->getErrorsCount() == 0); |
| 1057 | + $productImportModel->importData(); |
| 1058 | + } |
| 1059 | + |
| 1060 | + /** @var ProductRepositoryInterface $productRepository */ |
| 1061 | + $productRepository = Bootstrap::getObjectManager()->create( |
| 1062 | + ProductRepositoryInterface::class |
| 1063 | + ); |
| 1064 | + $product = $productRepository->get($sku); |
| 1065 | + |
| 1066 | + $this->assertInstanceOf(\Magento\Catalog\Model\Product::class, $product); |
| 1067 | + $options = $product->getOptionInstance()->getProductOptions($product); |
| 1068 | + |
| 1069 | + $expectedData = $this->getExpectedOptionsData($pathToFile, 'secondstore'); |
| 1070 | + $expectedOptions = $expectedData['options']; |
| 1071 | + |
| 1072 | + $this->assertCount(count($expectedOptions), $options); |
| 1073 | + |
| 1074 | + // Cleanup imported products |
| 1075 | + try { |
| 1076 | + $this->productRepository->delete($product); |
| 1077 | + } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { |
| 1078 | + } |
| 1079 | + } |
| 1080 | + |
| 1081 | + /** |
| 1082 | + * @return array |
| 1083 | + */ |
| 1084 | + public function getProductCustomOptionDataProvider(): array |
| 1085 | + { |
| 1086 | + return [ |
| 1087 | + [ |
| 1088 | + 'importFile' => 'product_with_custom_options_and_multiple_uploads.csv', |
| 1089 | + 'sku' => 'simple', |
| 1090 | + 'uploadCount' => 2, |
| 1091 | + ], |
| 1092 | + ]; |
| 1093 | + } |
1028 | 1094 | }
|
0 commit comments