/** * @dataProvider dataForGettingSwatchAsArray */ public function testGetSwatchAttributesAsArray($optionsArray, $attributeData, $expected) { $configurable = $this->getMock('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', [], [], '', false); $this->productMock->expects($this->atLeastOnce())->method('getTypeInstance')->willReturn($configurable); $confAttribute = $this->getMock('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute', [], [], '', false); $configurable->expects($this->atLeastOnce())->method('getConfigurableAttributes')->with($this->productMock)->willReturn([$confAttribute]); $confAttribute->expects($this->atLeastOnce())->method('__call')->with('getProductAttribute')->willReturn($this->attributeMock); $this->attributeMock->method('setStoreId')->will($this->returnSelf()); $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false); $storeMock->method('getId')->willReturn(1); $this->storeManagerMock->method('getStore')->willReturn($storeMock); $this->attributeMock->method('hasData')->with('swatch_input_type')->willReturn(true); $this->attributeMock->expects($this->at(1))->method('getData')->with('swatch_input_type')->willReturn('visual'); $this->attributeMock->expects($this->at(3))->method('getData')->with('')->willReturn($attributeData); $sourceMock = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\AbstractSource', [], [], '', false); $sourceMock->expects($this->any())->method('getAllOptions')->with(false)->willReturn($optionsArray); $this->attributeMock->method('getSource')->willReturn($sourceMock); $result = $this->swatchHelperObject->getSwatchAttributesAsArray($this->productMock); $this->assertEquals($result, $expected); }
/** * @return array */ protected function getSwatchAttributesData() { return $this->swatchHelper->getSwatchAttributesAsArray($this->getProduct()); }