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