20 private $swatchAttributeProvider;
25 private $typeConfigurable;
30 private $swatchAttributeCodes;
40 private $swatchTypeChecker;
44 $this->typeConfigurable = $this->createPartialMock(
46 [
'getConfigurableAttributes',
'getCodes',
'getProductAttribute']
49 $this->swatchAttributeCodes = $this->createMock(SwatchAttributeCodes::class);
51 $this->productMock = $this->createPartialMock(\
Magento\Catalog\Model\Product::class, [
'getId',
'getTypeId']);
52 $this->swatchTypeChecker = $this->createMock(SwatchAttributeType::class);
54 $this->swatchAttributeProvider = (
new ObjectManager($this))->getObject(SwatchAttributesProvider::class, [
55 'typeConfigurable' => $this->typeConfigurable,
56 'swatchAttributeCodes' => $this->swatchAttributeCodes,
57 'swatchTypeChecker' => $this->swatchTypeChecker,
63 $this->productMock->method(
'getId')->willReturn(1);
64 $this->productMock->method(
'getTypeId')
67 $attributeMock = $this->getMockBuilder(\
Magento\Catalog\Model\
ResourceModel\Eav\Attribute::class)
68 ->disableOriginalConstructor()
69 ->setMethods([
'setStoreId',
'getData',
'setData',
'getSource',
'hasData'])
72 $configAttributeMock = $this->createPartialMock(
74 [
'getAttributeId',
'getProductAttribute']
77 ->method(
'getAttributeId')
81 ->method(
'getProductAttribute')
82 ->willReturn($attributeMock);
84 $this->typeConfigurable
85 ->method(
'getConfigurableAttributes')
86 ->with($this->productMock)
87 ->willReturn([$configAttributeMock]);
89 $swatchAttributes = [1 =>
'text_swatch'];
90 $this->swatchAttributeCodes
92 ->willReturn($swatchAttributes);
94 $this->swatchTypeChecker->expects($this->once())->method(
'isSwatchAttribute')->willReturn(
true);
96 $result = $this->swatchAttributeProvider->provide($this->productMock);
98 $this->assertEquals([1 => $attributeMock],
$result);