10 use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
26 private $fixtureModelMock;
36 private $storeManagerMock;
41 private $attributeSetMock;
51 private $eavConfigMock;
56 private $attributeFactoryMock;
63 $this->fixtureModelMock = $this->getMockBuilder(FixtureModel::class)
64 ->disableOriginalConstructor()->getMock();
65 $this->eavConfigMock = $this->getMockBuilder(Config::class)
66 ->disableOriginalConstructor()->getMock();
67 $this->storeManagerMock = $this->getMockBuilder(StoreManager::class)
68 ->disableOriginalConstructor()->getMock();
69 $this->attributeSetMock = $this->getMockBuilder(Set::class)
70 ->disableOriginalConstructor()->getMock();
71 $this->cacheMock = $this->getMockBuilder(CacheInterface::class)
72 ->disableOriginalConstructor()->getMock();
73 $this->attributeFactoryMock = $this->getMockBuilder(AttributeFactory::class)
74 ->setMethods([
'create'])
75 ->disableOriginalConstructor()->getMock();
77 $this->model = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
78 EavVariationsFixture::class,
80 'fixtureModel' => $this->fixtureModelMock,
81 'eavConfig' => $this->eavConfigMock,
82 'storeManager' => $this->storeManagerMock,
83 'attributeSet' => $this->attributeSetMock,
84 'cache' => $this->cacheMock,
85 'attributeFactory' => $this->attributeFactoryMock,
97 $this->fixtureModelMock->expects($this->once())
98 ->method(
'getValue')->with(
'configurable_products', [])->willReturn(10);
99 $this->eavConfigMock->expects($this->once())->method(
'getEntityAttributeCodes')
100 ->willReturn([
'configurable_variation']);
101 $this->attributeFactoryMock->expects($this->never())->method(
'create');
103 $this->model->execute();
114 $this->eavConfigMock->expects($this->once())
115 ->method(
'getEntityAttributeCodes')->willReturn([
'attr1',
'attr2']);
116 $this->fixtureModelMock
117 ->expects($this->any())
120 [
'configurable_products', [], [
'some-config']],
121 [
'configurable_products_variation', 3, 1],
124 $storeMock = $this->getMockBuilder(\
Magento\
Store\Model\Store::class)
125 ->disableOriginalConstructor()->getMock();
126 $this->storeManagerMock->expects($this->once())->method(
'getStores')->willReturn([
$storeId => $storeMock]);
127 $this->attributeSetMock->expects($this->once())->method(
'load')->willReturnSelf();
128 $this->attributeSetMock->expects($this->once())->method(
'getDefaultGroupId')->willReturn(2);
130 $attributeMock = $this->getMockBuilder(\
Magento\Catalog\Model\
ResourceModel\Eav\Attribute::class)
133 'setAttributeGroupId',
136 ->disableOriginalConstructor()->getMock();
137 $attributeMock->expects($this->exactly(2))->method(
'setAttributeSetId')->willReturnSelf();
138 $attributeMock->expects($this->once())->method(
'setAttributeGroupId')->willReturnSelf();
139 $this->attributeFactoryMock->expects($this->once())->method(
'create')
143 'frontend_label' => [
144 $storeId =>
'configurable variations',
146 'frontend_input' =>
'select',
147 'is_required' =>
'0',
149 'order' => [
'option_1' => 1],
150 'value' => [
'option_1' => [
$storeId =>
'option 1']],
151 'delete' => [
'option_1' =>
''],
153 'default' => [
'option_0'],
154 'attribute_code' =>
'configurable_variation',
156 'default_value_text' =>
'',
157 'default_value_yesno' =>
'0',
158 'default_value_date' =>
'',
159 'default_value_textarea' =>
'',
161 'is_searchable' =>
'1',
162 'is_visible_in_advanced_search' =>
'0',
163 'is_comparable' =>
'0',
164 'is_filterable' =>
'1',
165 'is_filterable_in_search' =>
'0',
166 'is_used_for_promo_rules' =>
'0',
167 'is_html_allowed_on_front' =>
'1',
168 'is_visible_on_front' =>
'0',
169 'used_in_product_listing' =>
'0',
170 'used_for_sort_by' =>
'0',
171 'source_model' =>
null,
172 'backend_model' =>
null,
174 'backend_type' =>
'int',
175 'entity_type_id' => 4,
176 'is_user_defined' => 1,
177 'swatch_input_type' =>
'visual',
179 'value' => [
'option_1' =>
'#ffffff'],
182 'value' => [
'option_1' => [
'option 1']],
186 )->willReturn($attributeMock);
187 $this->cacheMock->expects($this->once())
188 ->method(
'remove')->with(Config::ATTRIBUTES_CACHE_ID .
Product::ENTITY);
190 $this->model->execute();
200 $this->assertSame(
'Generating configurable EAV variations', $this->model->getActionTitle());
210 $this->assertSame([], $this->model->introduceParamLabels());
testIntroduceParamLabels()
testDoNotExecuteWhenAttributeAlreadyExist()