@@ -112,11 +112,18 @@ public function setUp()
112
112
$ this ->_coreConfig = $ this ->getMockBuilder ('\Magento\Framework\App\Config\ScopeConfigInterface ' )
113
113
->disableOriginalConstructor ()
114
114
->getMock ();
115
- $ this ->_importConfig = $ this ->getMockBuilder ('\Magento\ImportExport\Model\Import\ConfigInterface ' )
115
+ $ this ->_importConfig = $ this ->getMockBuilder ('\Magento\ImportExport\Model\Import\Config ' )
116
116
->disableOriginalConstructor ()
117
- ->setMethods (['getEntityTypeCode ' , 'getBehavior ' ])
117
+ ->setMethods (['getEntityTypeCode ' , 'getBehavior ' , ' getEntities ' ])
118
118
->getMockForAbstractClass ();
119
- $ this ->_entityFactory = $ this ->getMockBuilder ('\Magento\ImportExport\Model\Import\Entity\Factory ' )
119
+ $ this ->_entityFactory = $ this ->getMock (
120
+ '\Magento\ImportExport\Model\Import\Entity\Factory ' ,
121
+ ['create ' , 'isNeedToLogInHistory ' ],
122
+ [],
123
+ '' ,
124
+ false
125
+ );
126
+ $ this ->getMockBuilder ('\Magento\ImportExport\Model\Import\Entity\Factory ' )
120
127
->disableOriginalConstructor ()
121
128
->getMock ();
122
129
$ this ->_importData = $ this ->getMockBuilder ('\Magento\ImportExport\Model\Resource\Import\Data ' )
@@ -422,16 +429,61 @@ public function testGetUniqueEntityBehaviors()
422
429
*
423
430
* @dataProvider isReportEntityTypeDataProvider
424
431
*/
425
- public function testIsReportEntityType ($ entity , $ processedReportsEntities , $ getEntityResult , $ expectedResult )
432
+ public function testIsReportEntityType ($ entity , $ getEntityResult , $ expectedResult )
426
433
{
427
434
$ importMock = $ this ->getMockBuilder ('\Magento\ImportExport\Model\Import ' )
428
435
->disableOriginalConstructor ()
429
436
->setMethods ([
430
- 'getEntity ' ,
437
+ 'getEntity ' , ' _getEntityAdapter ' , ' getEntityTypeCode ' , ' isNeedToLogInHistory '
431
438
])
432
439
->getMock ();
440
+ $ importMock ->expects ($ this ->any ())->method ('_getEntityAdapter ' )->willReturnSelf ();
441
+ $ importMock ->expects ($ this ->any ())->method ('getEntityTypeCode ' )->willReturn ('catalog_product ' );
442
+ $ this ->_importConfig
443
+ ->expects ($ this ->any ())
444
+ ->method ('getEntities ' )
445
+ ->willReturn (
446
+ [
447
+ 'advanced_pricing ' => [
448
+ 'model ' => 'advanced_pricing '
449
+ ]
450
+ ]
451
+ );
452
+ $ this ->_entityFactory ->expects ($ this ->any ())->method ('create ' )->willReturnSelf ();
453
+ $ this ->setPropertyValue ($ importMock , '_importConfig ' , $ this ->_importConfig );
454
+ $ this ->setPropertyValue ($ importMock , '_entityFactory ' , $ this ->_entityFactory );
455
+ $ importMock
456
+ ->expects ($ this ->any ())
457
+ ->method ('getEntity ' )
458
+ ->willReturn ($ getEntityResult );
459
+
460
+ $ actualResult = $ importMock ->isReportEntityType ($ entity );
461
+ $ this ->assertEquals ($ expectedResult , $ actualResult );
462
+ }
433
463
434
- $ this ->setPropertyValue ($ importMock , 'processedReportsEntities ' , $ processedReportsEntities );
464
+ /**
465
+ * Cover isReportEntityType().
466
+ *
467
+ * @dataProvider isReportEntityTypeExceptionDataProvider
468
+ * @expectedException \Magento\Framework\Exception\LocalizedException
469
+ */
470
+ public function testIsReportEntityTypeException ($ entity , $ getEntitiesResult , $ getEntityResult , $ expectedResult )
471
+ {
472
+ $ importMock = $ this ->getMockBuilder ('\Magento\ImportExport\Model\Import ' )
473
+ ->disableOriginalConstructor ()
474
+ ->setMethods ([
475
+ 'getEntity ' , '_getEntityAdapter ' , 'getEntityTypeCode ' , 'isNeedToLogInHistory '
476
+ ])
477
+ ->getMock ();
478
+ $ importMock ->expects ($ this ->any ())->method ('_getEntityAdapter ' )->willReturnSelf ();
479
+ $ importMock ->expects ($ this ->any ())->method ('getEntityTypeCode ' )->willReturn ('catalog_product ' );
480
+ $ this ->_importConfig
481
+ ->expects ($ this ->any ())
482
+ ->method ('getEntities ' )
483
+ ->willReturn ($ getEntitiesResult );
484
+ $ this ->_entityFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ('' );
485
+ $ this ->setPropertyValue ($ importMock , '_importConfig ' , $ this ->_importConfig );
486
+ $ this ->setPropertyValue ($ importMock , '_entityFactory ' , $ this ->_entityFactory );
435
487
$ importMock
436
488
->expects ($ this ->any ())
437
489
->method ('getEntity ' )
@@ -677,45 +729,45 @@ public function testCreateHistoryReportThrowException()
677
729
$ this ->assertEquals ($ this ->import , $ actualResult );
678
730
}
679
731
732
+ /**
733
+ * Dataprovider for isReportEntityType()
734
+ *
735
+ * @return array
736
+ */
680
737
public function isReportEntityTypeDataProvider ()
681
738
{
682
739
return [
683
740
[
684
741
'$entity ' => null ,
685
- '$processedReportsEntities ' => [],
686
742
'$getEntityResult ' => null ,
687
743
'$expectedResult ' => false ,
688
744
],
689
745
[
690
- '$entity ' => null ,
691
- '$processedReportsEntities ' => [
692
- 'entity '
693
- ],
694
- '$getEntityResult ' => null ,
695
- '$expectedResult ' => false ,
696
- ],
697
- [
698
- '$entity ' => null ,
699
- '$processedReportsEntities ' => [
700
- 'entity 1 '
701
- ],
702
- '$getEntityResult ' => 'entity 2 ' ,
703
- '$expectedResult ' => false ,
746
+ '$entity ' => 'advanced_pricing ' ,
747
+ '$getEntityResult ' => 'advanced_pricing ' ,
748
+ '$expectedResult ' => null ,
704
749
],
750
+ ];
751
+ }
752
+
753
+ /**
754
+ * Dataprovider for isReportEntityTypeException()
755
+ *
756
+ * @return array
757
+ */
758
+ public function isReportEntityTypeExceptionDataProvider ()
759
+ {
760
+ return [
705
761
[
706
762
'$entity ' => 'entity ' ,
707
- '$processedReportsEntities ' => [
708
- 'entity 1 '
709
- ],
710
- '$getEntityResult ' => 'entity 2 ' ,
763
+ '$getEntitiesResult ' => ['catalog_product ' => ['model ' => 'catalog_product ' ]],
764
+ '$getEntityResult ' => 'catalog_product ' ,
711
765
'$expectedResult ' => false ,
712
766
],
713
767
[
714
- '$entity ' => 'entity ' ,
715
- '$processedReportsEntities ' => [
716
- 'entity '
717
- ],
718
- '$getEntityResult ' => null ,
768
+ '$entity ' => 'advanced_pricing ' ,
769
+ '$getEntitiesResult ' => ['catalog_product ' => ['model ' => 'catalog_product ' ]],
770
+ '$getEntityResult ' => 'advanced_pricing ' ,
719
771
'$expectedResult ' => true ,
720
772
],
721
773
];
0 commit comments