Skip to content

Commit 4cf6034

Browse files
ENGCOM-6509: [ImportExport] Cover Export Source Model by Unit Test #26140
2 parents 6752b5f + d318094 commit 4cf6034

File tree

2 files changed

+181
-0
lines changed

2 files changed

+181
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\ImportExport\Test\Unit\Model\Source\Export;
10+
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Magento\ImportExport\Model\Export\ConfigInterface;
13+
use Magento\ImportExport\Model\Source\Export\Entity;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class EntityTest extends TestCase
18+
{
19+
/**
20+
* @var ConfigInterface|MockObject
21+
*/
22+
private $exportConfigMock;
23+
24+
/**
25+
* @var Entity
26+
*/
27+
private $model;
28+
29+
/**
30+
* Setup environment for test
31+
*/
32+
protected function setUp()
33+
{
34+
$this->exportConfigMock = $this->createMock(ConfigInterface::class);
35+
36+
$objectManager = new ObjectManager($this);
37+
$this->model = $objectManager->getObject(
38+
Entity::class,
39+
[
40+
'exportConfig' => $this->exportConfigMock
41+
]
42+
);
43+
}
44+
45+
/**
46+
* Test toOptionArray with data provider
47+
*
48+
* @param array $entities
49+
* @param array $expected
50+
* @dataProvider toOptionArrayDataProvider
51+
*/
52+
public function testToOptionArray($entities, $expected)
53+
{
54+
$this->exportConfigMock->expects($this->any())->method('getEntities')->willReturn($entities);
55+
56+
$this->assertEquals($expected, $this->model->toOptionArray());
57+
}
58+
59+
/**
60+
* Data Provider for test toOptionArray
61+
*
62+
* @return array
63+
*/
64+
public function toOptionArrayDataProvider()
65+
{
66+
return [
67+
'Empty Entity' => [
68+
[],
69+
[
70+
[
71+
'label' => (string)__('-- Please Select --'),
72+
'value' => ''
73+
]
74+
]
75+
],
76+
'Has entities' => [
77+
[
78+
'entity1' => [
79+
'label' => 'Entity 1'
80+
]
81+
],
82+
[
83+
[
84+
'label' => (string)__('-- Please Select --'),
85+
'value' => ''
86+
],
87+
[
88+
'label' => (string)__('Entity 1'),
89+
'value' => 'entity1'
90+
]
91+
]
92+
]
93+
];
94+
}
95+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\ImportExport\Test\Unit\Model\Source\Export;
10+
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Magento\ImportExport\Model\Export\ConfigInterface;
13+
use Magento\ImportExport\Model\Source\Export\Format;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class FormatTest extends TestCase
18+
{
19+
/**
20+
* @var ConfigInterface|MockObject
21+
*/
22+
private $exportConfigMock;
23+
24+
/**
25+
* @var Format
26+
*/
27+
private $model;
28+
29+
/**
30+
* Setup environment for test
31+
*/
32+
protected function setUp()
33+
{
34+
$this->exportConfigMock = $this->createMock(ConfigInterface::class);
35+
36+
$objectManager = new ObjectManager($this);
37+
$this->model = $objectManager->getObject(
38+
Format::class,
39+
[
40+
'exportConfig' => $this->exportConfigMock
41+
]
42+
);
43+
}
44+
45+
/**
46+
* Test toOptionArray with data provider
47+
*
48+
* @param array $fileFormats
49+
* @param array $expected
50+
* @dataProvider toOptionArrayDataProvider
51+
*/
52+
public function testToOptionArray($fileFormats, $expected)
53+
{
54+
$this->exportConfigMock->expects($this->any())->method('getFileFormats')->willReturn($fileFormats);
55+
56+
$this->assertEquals($expected, $this->model->toOptionArray());
57+
}
58+
59+
/**
60+
* Data Provider for test toOptionArray
61+
*
62+
* @return array
63+
*/
64+
public function toOptionArrayDataProvider()
65+
{
66+
return [
67+
'Empty file format' => [
68+
[],
69+
[]
70+
],
71+
'Has file format' => [
72+
[
73+
'fileFormat1' => [
74+
'label' => 'File Format 1'
75+
]
76+
],
77+
[
78+
[
79+
'label' => (string)__('File Format 1'),
80+
'value' => 'fileFormat1'
81+
]
82+
]
83+
]
84+
];
85+
}
86+
}

0 commit comments

Comments
 (0)