36 $this->swatchesHelperMock = $this->createPartialMock(
37 \
Magento\Swatches\Helper\Data::class,
38 [
'loadVariationByFallback',
'isSwatchAttribute',
'isProductHasSwatch']
41 $this->attributeFactoryMock = $this->createPartialMock(
46 $this->eavConfigMock = $this->createMock(\
Magento\Eav\Model\Config::class);
48 $this->attributeMock = $this->createPartialMock(
50 [
'loadByCode',
'getId',
'getUsedInProductListing',
'getIsFilterable',
'getData']
53 $this->requestMock = $this->createPartialMock(\
Magento\Framework\
App\Request\Http::class, [
'getParams']);
54 $this->productMock = $this->createMock(\
Magento\Catalog\Model\Product::class);
56 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
59 \
Magento\Swatches\Model\Plugin\ProductImage::class,
61 'swatchesHelperData' => $this->swatchesHelperMock,
62 'eavConfig' => $this->eavConfigMock,
63 'request' => $this->requestMock,
73 $this->productMock->expects($this->once())->method(
'getTypeId')->willReturn(
'configurable');
76 ->expects($this->once())
78 ->willReturn($expected[
'getParams']);
81 ->method(
'getEntityAttributes')
82 ->with(
'catalog_product')
83 ->willReturn([
'color' => $this->attributeMock]);
86 $this->swatchesHelperMock
87 ->expects($this->exactly($expected[
'loadVariationByFallback_count']))
88 ->method(
'loadVariationByFallback')
89 ->willReturn($expected[
'product']);
90 $this->swatchesHelperMock
91 ->method(
'isProductHasSwatch')
92 ->with($this->productMock)
95 $productImageMock = $this->createMock(\
Magento\Catalog\Block\Product\AbstractProduct::class);
97 $result = $this->pluginModel->beforeGetImage($productImageMock, $this->productMock, $expected[
'page_handle']);
98 $this->assertEquals([$this->productMock, $expected[
'page_handle'], []],
$result);
107 ->method(
'getEntityAttributeCodes')
108 ->with(
'catalog_product')
109 ->willReturn($expected[
'attribute_codes_array']);
112 ->method(
'getAttribute')
113 ->with(
'catalog_product', $expected[
'attribute_code'])
114 ->willReturn($this->attributeMock);
117 ->expects($this->exactly($expected[
'getId_count']))
119 ->willReturn($expected[
'getId']);
127 $this->swatchesHelperMock
128 ->expects($this->once())
129 ->method(
'isSwatchAttribute')
130 ->with($this->attributeMock)
131 ->willReturn($expected[
'isSwatchAttribute']);
134 ->expects($this->exactly($expected[
'getUsedInProductListing_count']))
135 ->method(
'getUsedInProductListing')
136 ->willReturn($expected[
'getUsedInProductListing']);
139 ->expects($this->exactly($expected[
'getIsFilterable_count']))
140 ->method(
'getIsFilterable')
141 ->willReturn($expected[
'getIsFilterable']);
143 if ($expected[
'update_product_preview_image__count'] == 1) {
146 ->with(
'update_product_preview_image')
147 ->willReturn($expected[
'update_product_preview_image']);
158 $productMock->expects($this->any())->method(
'getImage')->willReturn(
false);
163 'page_handle' =>
'category_page_grid',
164 'getParams' => [
'color' => 31],
165 'attribute_code' =>
'color',
168 'isSwatchAttribute' =>
false,
169 'getUsedInProductListing' =>
true,
170 'getUsedInProductListing_count' => 1,
171 'getIsFilterable' =>
true,
172 'getIsFilterable_count' => 1,
173 'update_product_preview_image' =>
true,
174 'update_product_preview_image__count' => 1,
175 'loadVariationByFallback_count' => 0,
181 'page_handle' =>
'category_page_grid',
182 'getParams' => [
'color' => 31],
183 'attribute_code' =>
'color',
186 'isSwatchAttribute' =>
true,
187 'getUsedInProductListing' =>
true,
188 'getUsedInProductListing_count' => 1,
189 'getIsFilterable' =>
true,
190 'getIsFilterable_count' => 1,
191 'update_product_preview_image' =>
true,
192 'update_product_preview_image__count' => 1,
193 'loadVariationByFallback_count' => 1,
199 'page_handle' =>
'category_page_grid',
200 'getParams' => [
'color' => 31],
201 'attribute_code' =>
'color',
204 'isSwatchAttribute' =>
true,
205 'getUsedInProductListing' =>
true,
206 'getUsedInProductListing_count' => 1,
207 'getIsFilterable' =>
true,
208 'getIsFilterable_count' => 1,
209 'update_product_preview_image' =>
false,
210 'update_product_preview_image__count' => 1,
211 'loadVariationByFallback_count' => 0,
canReplaceImageWithSwatch($expected)
getFilterArray($expected)
testBeforeGetImage($expected)