6
6
7
7
namespace Magento \CatalogImportExport \Test \Unit \Model \Import ;
8
8
9
+ use Magento \CatalogImportExport \Model \Import \Product ;
9
10
use Magento \CatalogImportExport \Model \Import \Product \ImageTypeProcessor ;
10
11
use Magento \Framework \App \Filesystem \DirectoryList ;
11
12
use Magento \ImportExport \Model \Import ;
12
- use PHPUnit \Framework \MockObject \MockObject ;
13
13
14
14
/**
15
15
* Class ProductTest
@@ -147,7 +147,7 @@ class ProductTest extends \Magento\ImportExport\Test\Unit\Model\Import\AbstractI
147
147
// @codingStandardsIgnoreEnd
148
148
protected $ taxClassProcessor ;
149
149
150
- /** @var \Magento\CatalogImportExport\Model\Import\ Product */
150
+ /** @var Product */
151
151
protected $ importProduct ;
152
152
153
153
/**
@@ -345,7 +345,7 @@ protected function setUp()
345
345
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
346
346
347
347
$ this ->importProduct = $ objectManager ->getObject (
348
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::class,
348
+ Product::class,
349
349
[
350
350
'jsonHelper ' => $ this ->jsonHelper ,
351
351
'importExportData ' => $ this ->importExportData ,
@@ -387,7 +387,7 @@ protected function setUp()
387
387
'imageTypeProcessor ' => $ this ->imageTypeProcessor
388
388
]
389
389
);
390
- $ reflection = new \ReflectionClass (\ Magento \ CatalogImportExport \ Model \ Import \ Product::class);
390
+ $ reflection = new \ReflectionClass (Product::class);
391
391
$ reflectionProperty = $ reflection ->getProperty ('metadataPool ' );
392
392
$ reflectionProperty ->setAccessible (true );
393
393
$ reflectionProperty ->setValue ($ this ->importProduct , $ metadataPoolMock );
@@ -629,7 +629,7 @@ public function testGetEmptyAttributeValueConstantFromParameters()
629
629
630
630
public function testDeleteProductsForReplacement ()
631
631
{
632
- $ importProduct = $ this ->getMockBuilder (\ Magento \ CatalogImportExport \ Model \ Import \ Product::class)
632
+ $ importProduct = $ this ->getMockBuilder (Product::class)
633
633
->disableOriginalConstructor ()
634
634
->setMethods ([
635
635
'setParameters ' , '_deleteProducts '
@@ -695,7 +695,7 @@ public function testValidateRowIsAlreadyValidated()
695
695
*/
696
696
public function testValidateRow ($ rowScope , $ oldSku , $ expectedResult , $ behaviour = Import::BEHAVIOR_DELETE )
697
697
{
698
- $ importProduct = $ this ->getMockBuilder (\ Magento \ CatalogImportExport \ Model \ Import \ Product::class)
698
+ $ importProduct = $ this ->getMockBuilder (Product::class)
699
699
->disableOriginalConstructor ()
700
700
->setMethods (['getBehavior ' , 'getRowScope ' , 'getErrorAggregator ' ])
701
701
->getMock ();
@@ -707,7 +707,7 @@ public function testValidateRow($rowScope, $oldSku, $expectedResult, $behaviour
707
707
->method ('getErrorAggregator ' )
708
708
->willReturn ($ this ->getErrorAggregatorObject ());
709
709
$ importProduct ->expects ($ this ->once ())->method ('getRowScope ' )->willReturn ($ rowScope );
710
- $ skuKey = \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU ;
710
+ $ skuKey = Product::COL_SKU ;
711
711
$ rowData = [
712
712
$ skuKey => 'sku ' ,
713
713
];
@@ -719,22 +719,22 @@ public function testValidateRow($rowScope, $oldSku, $expectedResult, $behaviour
719
719
720
720
public function testValidateRowDeleteBehaviourAddRowErrorCall ()
721
721
{
722
- $ importProduct = $ this ->getMockBuilder (\ Magento \ CatalogImportExport \ Model \ Import \ Product::class)
722
+ $ importProduct = $ this ->getMockBuilder (Product::class)
723
723
->disableOriginalConstructor ()
724
724
->setMethods (['getBehavior ' , 'getRowScope ' , 'addRowError ' , 'getErrorAggregator ' ])
725
725
->getMock ();
726
726
727
727
$ importProduct ->expects ($ this ->exactly (2 ))->method ('getBehavior ' )
728
728
->willReturn (\Magento \ImportExport \Model \Import::BEHAVIOR_DELETE );
729
729
$ importProduct ->expects ($ this ->once ())->method ('getRowScope ' )
730
- ->willReturn (\ Magento \ CatalogImportExport \ Model \ Import \ Product::SCOPE_DEFAULT );
730
+ ->willReturn (Product::SCOPE_DEFAULT );
731
731
$ importProduct ->expects ($ this ->once ())->method ('addRowError ' );
732
732
$ importProduct ->method ('getErrorAggregator ' )
733
733
->willReturn (
734
734
$ this ->getErrorAggregatorObject (['addRowToSkip ' ])
735
735
);
736
736
$ rowData = [
737
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => 'sku ' ,
737
+ Product::COL_SKU => 'sku ' ,
738
738
];
739
739
740
740
$ importProduct ->validateRow ($ rowData , 0 );
@@ -745,7 +745,7 @@ public function testValidateRowValidatorCheck()
745
745
$ messages = ['validator message ' ];
746
746
$ this ->validator ->expects ($ this ->once ())->method ('getMessages ' )->willReturn ($ messages );
747
747
$ rowData = [
748
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => 'sku ' ,
748
+ Product::COL_SKU => 'sku ' ,
749
749
];
750
750
$ rowNum = 0 ;
751
751
$ this ->importProduct ->validateRow ($ rowData , $ rowNum );
@@ -847,7 +847,7 @@ public function getStoreIdByCodeDataProvider()
847
847
return [
848
848
[
849
849
'$storeCode ' => null ,
850
- '$expectedResult ' => \ Magento \ CatalogImportExport \ Model \ Import \ Product::SCOPE_DEFAULT ,
850
+ '$expectedResult ' => Product::SCOPE_DEFAULT ,
851
851
],
852
852
[
853
853
'$storeCode ' => 'value ' ,
@@ -868,8 +868,8 @@ public function testValidateRowCheckSpecifiedSku($sku, $expectedError)
868
868
869
869
$ rowNum = 0 ;
870
870
$ rowData = [
871
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => $ sku ,
872
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_STORE => '' ,
871
+ Product::COL_SKU => $ sku ,
872
+ Product::COL_STORE => '' ,
873
873
];
874
874
875
875
$ this ->storeResolver ->method ('getStoreCodeToId ' )->willReturn (null );
@@ -881,7 +881,7 @@ public function testValidateRowCheckSpecifiedSku($sku, $expectedError)
881
881
$ importProduct
882
882
->expects ($ this ->once ())
883
883
->method ('getRowScope ' )
884
- ->willReturn (\ Magento \ CatalogImportExport \ Model \ Import \ Product::SCOPE_STORE );
884
+ ->willReturn (Product::SCOPE_STORE );
885
885
$ importProduct ->expects ($ this ->at (1 ))->method ('addRowError ' )->with ($ expectedError , $ rowNum )->willReturn (null );
886
886
887
887
$ importProduct ->validateRow ($ rowData , $ rowNum );
@@ -895,7 +895,7 @@ public function testValidateRowProcessEntityIncrement()
895
895
$ errorAggregator ->method ('isRowInvalid ' )->willReturn (true );
896
896
$ this ->setPropertyValue ($ this ->importProduct , '_processedEntitiesCount ' , $ count );
897
897
$ this ->setPropertyValue ($ this ->importProduct , 'errorAggregator ' , $ errorAggregator );
898
- $ rowData = [\ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => false ];
898
+ $ rowData = [Product::COL_SKU => false ];
899
899
//suppress validator
900
900
$ this ->_setValidatorMockInImportProduct ($ this ->importProduct );
901
901
$ this ->importProduct ->validateRow ($ rowData , $ rowNum );
@@ -912,7 +912,7 @@ public function testValidateRowValidateExistingProductTypeAddNewSku()
912
912
$ sku = 'sku ' ;
913
913
$ rowNum = 0 ;
914
914
$ rowData = [
915
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => $ sku ,
915
+ Product::COL_SKU => $ sku ,
916
916
];
917
917
$ oldSku = [
918
918
$ sku => [
@@ -953,7 +953,7 @@ public function testValidateRowValidateExistingProductTypeAddErrorRowCall()
953
953
$ sku = 'sku ' ;
954
954
$ rowNum = 0 ;
955
955
$ rowData = [
956
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => $ sku ,
956
+ Product::COL_SKU => $ sku ,
957
957
];
958
958
$ oldSku = [
959
959
$ sku => [
@@ -978,27 +978,31 @@ public function testValidateRowValidateExistingProductTypeAddErrorRowCall()
978
978
979
979
/**
980
980
* @dataProvider validateRowValidateNewProductTypeAddRowErrorCallDataProvider
981
+ * @param string $colType
982
+ * @param string $productTypeModelsColType
983
+ * @param string $colAttrSet
984
+ * @param string $attrSetNameToIdColAttrSet
985
+ * @param string $error
981
986
*/
982
987
public function testValidateRowValidateNewProductTypeAddRowErrorCall (
983
988
$ colType ,
984
989
$ productTypeModelsColType ,
985
990
$ colAttrSet ,
986
991
$ attrSetNameToIdColAttrSet ,
987
992
$ error
988
- )
989
- {
993
+ ) {
990
994
$ sku = 'sku ' ;
991
995
$ rowNum = 0 ;
992
996
$ rowData = [
993
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => $ sku ,
994
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_TYPE => $ colType ,
995
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_ATTR_SET => $ colAttrSet ,
997
+ Product::COL_SKU => $ sku ,
998
+ Product::COL_TYPE => $ colType ,
999
+ Product::COL_ATTR_SET => $ colAttrSet ,
996
1000
];
997
1001
$ _attrSetNameToId = [
998
- $ rowData [\ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_ATTR_SET ] => $ attrSetNameToIdColAttrSet ,
1002
+ $ rowData [Product::COL_ATTR_SET ] => $ attrSetNameToIdColAttrSet ,
999
1003
];
1000
1004
$ _productTypeModels = [
1001
- $ rowData [\ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_TYPE ] => $ productTypeModelsColType ,
1005
+ $ rowData [Product::COL_TYPE ] => $ productTypeModelsColType ,
1002
1006
];
1003
1007
$ oldSku = [
1004
1008
$ sku => null ,
@@ -1026,25 +1030,25 @@ public function testValidateRowValidateNewProductTypeGetNewSkuCall()
1026
1030
$ sku = 'sku ' ;
1027
1031
$ rowNum = 0 ;
1028
1032
$ rowData = [
1029
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => $ sku ,
1030
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_TYPE => 'value ' ,
1031
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_ATTR_SET => 'value ' ,
1033
+ Product::COL_SKU => $ sku ,
1034
+ Product::COL_TYPE => 'value ' ,
1035
+ Product::COL_ATTR_SET => 'value ' ,
1032
1036
];
1033
1037
$ _productTypeModels = [
1034
- $ rowData [\ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_TYPE ] => 'value ' ,
1038
+ $ rowData [Product::COL_TYPE ] => 'value ' ,
1035
1039
];
1036
1040
$ oldSku = [
1037
1041
$ sku => null ,
1038
1042
];
1039
1043
$ _attrSetNameToId = [
1040
- $ rowData [\ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_ATTR_SET ] => 'attr_set_code_val '
1044
+ $ rowData [Product::COL_ATTR_SET ] => 'attr_set_code_val '
1041
1045
];
1042
1046
$ expectedData = [
1043
1047
'entity_id ' => null ,
1044
- 'type_id ' => $ rowData [\ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_TYPE ],//value
1048
+ 'type_id ' => $ rowData [Product::COL_TYPE ],//value
1045
1049
//attr_set_id_val
1046
- 'attr_set_id ' => $ _attrSetNameToId [$ rowData [\ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_ATTR_SET ]],
1047
- 'attr_set_code ' => $ rowData [\ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_ATTR_SET ],//value
1050
+ 'attr_set_id ' => $ _attrSetNameToId [$ rowData [Product::COL_ATTR_SET ]],
1051
+ 'attr_set_code ' => $ rowData [Product::COL_ATTR_SET ],//value
1048
1052
'row_id ' => null
1049
1053
];
1050
1054
$ importProduct = $ this ->createModelMockWithErrorAggregator (
@@ -1080,17 +1084,17 @@ public function testValidateRowSetAttributeSetCodeIntoRowData()
1080
1084
$ sku = 'sku ' ;
1081
1085
$ rowNum = 0 ;
1082
1086
$ rowData = [
1083
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => $ sku ,
1084
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_ATTR_SET => 'col_attr_set_val ' ,
1087
+ Product::COL_SKU => $ sku ,
1088
+ Product::COL_ATTR_SET => 'col_attr_set_val ' ,
1085
1089
];
1086
1090
$ expectedAttrSetCode = 'new_attr_set_code ' ;
1087
1091
$ newSku = [
1088
1092
'attr_set_code ' => $ expectedAttrSetCode ,
1089
1093
'type_id ' => 'new_type_id_val ' ,
1090
1094
];
1091
1095
$ expectedRowData = [
1092
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => $ sku ,
1093
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_ATTR_SET => $ newSku ['attr_set_code ' ],
1096
+ Product::COL_SKU => $ sku ,
1097
+ Product::COL_ATTR_SET => $ newSku ['attr_set_code ' ],
1094
1098
];
1095
1099
$ oldSku = [
1096
1100
$ sku => [
@@ -1124,8 +1128,8 @@ public function testValidateValidateOptionEntity()
1124
1128
$ sku = 'sku ' ;
1125
1129
$ rowNum = 0 ;
1126
1130
$ rowData = [
1127
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU => $ sku ,
1128
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_ATTR_SET => 'col_attr_set_val ' ,
1131
+ Product::COL_SKU => $ sku ,
1132
+ Product::COL_ATTR_SET => 'col_attr_set_val ' ,
1129
1133
];
1130
1134
$ oldSku = [
1131
1135
$ sku => [
@@ -1377,7 +1381,7 @@ public function validateRowDataProvider()
1377
1381
{
1378
1382
return [
1379
1383
[
1380
- '$rowScope ' => \ Magento \ CatalogImportExport \ Model \ Import \ Product::SCOPE_DEFAULT ,
1384
+ '$rowScope ' => Product::SCOPE_DEFAULT ,
1381
1385
'$oldSku ' => null ,
1382
1386
'$expectedResult ' => false ,
1383
1387
],
@@ -1392,12 +1396,12 @@ public function validateRowDataProvider()
1392
1396
'$expectedResult ' => true ,
1393
1397
],
1394
1398
[
1395
- '$rowScope ' => \ Magento \ CatalogImportExport \ Model \ Import \ Product::SCOPE_DEFAULT ,
1399
+ '$rowScope ' => Product::SCOPE_DEFAULT ,
1396
1400
'$oldSku ' => true ,
1397
1401
'$expectedResult ' => true ,
1398
1402
],
1399
1403
[
1400
- '$rowScope ' => \ Magento \ CatalogImportExport \ Model \ Import \ Product::SCOPE_DEFAULT ,
1404
+ '$rowScope ' => Product::SCOPE_DEFAULT ,
1401
1405
'$oldSku ' => null ,
1402
1406
'$expectedResult ' => false ,
1403
1407
'$behaviour ' => Import::BEHAVIOR_REPLACE
@@ -1418,7 +1422,7 @@ public function isAttributeValidAssertAttrValidDataProvider()
1418
1422
'$rowData ' => [
1419
1423
'code ' => str_repeat (
1420
1424
'a ' ,
1421
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::DB_MAX_VARCHAR_LENGTH - 1
1425
+ Product::DB_MAX_VARCHAR_LENGTH - 1
1422
1426
),
1423
1427
],
1424
1428
],
@@ -1471,7 +1475,7 @@ public function isAttributeValidAssertAttrValidDataProvider()
1471
1475
'$rowData ' => [
1472
1476
'code ' => str_repeat (
1473
1477
'a ' ,
1474
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::DB_MAX_TEXT_LENGTH - 1
1478
+ Product::DB_MAX_TEXT_LENGTH - 1
1475
1479
),
1476
1480
],
1477
1481
],
@@ -1491,7 +1495,7 @@ public function isAttributeValidAssertAttrInvalidDataProvider()
1491
1495
'$rowData ' => [
1492
1496
'code ' => str_repeat (
1493
1497
'a ' ,
1494
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::DB_MAX_VARCHAR_LENGTH + 1
1498
+ Product::DB_MAX_VARCHAR_LENGTH + 1
1495
1499
),
1496
1500
],
1497
1501
],
@@ -1544,7 +1548,7 @@ public function isAttributeValidAssertAttrInvalidDataProvider()
1544
1548
'$rowData ' => [
1545
1549
'code ' => str_repeat (
1546
1550
'a ' ,
1547
- \ Magento \ CatalogImportExport \ Model \ Import \ Product::DB_MAX_TEXT_LENGTH + 1
1551
+ Product::DB_MAX_TEXT_LENGTH + 1
1548
1552
),
1549
1553
],
1550
1554
],
@@ -1556,30 +1560,30 @@ public function isAttributeValidAssertAttrInvalidDataProvider()
1556
1560
*/
1557
1561
public function getRowScopeDataProvider ()
1558
1562
{
1559
- $ colSku = \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_SKU ;
1560
- $ colStore = \ Magento \ CatalogImportExport \ Model \ Import \ Product::COL_STORE ;
1563
+ $ colSku = Product::COL_SKU ;
1564
+ $ colStore = Product::COL_STORE ;
1561
1565
1562
1566
return [
1563
1567
[
1564
1568
'$rowData ' => [
1565
1569
$ colSku => null ,
1566
1570
$ colStore => 'store ' ,
1567
1571
],
1568
- '$expectedResult ' => \ Magento \ CatalogImportExport \ Model \ Import \ Product::SCOPE_STORE
1572
+ '$expectedResult ' => Product::SCOPE_STORE
1569
1573
],
1570
1574
[
1571
1575
'$rowData ' => [
1572
1576
$ colSku => 'sku ' ,
1573
1577
$ colStore => null ,
1574
1578
],
1575
- '$expectedResult ' => \ Magento \ CatalogImportExport \ Model \ Import \ Product::SCOPE_DEFAULT
1579
+ '$expectedResult ' => Product::SCOPE_DEFAULT
1576
1580
],
1577
1581
[
1578
1582
'$rowData ' => [
1579
1583
$ colSku => 'sku ' ,
1580
1584
$ colStore => 'store ' ,
1581
1585
],
1582
- '$expectedResult ' => \ Magento \ CatalogImportExport \ Model \ Import \ Product::SCOPE_STORE
1586
+ '$expectedResult ' => Product::SCOPE_STORE
1583
1587
],
1584
1588
];
1585
1589
}
@@ -1656,7 +1660,7 @@ protected function overrideMethod(&$object, $methodName, array $parameters = [])
1656
1660
*
1657
1661
* @see _rewriteGetOptionEntityInImportProduct()
1658
1662
* @see _setValidatorMockInImportProduct()
1659
- * @param \Magento\CatalogImportExport\Model\Import\ Product
1663
+ * @param Product
1660
1664
* Param should go with rewritten getOptionEntity method.
1661
1665
* @return \Magento\CatalogImportExport\Model\Import\Product\Option|\PHPUnit_Framework_MockObject_MockObject
1662
1666
*/
@@ -1674,7 +1678,7 @@ private function _suppressValidateRowOptionValidatorInvalidRows($importProduct)
1674
1678
* Used in group of validateRow method's tests.
1675
1679
* Set validator mock in importProduct, return true for isValid method.
1676
1680
*
1677
- * @param \Magento\CatalogImportExport\Model\Import\ Product
1681
+ * @param Product
1678
1682
* @return \Magento\CatalogImportExport\Model\Import\Product\Validator|\PHPUnit_Framework_MockObject_MockObject
1679
1683
*/
1680
1684
private function _setValidatorMockInImportProduct ($ importProduct )
@@ -1689,7 +1693,7 @@ private function _setValidatorMockInImportProduct($importProduct)
1689
1693
* Used in group of validateRow method's tests.
1690
1694
* Make getOptionEntity return option mock.
1691
1695
*
1692
- * @param \Magento\CatalogImportExport\Model\Import\ Product
1696
+ * @param Product
1693
1697
* Param should go with rewritten getOptionEntity method.
1694
1698
* @return \Magento\CatalogImportExport\Model\Import\Product\Option|\PHPUnit_Framework_MockObject_MockObject
1695
1699
*/
@@ -1711,7 +1715,7 @@ private function _rewriteGetOptionEntityInImportProduct($importProduct)
1711
1715
protected function createModelMockWithErrorAggregator (array $ methods = [], array $ errorAggregatorMethods = [])
1712
1716
{
1713
1717
$ methods [] = 'getErrorAggregator ' ;
1714
- $ importProduct = $ this ->getMockBuilder (\ Magento \ CatalogImportExport \ Model \ Import \ Product::class)
1718
+ $ importProduct = $ this ->getMockBuilder (Product::class)
1715
1719
->disableOriginalConstructor ()
1716
1720
->setMethods ($ methods )
1717
1721
->getMock ();
0 commit comments