/** * @magentoAppIsolation enabled */ public function testGetSelectedAttributesInfoForStore() { $attributes = $this->_model->getConfigurableAttributesAsArray($this->_product); $attribute = reset($attributes); $optionValueId = $attribute['values'][0]['value_index']; $this->_product->addCustomOption('attributes', serialize([$attribute['attribute_id'] => $optionValueId])); $configurableAttr = $this->_model->getConfigurableAttributes($this->_product); $attribute = $configurableAttr->getFirstItem(); $attribute->getProductAttribute()->setStoreLabel('store label'); $info = $this->_model->getSelectedAttributesInfo($this->_product); $this->assertEquals([['label' => 'store label', 'value' => 'Option 1']], $info); }
public function testGetConfigurableAttributes() { $expectedData = [1]; $configurableAttributes = '_cache_instance_configurable_attributes'; /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */ $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getData', 'hasData', 'setData'])->disableOriginalConstructor()->getMock(); $product->expects($this->once())->method('hasData')->with($configurableAttributes)->willReturn(false); $product->expects($this->once())->method('setData')->willReturnSelf(); $product->expects($this->once())->method('getData')->with($configurableAttributes)->willReturn($expectedData); $attributeCollection = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Resource\\Product\\Type\\Configurable\\Attribute\\Collection')->setMethods(['setProductFilter', 'orderByPosition', 'load'])->disableOriginalConstructor()->getMock(); $attributeCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf()); $attributeCollection->expects($this->any())->method('orderByPosition')->will($this->returnSelf()); $this->_attributeCollectionFactory->expects($this->any())->method('create')->willReturn($attributeCollection); $this->extensionAttributesJoinProcessorMock->expects($this->once())->method('process')->with($this->isInstanceOf('Magento\\ConfigurableProduct\\Model\\Resource\\Product\\Type\\Configurable\\Attribute\\Collection')); $this->assertEquals($expectedData, $this->_model->getConfigurableAttributes($product)); }