1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Stockbase\Integration\Test\Unit\Model\Config\Source; |
5
|
|
|
|
6
|
|
|
use Magento\Customer\Api\Data\AttributeMetadataInterface; |
7
|
|
|
use Magento\Eav\Model\Entity\Attribute\Set; |
8
|
|
|
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection; |
9
|
|
|
use Magento\Framework\ObjectManagerInterface; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use Stockbase\Integration\Model\Config\Source\EanField; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class EanFieldTest |
15
|
|
|
*/ |
16
|
|
|
class EanFieldTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ |
19
|
|
|
private $objectManager; |
20
|
|
|
|
21
|
|
|
/** @var Collection|\PHPUnit_Framework_MockObject_MockObject */ |
22
|
|
|
private $collection; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
1 |
|
public function setUp() |
28
|
|
|
{ |
29
|
1 |
|
$this->collection = $this->createMock(Collection::class); |
30
|
|
|
|
31
|
1 |
|
$this->objectManager = $this->createMock(ObjectManagerInterface::class); |
32
|
1 |
|
$this->objectManager->method('get')->with(Collection::class)->willReturn($this->collection); |
33
|
1 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* testOptions |
37
|
|
|
*/ |
38
|
1 |
|
public function testOptions() |
39
|
|
|
{ |
40
|
1 |
|
$this->collection->expects($this->once())->method('addFieldToFilter') |
41
|
1 |
|
->with(Set::KEY_ENTITY_TYPE_ID, 4); |
42
|
|
|
|
43
|
1 |
|
$this->collection->expects($this->once())->method('load') |
44
|
1 |
|
->willReturnSelf(); |
45
|
|
|
|
46
|
1 |
|
$items = []; |
47
|
1 |
|
$item = $this->createMock(AttributeMetadataInterface::class); |
48
|
1 |
|
$item->method('getFrontendLabel')->willReturn('Test Attribute'); |
49
|
1 |
|
$item->method('getAttributeCode')->willReturn('test'); |
50
|
1 |
|
$items[] = $item; |
51
|
|
|
|
52
|
1 |
|
$this->collection->expects($this->once())->method('getItems') |
53
|
1 |
|
->willReturn($items); |
54
|
|
|
|
55
|
1 |
|
$fieldSource = new EanField($this->objectManager); |
56
|
1 |
|
$result = $fieldSource->toOptionArray(); |
57
|
|
|
|
58
|
|
|
$expectedResult = [ |
59
|
1 |
|
['label' => '', 'value' => ''], |
60
|
|
|
['label' => 'Test Attribute', 'value' => 'test'], |
61
|
|
|
]; |
62
|
|
|
|
63
|
1 |
|
$this->assertEquals($expectedResult, $result); |
64
|
1 |
|
} |
65
|
|
|
} |
66
|
|
|
|