Skip to content

Commit 8630762

Browse files
Siarhei AndreyeuSiarhei Andreyeu
authored andcommitted
MAGNIMEX-13: Import history
- Fix import test.
1 parent 37d919a commit 8630762

File tree

1 file changed

+82
-30
lines changed

1 file changed

+82
-30
lines changed

app/code/Magento/ImportExport/Test/Unit/Model/ImportTest.php

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,18 @@ public function setUp()
112112
$this->_coreConfig = $this->getMockBuilder('\Magento\Framework\App\Config\ScopeConfigInterface')
113113
->disableOriginalConstructor()
114114
->getMock();
115-
$this->_importConfig = $this->getMockBuilder('\Magento\ImportExport\Model\Import\ConfigInterface')
115+
$this->_importConfig = $this->getMockBuilder('\Magento\ImportExport\Model\Import\Config')
116116
->disableOriginalConstructor()
117-
->setMethods(['getEntityTypeCode', 'getBehavior'])
117+
->setMethods(['getEntityTypeCode', 'getBehavior', 'getEntities'])
118118
->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')
120127
->disableOriginalConstructor()
121128
->getMock();
122129
$this->_importData = $this->getMockBuilder('\Magento\ImportExport\Model\Resource\Import\Data')
@@ -422,16 +429,61 @@ public function testGetUniqueEntityBehaviors()
422429
*
423430
* @dataProvider isReportEntityTypeDataProvider
424431
*/
425-
public function testIsReportEntityType($entity, $processedReportsEntities, $getEntityResult, $expectedResult)
432+
public function testIsReportEntityType($entity, $getEntityResult, $expectedResult)
426433
{
427434
$importMock = $this->getMockBuilder('\Magento\ImportExport\Model\Import')
428435
->disableOriginalConstructor()
429436
->setMethods([
430-
'getEntity',
437+
'getEntity', '_getEntityAdapter', 'getEntityTypeCode', 'isNeedToLogInHistory'
431438
])
432439
->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+
}
433463

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);
435487
$importMock
436488
->expects($this->any())
437489
->method('getEntity')
@@ -677,45 +729,45 @@ public function testCreateHistoryReportThrowException()
677729
$this->assertEquals($this->import, $actualResult);
678730
}
679731

732+
/**
733+
* Dataprovider for isReportEntityType()
734+
*
735+
* @return array
736+
*/
680737
public function isReportEntityTypeDataProvider()
681738
{
682739
return [
683740
[
684741
'$entity' => null,
685-
'$processedReportsEntities' => [],
686742
'$getEntityResult' => null,
687743
'$expectedResult' => false,
688744
],
689745
[
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,
704749
],
750+
];
751+
}
752+
753+
/**
754+
* Dataprovider for isReportEntityTypeException()
755+
*
756+
* @return array
757+
*/
758+
public function isReportEntityTypeExceptionDataProvider()
759+
{
760+
return [
705761
[
706762
'$entity' => 'entity',
707-
'$processedReportsEntities' => [
708-
'entity 1'
709-
],
710-
'$getEntityResult' => 'entity 2',
763+
'$getEntitiesResult' => ['catalog_product' => ['model' => 'catalog_product']],
764+
'$getEntityResult' => 'catalog_product',
711765
'$expectedResult' => false,
712766
],
713767
[
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',
719771
'$expectedResult' => true,
720772
],
721773
];

0 commit comments

Comments
 (0)