Skip to content

Commit af28a78

Browse files
committed
ACP2E-957: Re: Problem in import products module (Merchant made a patch & asking us to fix in core magento)
1 parent dbe3986 commit af28a78

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest/ProductUrlKeyTest.php

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
namespace Magento\CatalogImportExport\Model\Import\ProductTest;
99

1010
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
1112
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
1213
use Magento\CatalogImportExport\Model\Import\ProductTestBase;
1314
use Magento\Framework\App\Filesystem\DirectoryList;
15+
use Magento\Framework\Exception\LocalizedException;
1416
use Magento\Framework\Filesystem;
1517
use Magento\ImportExport\Model\Import;
1618
use Magento\ImportExport\Model\Import\Source\Csv;
19+
use Magento\TestFramework\Fixture\Config;
20+
use Magento\TestFramework\Fixture\DataFixture;
1721

1822
/**
1923
* Integration test for \Magento\CatalogImportExport\Model\Import\Product class.
@@ -67,7 +71,7 @@ public function testImportWithoutUrlKeysAndName()
6771
* @dataProvider validateUrlKeysDataProvider
6872
* @param $importFile string
6973
* @param $expectedErrors array
70-
* @throws \Magento\Framework\Exception\LocalizedException
74+
* @throws LocalizedException
7175
*/
7276
public function testValidateUrlKeys($importFile, $expectedErrors)
7377
{
@@ -306,7 +310,7 @@ public function testImportWithoutUrlKeys()
306310
/**
307311
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_non_latin_url_key.php
308312
* @return void
309-
* @throws \Magento\Framework\Exception\LocalizedException
313+
* @throws LocalizedException
310314
*/
311315
public function testImportWithNonLatinUrlKeys()
312316
{
@@ -352,7 +356,7 @@ public function testImportWithNonLatinUrlKeys()
352356
* @magentoDbIsolation disabled
353357
* @magentoAppIsolation enabled
354358
* @return void
355-
* @throws \Magento\Framework\Exception\LocalizedException
359+
* @throws LocalizedException
356360
*/
357361
public function testImportWithSpacesInUrlKeys()
358362
{
@@ -384,4 +388,45 @@ public function testImportWithSpacesInUrlKeys()
384388
$this->assertEquals($productUrlKey, $productRepository->get($productSku)->getUrlKey());
385389
}
386390
}
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+
}
387432
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,product_type,store_view_code,name,price,attribute_set_code,url_key
2+
simple1,simple,,"simple 1",25,Default,1234

0 commit comments

Comments
 (0)