Skip to content

Commit 3bf7d4f

Browse files
ENGCOM-6141: Limit the php explode to 2 to prevent extra '=' sign content in the a… #25194
2 parents 66ee4c1 + b0b3118 commit 3bf7d4f

File tree

2 files changed

+104
-67
lines changed

2 files changed

+104
-67
lines changed

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ protected function _parseVariations($rowData)
573573

574574
$fieldAndValuePairs = [];
575575
foreach ($fieldAndValuePairsText as $nameAndValue) {
576-
$nameAndValue = explode(ImportProduct::PAIR_NAME_VALUE_SEPARATOR, $nameAndValue);
576+
$nameAndValue = explode(ImportProduct::PAIR_NAME_VALUE_SEPARATOR, $nameAndValue, 2);
577577
if (!empty($nameAndValue)) {
578578
$value = isset($nameAndValue[1]) ? trim($nameAndValue[1]) : '';
579579
// Ignoring field names' case.

app/code/Magento/ConfigurableImportExport/Test/Unit/Model/Import/Product/Type/ConfigurableTest.php

Lines changed: 103 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Magento\ConfigurableImportExport;
1010

1111
/**
12-
* Class ConfigurableTest
13-
* @package Magento\ConfigurableImportExport\Test\Unit\Model\Import\Product\Type
12+
* Configurable import export tests
13+
*
1414
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1515
*/
1616
class ConfigurableTest extends \Magento\ImportExport\Test\Unit\Model\Import\AbstractImportTestCase
@@ -78,6 +78,8 @@ class ConfigurableTest extends \Magento\ImportExport\Test\Unit\Model\Import\Abst
7878
protected $productEntityLinkField = 'entity_id';
7979

8080
/**
81+
* @inheritdoc
82+
*
8183
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
8284
*/
8385
protected function setUp()
@@ -270,10 +272,12 @@ protected function setUp()
270272
}
271273

272274
/**
275+
* Bunches data provider
276+
*
273277
* @return array
274278
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
275279
*/
276-
protected function _getBunch()
280+
protected function _getBunch(): array
277281
{
278282
return [[
279283
'sku' => 'configurableskuI22',
@@ -393,9 +397,11 @@ protected function _getBunch()
393397
}
394398

395399
/**
400+
* Super attributes data provider
401+
*
396402
* @return array
397403
*/
398-
protected function _getSuperAttributes()
404+
protected function _getSuperAttributes(): array
399405
{
400406
return [
401407
'testattr2' => [
@@ -404,7 +410,6 @@ protected function _getSuperAttributes()
404410
'attribute_code' => 'testattr2',
405411
'is_global' => '1',
406412
'is_visible' => '1',
407-
'is_static' => '0',
408413
'is_required' => '0',
409414
'is_unique' => '0',
410415
'frontend_label' => 'testattr2',
@@ -426,7 +431,6 @@ protected function _getSuperAttributes()
426431
'attribute_code' => 'testattr3',
427432
'is_global' => '1',
428433
'is_visible' => '1',
429-
'is_static' => '0',
430434
'is_required' => '0',
431435
'is_unique' => '0',
432436
'frontend_label' => 'testattr3',
@@ -445,6 +449,8 @@ protected function _getSuperAttributes()
445449
}
446450

447451
/**
452+
* Verify save mtethod
453+
*
448454
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
449455
*/
450456
public function testSaveData()
@@ -527,6 +533,8 @@ public function testSaveData()
527533
}
528534

529535
/**
536+
* Callback for is row allowed to import
537+
*
530538
* @param $rowData
531539
* @param $rowNum
532540
* @return bool
@@ -540,83 +548,110 @@ public function isRowAllowedToImport($rowData, $rowNum)
540548
return true;
541549
}
542550

543-
public function testIsRowValid()
551+
/**
552+
* Verify is row valid method
553+
*
554+
* @dataProvider getProductDataIsValidRow
555+
* @param array $productData
556+
* @return void
557+
*/
558+
public function testIsRowValid(array $productData): void
544559
{
545560
$bunch = $this->_getBunch();
546-
$badProduct = [
547-
'sku' => 'configurableskuI22BadPrice',
548-
'store_view_code' => null,
549-
'attribute_set_code' => 'Default',
550-
'product_type' => 'configurable',
551-
'name' => 'Configurable Product 21 BadPrice',
552-
'product_websites' => 'website_1',
553-
'configurable_variation_labels' => 'testattr2=Select Color, testattr3=Select Size',
554-
'configurable_variations' => 'sku=testconf2-attr2val1-testattr3v1,'
555-
. 'testattr2=attr2val1_DOESNT_EXIST,'
556-
. 'testattr3=testattr3v1,'
557-
. 'display=1|sku=testconf2-attr2val1-testattr3v2,'
558-
. 'testattr2=attr2val1,'
559-
. 'testattr3=testattr3v2,'
560-
. 'display=0',
561-
'_store' => null,
562-
'_attribute_set' => 'Default',
563-
'_type' => 'configurable',
564-
'_product_websites' => 'website_1',
565-
];
566561
// Checking that variations' field names are case-insensitive with this
567562
// product.
568563
$caseInsensitiveSKU = 'configurableskuI22CaseInsensitive';
569-
$caseInsensitiveProduct = [
570-
'sku' => $caseInsensitiveSKU,
571-
'store_view_code' => null,
572-
'attribute_set_code' => 'Default',
573-
'product_type' => 'configurable',
574-
'name' => 'Configurable Product 21',
575-
'product_websites' => 'website_1',
576-
'configurable_variation_labels' => 'testattr2=Select Color, testattr3=Select Size',
577-
'configurable_variations' => 'SKU=testconf2-attr2val1-testattr3v1,'
578-
. 'testattr2=attr2val1,'
579-
. 'testattr3=testattr3v1,'
580-
. 'display=1|sku=testconf2-attr2val1-testattr3v2,'
581-
. 'testattr2=attr2val1,'
582-
. 'testattr3=testattr3v2,'
583-
. 'display=0',
584-
'_store' => null,
585-
'_attribute_set' => 'Default',
586-
'_type' => 'configurable',
587-
'_product_websites' => 'website_1',
588-
];
589-
$bunch[] = $badProduct;
590-
$bunch[] = $caseInsensitiveProduct;
564+
$productData['caseInsencitiveProduct']['sku'] = $caseInsensitiveSKU;
565+
$bunch[] = $productData['bad_product'];
566+
$bunch[] = $productData['caseInsencitiveProduct'];
591567
// Set _attributes to avoid error in Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType.
592568
$this->setPropertyValue($this->configurable, '_attributes', [
593-
$badProduct[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
569+
$productData['bad_product'][\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
594570
]);
595571
// Avoiding errors about attributes not being super
596-
$this->setPropertyValue(
597-
$this->configurable,
598-
'_superAttributes',
599-
[
600-
'testattr2' => ['options' => ['attr2val1' => 1]],
601-
'testattr3' => [
602-
'options' => [
603-
'testattr3v2' => 1,
604-
'testattr3v1' => 1,
605-
],
606-
],
607-
]
608-
);
572+
$this->setPropertyValue($this->configurable, '_superAttributes', $productData['super_attributes']);
609573

610574
foreach ($bunch as $rowData) {
611-
$result = $this->configurable->isRowValid($rowData, 0, !isset($this->_oldSku[$rowData['sku']]));
575+
$result = $this->configurable->isRowValid($rowData, 0, false);
612576
$this->assertNotNull($result);
613577
if ($rowData['sku'] === $caseInsensitiveSKU) {
614578
$this->assertTrue($result);
615579
}
616580
}
617581
}
618582

619-
public function testRowValidationForNumericalSkus()
583+
/**
584+
*
585+
* Data provider for isValidRows test.
586+
*
587+
* @return array
588+
*/
589+
public function getProductDataIsValidRow(): array
590+
{
591+
return [
592+
[
593+
[
594+
'bad_product' => [
595+
'sku' => 'configurableskuI22BadPrice',
596+
'store_view_code' => null,
597+
'attribute_set_code' => 'Default',
598+
'product_type' => 'configurable',
599+
'name' => 'Configurable Product 21 BadPrice',
600+
'product_websites' => 'website_1',
601+
'configurable_variation_labels' => 'testattr2=Select Color, testattr3=Select Size',
602+
'configurable_variations' => 'sku=testconf2-attr2val1-testattr3v1,'
603+
. 'testattr2=attr2val1_DOESNT_EXIST,'
604+
. 'testattr3=testattr3v1,'
605+
. 'display=1|sku=testconf2-attr2val1-testattr3v2,'
606+
. 'testattr2=attr2val1,'
607+
. 'testattr3=testattr3v2,'
608+
. 'display=0',
609+
'_store' => null,
610+
'_attribute_set' => 'Default',
611+
'_type' => 'configurable',
612+
'_product_websites' => 'website_1',
613+
],
614+
'caseInsencitiveProduct' => [
615+
'sku' => '',
616+
'store_view_code' => null,
617+
'attribute_set_code' => 'Default',
618+
'product_type' => 'configurable',
619+
'name' => 'Configurable Product 21',
620+
'product_websites' => 'website_1',
621+
'configurable_variation_labels' => 'testattr2=Select Color, testattr3=Select Size',
622+
'configurable_variations' => 'SKU=testconf2-attr2val1-testattr3v1,'
623+
. 'testattr2=attr2val1,'
624+
. 'testattr3=testattr3v1=sx=sl,'
625+
. 'display=1|sku=testconf2-attr2val1-testattr3v2,'
626+
. 'testattr2=attr2val1,'
627+
. 'testattr3=testattr3v2,'
628+
. 'display=0',
629+
'_store' => null,
630+
'_attribute_set' => 'Default',
631+
'_type' => 'configurable',
632+
'_product_websites' => 'website_1',
633+
],
634+
'super_attributes' =>
635+
[
636+
'testattr2' => ['options' => ['attr2val1' => 1]],
637+
'testattr3' => [
638+
'options' => [
639+
'testattr3v2' => 1,
640+
'testattr3v1=sx=sl' => 1,
641+
],
642+
],
643+
]
644+
]
645+
]
646+
];
647+
}
648+
649+
/**
650+
* Verify row validation with numeric skus
651+
*
652+
* @return void
653+
*/
654+
public function testRowValidationForNumericalSkus(): void
620655
{
621656
// Set _attributes to avoid error in Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType.
622657
$this->setPropertyValue($this->configurable, '_attributes', [
@@ -649,9 +684,11 @@ public function testRowValidationForNumericalSkus()
649684
}
650685

651686
/**
687+
* Row validation Data Provider
688+
*
652689
* @return array
653690
*/
654-
public function rowValidationDataProvider()
691+
public function rowValidationDataProvider(): array
655692
{
656693
return [
657694
'duplicateProduct' => [

0 commit comments

Comments
 (0)