|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2025 Adobe |
| 4 | + * All Rights Reserved |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\CatalogImportExport\Model\Import\ProductTest; |
| 9 | + |
| 10 | +use Magento\Catalog\Api\ProductRepositoryInterface; |
| 11 | +use Magento\Catalog\Model\Product; |
| 12 | +use Magento\CatalogImportExport\Model\Import\ProductTestBase; |
| 13 | +use Magento\ImportExport\Model\Import; |
| 14 | +use Magento\Framework\Exception\LocalizedException; |
| 15 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 16 | +use Magento\TestFramework\Helper\Bootstrap; |
| 17 | + |
| 18 | +/** |
| 19 | + * @magentoAppArea adminhtml |
| 20 | + * @magentoDbIsolation disabled |
| 21 | + * @magentoDataFixtureBeforeTransaction Magento/Catalog/_files/enable_reindex_schedule.php |
| 22 | + * @magentoDataFixtureBeforeTransaction Magento/Catalog/_files/enable_catalog_product_reindex_schedule.php |
| 23 | + */ |
| 24 | +class CustomOptionsTest extends ProductTestBase |
| 25 | +{ |
| 26 | + /** |
| 27 | + * Test for custom options based on AC-3637 |
| 28 | + * |
| 29 | + * @dataProvider productsWithCustomOptionsDataProvider |
| 30 | + * @param string $filename |
| 31 | + * @param string $sku |
| 32 | + * @param int $numOfCustomOptions |
| 33 | + * @throws LocalizedException |
| 34 | + * @throws NoSuchEntityException |
| 35 | + * |
| 36 | + * @return void |
| 37 | + */ |
| 38 | + public function testImportDifferentCustomOptions(string $filename, string $sku, int $numOfCustomOptions): void |
| 39 | + { |
| 40 | + $pathToFile = __DIR__ . '/../_files/' . $filename; |
| 41 | + $importModel = $this->createImportModel($pathToFile, Import::BEHAVIOR_ADD_UPDATE); |
| 42 | + $errors = $importModel->validateData(); |
| 43 | + $this->assertTrue($errors->getErrorsCount() == 0); |
| 44 | + $importModel->importData(); |
| 45 | + |
| 46 | + /** @var ProductRepositoryInterface $productRepository */ |
| 47 | + $productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class); |
| 48 | + $product = $productRepository->get($sku); |
| 49 | + |
| 50 | + $this->assertInstanceOf(Product::class, $product); |
| 51 | + $options = $product->getOptionInstance()->getProductOptions($product); |
| 52 | + $this->assertCount($numOfCustomOptions, $options); |
| 53 | + |
| 54 | + try { |
| 55 | + $this->productRepository->delete($product); |
| 56 | + } catch (NoSuchEntityException $e) { |
| 57 | + //already deleted |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return array |
| 63 | + */ |
| 64 | + public static function productsWithCustomOptionsDataProvider(): array |
| 65 | + { |
| 66 | + return [ |
| 67 | + [ |
| 68 | + 'filename' => '001_simple1_no_custom_options.csv', |
| 69 | + 'sku' => 'simple1', |
| 70 | + 'numOfCustomOptions' => 0, |
| 71 | + ], |
| 72 | + [ |
| 73 | + 'filename' => '002_simple1_4_custom_options.csv', |
| 74 | + 'sku' => 'simple1', |
| 75 | + 'numOfCustomOptions' => 4, |
| 76 | + ], |
| 77 | + [ |
| 78 | + 'filename' => '003_simple1_5_custom_options.csv', |
| 79 | + 'sku' => 'simple1', |
| 80 | + 'numOfCustomOptions' => 5, |
| 81 | + ], |
| 82 | + [ |
| 83 | + 'filename' => '004_simple1_5_custom_options_1_updated.csv', |
| 84 | + 'sku' => 'simple1', |
| 85 | + 'numOfCustomOptions' => 5, |
| 86 | + ], |
| 87 | + [ |
| 88 | + 'filename' => '005_simple1_no_custom_options.csv', |
| 89 | + 'sku' => 'simple1', |
| 90 | + 'numOfCustomOptions' => 0, |
| 91 | + ], |
| 92 | + ]; |
| 93 | + } |
| 94 | +} |
0 commit comments