33
33
use Magento \Framework \App \Filesystem \DirectoryList ;
34
34
use Magento \Framework \App \ResourceConnection ;
35
35
use Magento \Framework \DB \Adapter \AdapterInterface ;
36
+ use Magento \Framework \DB \Select ;
36
37
use Magento \Framework \EntityManager \EntityMetadata ;
37
38
use Magento \Framework \EntityManager \MetadataPool ;
38
39
use Magento \Framework \Event \ManagerInterface ;
61
62
* @SuppressWarnings(PHPMD.TooManyFields)
62
63
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
63
64
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
65
+ * @SuppressWarnings(PHPMD.ExcessivePublicCount)
64
66
*/
65
67
class ProductTest extends AbstractImportTestCase
66
68
{
@@ -299,6 +301,9 @@ class ProductTest extends AbstractImportTestCase
299
301
*/
300
302
private $ driverFile ;
301
303
304
+ /** @var Select|MockObject */
305
+ protected $ select ;
306
+
302
307
/**
303
308
* @inheritDoc
304
309
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -566,6 +571,13 @@ protected function _parentObjectConstructor()
566
571
$ this ->config ->expects ($ this ->any ())->method ('getEntityType ' )->with (self ::ENTITY_TYPE_CODE )->willReturn ($ type );
567
572
568
573
$ this ->_connection = $ this ->getMockForAbstractClass (AdapterInterface::class);
574
+ $ this ->select = $ this ->getMockBuilder (Select::class)
575
+ ->disableOriginalConstructor ()
576
+ ->setMethods (['from ' , 'where ' ])
577
+ ->getMock ();
578
+ $ this ->select ->expects ($ this ->any ())->method ('from ' )->willReturnSelf ();
579
+ //$this->select->expects($this->any())->method('where')->willReturnSelf();
580
+ $ this ->_connection ->expects ($ this ->any ())->method ('select ' )->willReturn ($ this ->select );
569
581
$ this ->resource ->expects ($ this ->any ())->method ('getConnection ' )->willReturn ($ this ->_connection );
570
582
return $ this ;
571
583
}
@@ -661,8 +673,8 @@ protected function _initImagesArrayKeys()
661
673
}
662
674
663
675
/**
664
- * @return void
665
- */
676
+ * @return void
677
+ */
666
678
public function testSaveProductAttributes (): void
667
679
{
668
680
$ testTable = 'test_table ' ;
@@ -744,8 +756,8 @@ public function testIsAttributeValidAssertAttrInvalid($attrParams, $rowData): vo
744
756
}
745
757
746
758
/**
747
- * @return void
748
- */
759
+ * @return void
760
+ */
749
761
public function testGetMultipleValueSeparatorDefault (): void
750
762
{
751
763
$ this ->setPropertyValue ($ this ->importProduct , '_parameters ' , null );
@@ -756,8 +768,8 @@ public function testGetMultipleValueSeparatorDefault(): void
756
768
}
757
769
758
770
/**
759
- * @return void
760
- */
771
+ * @return void
772
+ */
761
773
public function testGetMultipleValueSeparatorFromParameters (): void
762
774
{
763
775
$ expectedSeparator = 'value ' ;
@@ -776,8 +788,8 @@ public function testGetMultipleValueSeparatorFromParameters(): void
776
788
}
777
789
778
790
/**
779
- * @return void
780
- */
791
+ * @return void
792
+ */
781
793
public function testGetEmptyAttributeValueConstantDefault (): void
782
794
{
783
795
$ this ->setPropertyValue ($ this ->importProduct , '_parameters ' , null );
@@ -788,8 +800,8 @@ public function testGetEmptyAttributeValueConstantDefault(): void
788
800
}
789
801
790
802
/**
791
- * @return void
792
- */
803
+ * @return void
804
+ */
793
805
public function testGetEmptyAttributeValueConstantFromParameters (): void
794
806
{
795
807
$ expectedSeparator = '__EMPTY__VALUE__TEST__ ' ;
@@ -808,8 +820,8 @@ public function testGetEmptyAttributeValueConstantFromParameters(): void
808
820
}
809
821
810
822
/**
811
- * @return void
812
- */
823
+ * @return void
824
+ */
813
825
public function testDeleteProductsForReplacement (): void
814
826
{
815
827
$ importProduct = $ this ->getMockBuilder (Product::class)
@@ -830,8 +842,8 @@ public function testDeleteProductsForReplacement(): void
830
842
}
831
843
832
844
/**
833
- * @return void
834
- */
845
+ * @return void
846
+ */
835
847
public function testGetMediaGalleryAttributeIdIfNotSetYet (): void
836
848
{
837
849
// reset possible existing id
@@ -903,8 +915,8 @@ public function testValidateRow($rowScope, $oldSku, $expectedResult, $behaviour
903
915
}
904
916
905
917
/**
906
- * @return void
907
- */
918
+ * @return void
919
+ */
908
920
public function testValidateRowDeleteBehaviourAddRowErrorCall (): void
909
921
{
910
922
$ importProduct = $ this ->getMockBuilder (Product::class)
@@ -929,8 +941,8 @@ public function testValidateRowDeleteBehaviourAddRowErrorCall(): void
929
941
}
930
942
931
943
/**
932
- * @return void
933
- */
944
+ * @return void
945
+ */
934
946
public function testValidateRowValidatorCheck (): void
935
947
{
936
948
$ messages = ['validator message ' ];
@@ -1100,8 +1112,8 @@ public function testValidateRowCheckSpecifiedSku($sku, $expectedError): void
1100
1112
}
1101
1113
1102
1114
/**
1103
- * @return void
1104
- */
1115
+ * @return void
1116
+ */
1105
1117
public function testValidateRowProcessEntityIncrement (): void
1106
1118
{
1107
1119
$ count = 0 ;
@@ -1118,8 +1130,8 @@ public function testValidateRowProcessEntityIncrement(): void
1118
1130
}
1119
1131
1120
1132
/**
1121
- * @return void
1122
- */
1133
+ * @return void
1134
+ */
1123
1135
public function testValidateRowValidateExistingProductTypeAddNewSku (): void
1124
1136
{
1125
1137
$ importProduct = $ this ->createModelMockWithErrorAggregator (
@@ -1167,8 +1179,8 @@ public function testValidateRowValidateExistingProductTypeAddNewSku(): void
1167
1179
}
1168
1180
1169
1181
/**
1170
- * @return void
1171
- */
1182
+ * @return void
1183
+ */
1172
1184
public function testValidateRowValidateExistingProductTypeAddErrorRowCall (): void
1173
1185
{
1174
1186
$ sku = 'sku ' ;
@@ -1249,8 +1261,8 @@ public function testValidateRowValidateNewProductTypeAddRowErrorCall(
1249
1261
}
1250
1262
1251
1263
/**
1252
- * @return void
1253
- */
1264
+ * @return void
1265
+ */
1254
1266
public function testValidateRowValidateNewProductTypeGetNewSkuCall (): void
1255
1267
{
1256
1268
$ sku = 'sku ' ;
@@ -1296,8 +1308,8 @@ public function testValidateRowValidateNewProductTypeGetNewSkuCall(): void
1296
1308
}
1297
1309
1298
1310
/**
1299
- * @return void
1300
- */
1311
+ * @return void
1312
+ */
1301
1313
public function testValidateDefaultScopeNotValidAttributesResetSku (): void
1302
1314
{
1303
1315
$ this ->validator ->expects ($ this ->once ())->method ('isAttributeValid ' )->willReturn (false );
@@ -1309,8 +1321,8 @@ public function testValidateDefaultScopeNotValidAttributesResetSku(): void
1309
1321
}
1310
1322
1311
1323
/**
1312
- * @return void
1313
- */
1324
+ * @return void
1325
+ */
1314
1326
public function testValidateRowSetAttributeSetCodeIntoRowData (): void
1315
1327
{
1316
1328
$ sku = 'sku ' ;
@@ -1360,8 +1372,8 @@ public function testValidateRowSetAttributeSetCodeIntoRowData(): void
1360
1372
}
1361
1373
1362
1374
/**
1363
- * @return void
1364
- */
1375
+ * @return void
1376
+ */
1365
1377
public function testValidateValidateOptionEntity (): void
1366
1378
{
1367
1379
$ sku = 'sku ' ;
@@ -1407,8 +1419,8 @@ public function testGetImagesFromRow($rowData, $expectedResult): void
1407
1419
}
1408
1420
1409
1421
/**
1410
- * @return void
1411
- */
1422
+ * @return void
1423
+ */
1412
1424
public function testParseAttributesWithoutWrappedValuesWillReturnsLowercasedAttributeCodes (): void
1413
1425
{
1414
1426
$ attributesData = 'PARAM1=value1,param2=value2 ' ;
@@ -1428,8 +1440,8 @@ public function testParseAttributesWithoutWrappedValuesWillReturnsLowercasedAttr
1428
1440
}
1429
1441
1430
1442
/**
1431
- * @return void
1432
- */
1443
+ * @return void
1444
+ */
1433
1445
public function testParseAttributesWithWrappedValuesWillReturnsLowercasedAttributeCodes (): void
1434
1446
{
1435
1447
$ attribute1 = $ this ->getMockBuilder (AbstractAttribute::class)->disableOriginalConstructor ()
@@ -1584,6 +1596,62 @@ function ($name) use ($throwException, $exception) {
1584
1596
);
1585
1597
}
1586
1598
1599
+ /**
1600
+ * Check that getProductCategoriesDataSave method will return array with product-category-position relations
1601
+ * where new products positioned before existing
1602
+ *
1603
+ * @param array $categoriesData
1604
+ * @param string $tableName
1605
+ * @param array $result
1606
+ * @dataProvider productCategoriesDataProvider
1607
+ */
1608
+ public function testGetProductCategoriesDataSave (array $ categoriesData , string $ tableName , array $ result )
1609
+ {
1610
+ $ this ->_connection ->expects ($ this ->at (1 ))->method ('fetchOne ' )->willReturn ('0 ' );
1611
+ $ this ->_connection ->expects ($ this ->at (3 ))->method ('fetchOne ' )->willReturn ('-2 ' );
1612
+ $ this ->skuProcessor ->expects ($ this ->at (0 ))->method ('getNewSku ' )->willReturn (['entity_id ' => 2 ]);
1613
+ $ this ->skuProcessor ->expects ($ this ->at (1 ))->method ('getNewSku ' )->willReturn (['entity_id ' => 5 ]);
1614
+ $ actualResult = $ this ->invokeMethod (
1615
+ $ this ->importProduct ,
1616
+ 'getProductCategoriesDataSave ' ,
1617
+ [$ categoriesData , $ tableName ]
1618
+ );
1619
+ $ this ->assertEquals ($ result , $ actualResult );
1620
+ }
1621
+
1622
+ /**
1623
+ * Data provider for testGetProductCategoriesDataSave.
1624
+ *
1625
+ * @return array
1626
+ */
1627
+ public function productCategoriesDataProvider ()
1628
+ {
1629
+ return [
1630
+ [
1631
+ [
1632
+ 'simple_2 ' => [3 => true ],
1633
+ 'simple_5 ' => [5 => true ]
1634
+ ],
1635
+ 'catalog_category_product ' ,
1636
+ [
1637
+ [2 , 5 ],
1638
+ [
1639
+ [
1640
+ 'product_id ' => 2 ,
1641
+ 'category_id ' => 3 ,
1642
+ 'position ' => -1
1643
+ ],
1644
+ [
1645
+ 'product_id ' => 5 ,
1646
+ 'category_id ' => 5 ,
1647
+ 'position ' => -3
1648
+ ]
1649
+ ]
1650
+ ]
1651
+ ]
1652
+ ];
1653
+ }
1654
+
1587
1655
/**
1588
1656
* Data provider for testFillUploaderObject.
1589
1657
*
0 commit comments