35 $this->product = $this->createPartialMock(\
Magento\Catalog\Model\Product::class, [
38 'hasPreconfiguredValues',
39 'getPreconfiguredValues',
43 $this->attributeMock = $this->createMock(
46 $this->configurableAttributeData = new \Magento\ConfigurableProduct\Model\ConfigurableAttributeData();
57 [
'value_index' =>
'option_id_1',
'label' =>
'label_1'],
58 [
'value_index' =>
'option_id_2',
'label' =>
'label_2'],
65 'code' =>
'test_attribute',
67 'position' => $position,
70 'id' =>
'option_id_1',
72 'products' =>
'option_products_1',
75 'id' =>
'option_id_2',
77 'products' =>
'option_products_2',
83 $attributeId =>
'option_id_1',
87 $attributeId => [
'option_id_1' =>
'option_products_1',
'option_id_2' =>
'option_products_2'],
90 $productAttributeMock = $this->getMockBuilder(\
Magento\Catalog\Model\Entity\Attribute::class)
91 ->disableOriginalConstructor()
92 ->setMethods([
'getStoreLabel',
'__wakeup',
'getAttributeCode',
'getId',
'getAttributeLabel'])
94 $productAttributeMock->expects($this->once())
96 ->willReturn($attributeId);
97 $productAttributeMock->expects($this->once())
98 ->method(
'getAttributeCode')
99 ->willReturn($expected[
'attributes'][$attributeId][
'code']);
104 ->disableOriginalConstructor()
105 ->setMethods([
'getProductAttribute',
'__wakeup',
'getLabel',
'getOptions',
'getAttributeId',
'getPosition'])
108 ->method(
'getProductAttribute')
109 ->willReturn($productAttributeMock);
111 ->method(
'getPosition')
112 ->willReturn($position);
114 $this->product->expects($this->once())->method(
'getStoreId')->willReturn(
$storeId);
115 $productAttributeMock->expects($this->once())
116 ->method(
'getStoreLabel')
118 ->willReturn($expected[
'attributes'][$attributeId][
'label']);
121 ->method(
'getAttributeId')
122 ->willReturn($attributeId);
124 ->method(
'getOptions')
125 ->willReturn($attributeOptions);
129 )->disableOriginalConstructor()->getMock();
131 ->method(
'getConfigurableAttributes')
132 ->with($this->product)
135 $configuredValueMock = $this->getMockBuilder(\
Magento\Framework\DataObject::class)
136 ->disableOriginalConstructor()
138 $configuredValueMock->expects($this->any())
140 ->willReturn($expected[
'defaultValues'][$attributeId]);
142 $this->product->expects($this->once())
143 ->method(
'getTypeInstance')
145 $this->product->expects($this->once())
146 ->method(
'hasPreconfiguredValues')
148 $this->product->expects($this->once())
149 ->method(
'getPreconfiguredValues')
150 ->willReturn($configuredValueMock);
152 $this->assertEquals($expected, $this->configurableAttributeData->getAttributesData($this->product,
$options));
testPrepareJsonAttributes()
$configurableAttributeData