Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeSetsFixtureTest.php
Go to the documentation of this file.
1 <?php
8 
11 
15 class AttributeSetsFixtureTest extends \PHPUnit\Framework\TestCase
16 {
20  private $fixtureModelMock;
21 
25  private $model;
26 
30  private $attributeSetsFixtureMock;
31 
35  private $patternMock;
36 
37  public function setUp()
38  {
39  $this->fixtureModelMock = $this->getMockBuilder(\Magento\Setup\Fixtures\FixtureModel::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42  $this->attributeSetsFixtureMock = $this->getMockBuilder(AttributeSetFixture::class)
43  ->disableOriginalConstructor()
44  ->getMock();
45  $this->patternMock = $this->getMockBuilder(\Magento\Setup\Fixtures\AttributeSet\Pattern::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48 
49  $this->model = new AttributeSetsFixture(
50  $this->fixtureModelMock,
51  $this->attributeSetsFixtureMock,
52  $this->patternMock
53  );
54  }
55 
56  public function testCreateAttributeSet()
57  {
58  $valueMap = [
59  ['attribute_sets', null, ['attribute_set' => [['some-data']]]],
60  ['product_attribute_sets', null, null],
61  ];
62 
63  $this->attributeSetsFixtureMock->expects($this->once())
64  ->method('createAttributeSet')
65  ->with(['some-data']);
66  $this->fixtureModelMock
67  ->expects($this->exactly(2))
68  ->method('getValue')
69  ->will($this->returnValueMap($valueMap));
70 
71  $this->model->execute();
72  }
73 
75  {
76  $valueMap = [
77  ['attribute_sets', null, null],
78  ['product_attribute_sets', null, 1],
79  ['product_attribute_sets_attributes', 3, 2],
80  ['product_attribute_sets_attributes_values', 3, 3],
81  ];
82 
83  $closure = function () {
84  };
85  $this->patternMock->expects($this->once())
86  ->method('generateAttributeSet')
87  ->with(\Magento\Setup\Fixtures\AttributeSetsFixture::PRODUCT_SET_NAME . 1, 2, 3, $closure)
88  ->willReturn(['some-data']);
89  $this->attributeSetsFixtureMock->expects($this->once())
90  ->method('createAttributeSet')
91  ->with(['some-data']);
92  $this->fixtureModelMock
93  ->expects($this->exactly(4))
94  ->method('getValue')
95  ->will($this->returnValueMap($valueMap));
96 
97  $this->model->execute();
98  }
99 
100  public function testGetActionTitle()
101  {
102  $this->assertSame('Generating attribute sets', $this->model->getActionTitle());
103  }
104 
105  public function testIntroduceParamLabels()
106  {
107  $this->assertSame([
108  'attribute_sets' => 'Attribute Sets (Default)',
109  'product_attribute_sets' => 'Attribute Sets (Extra)'
110  ], $this->model->introduceParamLabels());
111  }
112 }