1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Test\Unit\Fixtures;
use Magento\Setup\Fixtures\AttributeSet\AttributeSetFixture;
use Magento\Setup\Fixtures\AttributeSetsFixture;
/**
* @SuppressWarnings(PHPMD)
*/
class AttributeSetsFixtureTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel
*/
private $fixtureModelMock;
/**
* @var \Magento\Setup\Fixtures\AttributeSetsFixture
*/
private $model;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $attributeSetsFixtureMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $patternMock;
public function setUp()
{
$this->fixtureModelMock = $this->getMockBuilder(\Magento\Setup\Fixtures\FixtureModel::class)
->disableOriginalConstructor()
->getMock();
$this->attributeSetsFixtureMock = $this->getMockBuilder(AttributeSetFixture::class)
->disableOriginalConstructor()
->getMock();
$this->patternMock = $this->getMockBuilder(\Magento\Setup\Fixtures\AttributeSet\Pattern::class)
->disableOriginalConstructor()
->getMock();
$this->model = new AttributeSetsFixture(
$this->fixtureModelMock,
$this->attributeSetsFixtureMock,
$this->patternMock
);
}
public function testCreateAttributeSet()
{
$valueMap = [
['attribute_sets', null, ['attribute_set' => [['some-data']]]],
['product_attribute_sets', null, null],
];
$this->attributeSetsFixtureMock->expects($this->once())
->method('createAttributeSet')
->with(['some-data']);
$this->fixtureModelMock
->expects($this->exactly(2))
->method('getValue')
->will($this->returnValueMap($valueMap));
$this->model->execute();
}
public function testCreateProductAttributeSet()
{
$valueMap = [
['attribute_sets', null, null],
['product_attribute_sets', null, 1],
['product_attribute_sets_attributes', 3, 2],
['product_attribute_sets_attributes_values', 3, 3],
];
$closure = function () {
};
$this->patternMock->expects($this->once())
->method('generateAttributeSet')
->with(\Magento\Setup\Fixtures\AttributeSetsFixture::PRODUCT_SET_NAME . 1, 2, 3, $closure)
->willReturn(['some-data']);
$this->attributeSetsFixtureMock->expects($this->once())
->method('createAttributeSet')
->with(['some-data']);
$this->fixtureModelMock
->expects($this->exactly(4))
->method('getValue')
->will($this->returnValueMap($valueMap));
$this->model->execute();
}
public function testGetActionTitle()
{
$this->assertSame('Generating attribute sets', $this->model->getActionTitle());
}
public function testIntroduceParamLabels()
{
$this->assertSame([
'attribute_sets' => 'Attribute Sets (Default)',
'product_attribute_sets' => 'Attribute Sets (Extra)'
], $this->model->introduceParamLabels());
}
}