|
8 | 8 | namespace Magento\CatalogImportExport\Model\Import\ProductTest;
|
9 | 9 |
|
10 | 10 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
| 11 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
11 | 12 | use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
|
12 | 13 | use Magento\CatalogImportExport\Model\Import\ProductTestBase;
|
13 | 14 | use Magento\Framework\App\Filesystem\DirectoryList;
|
| 15 | +use Magento\Framework\Exception\LocalizedException; |
14 | 16 | use Magento\Framework\Filesystem;
|
15 | 17 | use Magento\ImportExport\Model\Import;
|
16 | 18 | use Magento\ImportExport\Model\Import\Source\Csv;
|
| 19 | +use Magento\TestFramework\Fixture\Config; |
| 20 | +use Magento\TestFramework\Fixture\DataFixture; |
17 | 21 |
|
18 | 22 | /**
|
19 | 23 | * Integration test for \Magento\CatalogImportExport\Model\Import\Product class.
|
@@ -67,7 +71,7 @@ public function testImportWithoutUrlKeysAndName()
|
67 | 71 | * @dataProvider validateUrlKeysDataProvider
|
68 | 72 | * @param $importFile string
|
69 | 73 | * @param $expectedErrors array
|
70 |
| - * @throws \Magento\Framework\Exception\LocalizedException |
| 74 | + * @throws LocalizedException |
71 | 75 | */
|
72 | 76 | public function testValidateUrlKeys($importFile, $expectedErrors)
|
73 | 77 | {
|
@@ -306,7 +310,7 @@ public function testImportWithoutUrlKeys()
|
306 | 310 | /**
|
307 | 311 | * @magentoDataFixture Magento/Catalog/_files/product_simple_with_non_latin_url_key.php
|
308 | 312 | * @return void
|
309 |
| - * @throws \Magento\Framework\Exception\LocalizedException |
| 313 | + * @throws LocalizedException |
310 | 314 | */
|
311 | 315 | public function testImportWithNonLatinUrlKeys()
|
312 | 316 | {
|
@@ -352,7 +356,7 @@ public function testImportWithNonLatinUrlKeys()
|
352 | 356 | * @magentoDbIsolation disabled
|
353 | 357 | * @magentoAppIsolation enabled
|
354 | 358 | * @return void
|
355 |
| - * @throws \Magento\Framework\Exception\LocalizedException |
| 359 | + * @throws LocalizedException |
356 | 360 | */
|
357 | 361 | public function testImportWithSpacesInUrlKeys()
|
358 | 362 | {
|
@@ -384,4 +388,45 @@ public function testImportWithSpacesInUrlKeys()
|
384 | 388 | $this->assertEquals($productUrlKey, $productRepository->get($productSku)->getUrlKey());
|
385 | 389 | }
|
386 | 390 | }
|
| 391 | + |
| 392 | + /** |
| 393 | + * Validate import file when we have an existing product with UrlKey that consists of an alpha characters and |
| 394 | + * a number at the end against the same imported UrlKey but without the number at the end, |
| 395 | + * when Product URL Suffix is set to none in the admin. |
| 396 | + * |
| 397 | + * @throws LocalizedException |
| 398 | + */ |
| 399 | + #[ |
| 400 | + Config('catalog/seo/product_url_suffix', null, 'store', 'default'), |
| 401 | + DataFixture( |
| 402 | + ProductFixture::class, |
| 403 | + [ |
| 404 | + 'url_key' => '1234t', |
| 405 | + 'url_path' => '1234t' |
| 406 | + ], |
| 407 | + ), |
| 408 | + ] |
| 409 | + public function testValidateMixedCharNumUrlKeysWithNullUrlSuffix() |
| 410 | + { |
| 411 | + $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( |
| 412 | + \Magento\Framework\Filesystem::class |
| 413 | + ); |
| 414 | + $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); |
| 415 | + |
| 416 | + $source = $this->objectManager->create( |
| 417 | + \Magento\ImportExport\Model\Import\Source\Csv::class, |
| 418 | + [ |
| 419 | + 'file' => __DIR__ . '/../_files/products_to_check_valid_url_keys_mixed_chars_nums.csv', |
| 420 | + 'directory' => $directory |
| 421 | + ] |
| 422 | + ); |
| 423 | + |
| 424 | + $errors = $this->_model->setParameters( |
| 425 | + ['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'] |
| 426 | + )->setSource( |
| 427 | + $source |
| 428 | + )->validateData(); |
| 429 | + |
| 430 | + $this->assertEmpty($errors->getAllErrors(), 'Assert that import validation returns no errors'); |
| 431 | + } |
387 | 432 | }
|
0 commit comments