@@ -144,9 +144,6 @@ class ProductTest extends \PHPUnit_Framework_TestCase
144
144
/** @var \Magento\Framework\Model\Resource\Db\TransactionManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
145
145
protected $ transactionManager ;
146
146
147
- /** @var \Magento\Catalog\Model\ProductFactory|\PHPUnit_Framework_MockObject_MockObject */
148
- protected $ catalogProductFactory ;
149
-
150
147
/** @var \Magento\CatalogImportExport\Model\Import\Product\TaxClassProcessor|\PHPUnit_Framework_MockObject_MockObject */
151
148
// @codingStandardsIgnoreEnd
152
149
protected $ taxClassProcessor ;
@@ -282,6 +279,9 @@ protected function setUp()
282
279
->getMock ();
283
280
$ this ->storeResolver =
284
281
$ this ->getMockBuilder ('\Magento\CatalogImportExport\Model\Import\Product\StoreResolver ' )
282
+ ->setMethods ([
283
+ 'getStoreCodeToId ' ,
284
+ ])
285
285
->disableOriginalConstructor ()
286
286
->getMock ();
287
287
$ this ->skuProcessor =
@@ -303,13 +303,6 @@ protected function setUp()
303
303
$ this ->transactionManager =
304
304
$ this ->getMockBuilder ('\Magento\Framework\Model\Resource\Db\TransactionManagerInterface ' )
305
305
->getMock ();
306
- $ this ->catalogProductFactory = $ this ->getMock (
307
- '\Magento\Catalog\Model\ProductFactory ' ,
308
- ['create ' ],
309
- [],
310
- '' ,
311
- false
312
- );
313
306
314
307
$ this ->taxClassProcessor =
315
308
$ this ->getMockBuilder ('\Magento\CatalogImportExport\Model\Import\Product\TaxClassProcessor ' )
@@ -355,7 +348,6 @@ protected function setUp()
355
348
$ this ->skuProcessor ,
356
349
$ this ->categoryProcessor ,
357
350
$ this ->validator ,
358
- $ this ->catalogProductFactory ,
359
351
$ this ->objectRelationProcessor ,
360
352
$ this ->transactionManager ,
361
353
$ this ->taxClassProcessor ,
@@ -479,33 +471,6 @@ protected function _initSkus()
479
471
return $ this ;
480
472
}
481
473
482
- public function testGetAffectedProducts ()
483
- {
484
- $ testProduct = 'test_product ' ;
485
- $ rowData = ['data ' ];
486
- $ rowNum = 666 ;
487
- $ importProduct = $ this ->getMockBuilder ('\Magento\CatalogImportExport\Model\Import\Product ' )
488
- ->disableOriginalConstructor ()
489
- ->setMethods (['isRowAllowedToImport ' , '_populateToUrlGeneration ' ])
490
- ->getMock ();
491
-
492
- $ this ->_dataSourceModel ->expects ($ this ->exactly (2 ))->method ('getNextBunch ' )->willReturnOnConsecutiveCalls (
493
- [
494
- $ rowNum => $ rowData
495
- ],
496
- null
497
- );
498
- $ this ->setPropertyValue ($ importProduct , '_dataSourceModel ' , $ this ->_dataSourceModel );
499
- $ importProduct ->expects ($ this ->once ())
500
- ->method ('isRowAllowedToImport ' )
501
- ->with ($ rowData , $ rowNum )->willReturn (true );
502
- $ importProduct ->expects ($ this ->once ())->method ('_populateToUrlGeneration ' )
503
- ->with ($ rowData )
504
- ->willReturn ($ testProduct );
505
-
506
- $ this ->assertEquals ([$ testProduct ], $ importProduct ->getAffectedProducts ());
507
- }
508
-
509
474
public function testSaveProductAttributes ()
510
475
{
511
476
$ testTable = 'test_table ' ;
@@ -815,6 +780,108 @@ public function testValidateRowValidatorCheck()
815
780
$ importProduct ->validateRow ($ rowData , $ rowNum );
816
781
}
817
782
783
+ /**
784
+ * Cover getProductWebsites().
785
+ */
786
+ public function testGetProductWebsites ()
787
+ {
788
+ $ productSku = 'productSku ' ;
789
+ $ productValue = [
790
+ 'key 1 ' => 'val ' ,
791
+ 'key 2 ' => 'val ' ,
792
+ 'key 3 ' => 'val ' ,
793
+ ];
794
+ $ expectedResult = array_keys ($ productValue );
795
+ $ this ->setPropertyValue ($ this ->importProduct , 'websitesCache ' , [
796
+ $ productSku => $ productValue
797
+ ]);
798
+
799
+ $ actualResult = $ this ->importProduct ->getProductWebsites ($ productSku );
800
+
801
+ $ this ->assertEquals ($ expectedResult , $ actualResult );
802
+ }
803
+
804
+ /**
805
+ * Cover getProductCategories().
806
+ */
807
+ public function testGetProductCategories ()
808
+ {
809
+ $ productSku = 'productSku ' ;
810
+ $ productValue = [
811
+ 'key 1 ' => 'val ' ,
812
+ 'key 2 ' => 'val ' ,
813
+ 'key 3 ' => 'val ' ,
814
+ ];
815
+ $ expectedResult = array_keys ($ productValue );
816
+ $ this ->setPropertyValue ($ this ->importProduct , 'categoriesCache ' , [
817
+ $ productSku => $ productValue
818
+ ]);
819
+
820
+ $ actualResult = $ this ->importProduct ->getProductCategories ($ productSku );
821
+
822
+ $ this ->assertEquals ($ expectedResult , $ actualResult );
823
+ }
824
+
825
+ /**
826
+ * Cover getStoreIdByCode().
827
+ *
828
+ * @dataProvider getStoreIdByCodeDataProvider
829
+ */
830
+ public function testGetStoreIdByCode ($ storeCode , $ expectedResult )
831
+ {
832
+ $ this ->storeResolver
833
+ ->expects ($ this ->any ())
834
+ ->method ('getStoreCodeToId ' )
835
+ ->willReturn ('getStoreCodeToId value ' );
836
+
837
+ $ actualResult = $ this ->importProduct ->getStoreIdByCode ($ storeCode );
838
+ $ this ->assertEquals ($ expectedResult , $ actualResult );
839
+ }
840
+
841
+ /**
842
+ * Cover getNewSku().
843
+ */
844
+ public function testGetNewSku ()
845
+ {
846
+ $ expectedSku = 'value ' ;
847
+ $ expectedResult = 'result value ' ;
848
+
849
+ $ this ->skuProcessor
850
+ ->expects ($ this ->any ())
851
+ ->method ('getNewSku ' )
852
+ ->with ($ expectedSku )
853
+ ->willReturn ($ expectedResult );
854
+
855
+ $ actualResult = $ this ->importProduct ->getNewSku ($ expectedSku );
856
+ $ this ->assertEquals ($ expectedResult , $ actualResult );
857
+ }
858
+
859
+ /**
860
+ * Cover getCategoryProcessor().
861
+ */
862
+ public function testGetCategoryProcessor ()
863
+ {
864
+ $ expectedResult = 'value ' ;
865
+ $ this ->setPropertyValue ($ this ->importProduct , 'categoryProcessor ' , $ expectedResult );
866
+
867
+ $ actualResult = $ this ->importProduct ->getCategoryProcessor ();
868
+ $ this ->assertEquals ($ expectedResult , $ actualResult );
869
+ }
870
+
871
+ public function getStoreIdByCodeDataProvider ()
872
+ {
873
+ return [
874
+ [
875
+ '$storeCode ' => null ,
876
+ '$expectedResult ' => \Magento \CatalogImportExport \Model \Import \Product::SCOPE_DEFAULT ,
877
+ ],
878
+ [
879
+ '$storeCode ' => 'value ' ,
880
+ '$expectedResult ' => 'getStoreCodeToId value ' ,
881
+ ],
882
+ ];
883
+ }
884
+
818
885
/**
819
886
* @dataProvider validateRowCheckSpecifiedSkuDataProvider
820
887
*/
@@ -1154,95 +1221,6 @@ public function testValidateValidateOptionEntity()
1154
1221
$ importProduct ->validateRow ($ rowData , $ rowNum );
1155
1222
}
1156
1223
1157
- /**
1158
- * @dataProvider populateToUrlGenerationReturnNullDataProvider
1159
- */
1160
- public function testPopulateToUrlGenerationReturnNull ($ rowData , $ newSku )
1161
- {
1162
- $ productMock = $ this ->getMock (
1163
- '\Magento\Catalog\Model\Product ' ,
1164
- ['addData ' ],
1165
- [],
1166
- '' ,
1167
- false
1168
- );
1169
-
1170
- $ this ->catalogProductFactory
1171
- ->expects ($ this ->once ())
1172
- ->method ('create ' )
1173
- ->willReturn ($ productMock );
1174
-
1175
- $ this ->skuProcessor
1176
- ->expects ($ this ->once ())
1177
- ->method ('getNewSku ' )
1178
- ->willReturn ($ newSku );
1179
-
1180
- $ result = $ this ->importProduct ->_populateToUrlGeneration ($ rowData );
1181
-
1182
- $ this ->assertNull ($ result );
1183
-
1184
- }
1185
-
1186
- public function testPopulateToUrlGenerationReturnProduct ()
1187
- {
1188
- $ rowData = [
1189
- \Magento \CatalogImportExport \Model \Import \Product::COL_SKU => 'value '
1190
- ];
1191
- $ newSku = [
1192
- 'entity_id ' => 'new sku value ' ,
1193
- ];
1194
- $ expectedRowData = [
1195
- \Magento \CatalogImportExport \Model \Import \Product::COL_SKU => 'value ' ,
1196
- 'entity_id ' => $ newSku ['entity_id ' ],
1197
- ];
1198
- $ productMock = $ this ->getMock (
1199
- '\Magento\Catalog\Model\Product ' ,
1200
- ['addData ' ],
1201
- [],
1202
- '' ,
1203
- false
1204
- );
1205
-
1206
- $ productMock
1207
- ->expects ($ this ->once ())
1208
- ->method ('addData ' )
1209
- ->with ($ expectedRowData );
1210
-
1211
- $ this ->catalogProductFactory
1212
- ->expects ($ this ->once ())
1213
- ->method ('create ' )
1214
- ->willReturn ($ productMock );
1215
-
1216
- $ this ->skuProcessor
1217
- ->expects ($ this ->once ())
1218
- ->method ('getNewSku ' )
1219
- ->willReturn ($ newSku );
1220
-
1221
- $ result = $ this ->importProduct ->_populateToUrlGeneration ($ rowData );
1222
-
1223
- $ this ->assertEquals ($ productMock , $ result );
1224
- }
1225
-
1226
- public function populateToUrlGenerationReturnNullDataProvider ()
1227
- {
1228
- return [
1229
- [
1230
- '$rowData ' => [
1231
- \Magento \CatalogImportExport \Model \Import \Product::COL_SKU => 'value '
1232
- ],
1233
- '$newSku ' => [
1234
- 'entity_id ' => null ,
1235
- ],
1236
- ],
1237
- [
1238
- '$rowData ' => [
1239
- \Magento \CatalogImportExport \Model \Import \Product::COL_SKU => 'value '
1240
- ],
1241
- '$newSku ' => [],
1242
- ],
1243
- ];
1244
- }
1245
-
1246
1224
public function validateRowValidateNewProductTypeAddRowErrorCallDataProvider ()
1247
1225
{
1248
1226
return [
0 commit comments