/** * @dataProvider dataForTest */ public function testBeforeGetImage($expected) { $this->productMock->expects($this->once())->method('getTypeId')->willReturn('configurable'); $this->requestMock->expects($this->once())->method('getParams')->willReturn($expected['getParams']); $this->getFilterArray($expected); $this->canReplaceImageWithSwatch($expected); $this->swatchesHelperMock->expects($this->exactly($expected['loadVariationByFallback_count']))->method('loadVariationByFallback')->willReturn($expected['product']); $productImageMock = $this->getMock('Magento\\Catalog\\Block\\Product\\AbstractProduct', [], [], '', false); $result = $this->pluginModel->beforeGetImage($productImageMock, $this->productMock, $expected['page_handle']); $this->assertEquals([$this->productMock, $expected['page_handle'], []], $result); }
/** * {@inheritDoc} */ protected function getFilterArray(array $request) { $filterArray = parent::getFilterArray($request); $attributeCodes = $this->eavConfig->getEntityAttributeCodes(\Magento\Catalog\Model\Product::ENTITY); foreach ($request as $code => $value) { if (in_array($code, $attributeCodes)) { $attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $code); if (isset($filterArray[$code]) && !is_array($filterArray[$code])) { $filterArray[$code] = [$filterArray[$code]]; } if ($attribute->getId() && $this->canReplaceImageWithSwatch($attribute)) { $filterArray[$code][] = $this->getOptionIds($attribute, $value); } } } return $filterArray; }