Skip to content

Commit c721ae4

Browse files
committed
cover changes with unit test
1 parent c983d41 commit c721ae4

File tree

1 file changed

+111
-83
lines changed

1 file changed

+111
-83
lines changed

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

Lines changed: 111 additions & 83 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' => [
@@ -445,31 +451,23 @@ protected function _getSuperAttributes()
445451
}
446452

447453
/**
454+
* Verify save mtethod
455+
*
448456
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
449457
*/
450458
public function testSaveData()
451459
{
452460
$newSkus = array_change_key_case([
453-
'configurableskuI22' =>
454-
[$this->productEntityLinkField => 1, 'type_id' => 'configurable', 'attr_set_code' => 'Default'],
455-
'testconf2-attr2val1-testattr3v1' =>
456-
[$this->productEntityLinkField => 2, 'type_id' => 'simple', 'attr_set_code' => 'Default'],
457-
'testconf2-attr2val1-testattr30v1' =>
458-
[$this->productEntityLinkField => 20, 'type_id' => 'simple', 'attr_set_code' => 'Default'],
459-
'testconf2-attr2val1-testattr3v2' =>
460-
[$this->productEntityLinkField => 3, 'type_id' => 'simple', 'attr_set_code' => 'Default'],
461-
'testSimple' =>
462-
[$this->productEntityLinkField => 4, 'type_id' => 'simple', 'attr_set_code' => 'Default'],
463-
'testSimpleToSkip' =>
464-
[$this->productEntityLinkField => 5, 'type_id' => 'simple', 'attr_set_code' => 'Default'],
465-
'configurableskuI22withoutLabels' =>
466-
[$this->productEntityLinkField => 6, 'type_id' => 'configurable', 'attr_set_code' => 'Default'],
467-
'configurableskuI22withoutVariations' =>
468-
[$this->productEntityLinkField => 7, 'type_id' => 'configurable', 'attr_set_code' => 'Default'],
469-
'configurableskuI22Duplicated' =>
470-
[$this->productEntityLinkField => 8, 'type_id' => 'configurable', 'attr_set_code' => 'Default'],
471-
'configurableskuI22BadPrice' =>
472-
[$this->productEntityLinkField => 9, 'type_id' => 'configurable', 'attr_set_code' => 'Default'],
461+
'configurableskuI22' => [$this->productEntityLinkField => 1, 'type_id' => 'configurable', 'attr_set_code' => 'Default'],
462+
'testconf2-attr2val1-testattr3v1' => [$this->productEntityLinkField => 2, 'type_id' => 'simple', 'attr_set_code' => 'Default'],
463+
'testconf2-attr2val1-testattr30v1' => [$this->productEntityLinkField => 20, 'type_id' => 'simple', 'attr_set_code' => 'Default'],
464+
'testconf2-attr2val1-testattr3v2' => [$this->productEntityLinkField => 3, 'type_id' => 'simple', 'attr_set_code' => 'Default'],
465+
'testSimple' => [$this->productEntityLinkField => 4, 'type_id' => 'simple', 'attr_set_code' => 'Default'],
466+
'testSimpleToSkip' => [$this->productEntityLinkField => 5, 'type_id' => 'simple', 'attr_set_code' => 'Default'],
467+
'configurableskuI22withoutLabels' => [$this->productEntityLinkField => 6, 'type_id' => 'configurable', 'attr_set_code' => 'Default'],
468+
'configurableskuI22withoutVariations' => [$this->productEntityLinkField => 7, 'type_id' => 'configurable', 'attr_set_code' => 'Default'],
469+
'configurableskuI22Duplicated' => [$this->productEntityLinkField => 8, 'type_id' => 'configurable', 'attr_set_code' => 'Default'],
470+
'configurableskuI22BadPrice' => [$this->productEntityLinkField => 9, 'type_id' => 'configurable', 'attr_set_code' => 'Default'],
473471
]);
474472
$this->_entityModel->expects($this->any())
475473
->method('getNewSku')
@@ -527,6 +525,8 @@ public function testSaveData()
527525
}
528526

529527
/**
528+
* Callback for is row allowed to import
529+
*
530530
* @param $rowData
531531
* @param $rowNum
532532
* @return bool
@@ -540,72 +540,28 @@ public function isRowAllowedToImport($rowData, $rowNum)
540540
return true;
541541
}
542542

543-
public function testIsRowValid()
543+
/**
544+
* Verify is row valid method
545+
*
546+
* @dataProvider getProductDataIsValidRow
547+
* @param array $productData
548+
* @return void
549+
*/
550+
public function testIsRowValid(array $productData): void
544551
{
545552
$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-
];
566553
// Checking that variations' field names are case-insensitive with this
567554
// product.
568555
$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;
556+
$productData['caseInsencitiveProduct']['sku'] = $caseInsensitiveSKU;
557+
$bunch[] = $productData['bad_product'];
558+
$bunch[] = $productData['caseInsencitiveProduct'];
591559
// Set _attributes to avoid error in Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType.
592560
$this->setPropertyValue($this->configurable, '_attributes', [
593-
$badProduct[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
561+
$productData['bad_product'][\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
594562
]);
595563
// 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-
);
564+
$this->setPropertyValue($this->configurable,'_superAttributes', $productData['super_attributes']);
609565

610566
foreach ($bunch as $rowData) {
611567
$result = $this->configurable->isRowValid($rowData, 0, !isset($this->_oldSku[$rowData['sku']]));
@@ -616,7 +572,77 @@ public function testIsRowValid()
616572
}
617573
}
618574

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

651677
/**
678+
* Row validation Data Provider
679+
*
652680
* @return array
653681
*/
654-
public function rowValidationDataProvider()
682+
public function rowValidationDataProvider(): array
655683
{
656684
return [
657685
'duplicateProduct' => [

0 commit comments

Comments
 (0)