@@ -16,9 +16,6 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
16
16
/** @var Configurable */
17
17
private $ configurable ;
18
18
19
- /** @var \Magento\Catalog\Block\Product\Context|\PHPUnit_Framework_MockObject_MockObject */
20
- private $ context ;
21
-
22
19
/** @var \Magento\Framework\Stdlib\ArrayUtils|\PHPUnit_Framework_MockObject_MockObject */
23
20
private $ arrayUtils ;
24
21
@@ -60,7 +57,6 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
60
57
61
58
public function setUp ()
62
59
{
63
- $ this ->context = $ this ->getMock ('\Magento\Catalog\Block\Product\Context ' , [], [], '' , false );
64
60
$ this ->arrayUtils = $ this ->getMock ('\Magento\Framework\Stdlib\ArrayUtils ' , [], [], '' , false );
65
61
$ this ->jsonEncoder = $ this ->getMock ('\Magento\Framework\Json\EncoderInterface ' , [], [], '' , false );
66
62
$ this ->helper = $ this ->getMock ('\Magento\ConfigurableProduct\Helper\Data ' , [], [], '' , false );
@@ -75,15 +71,13 @@ public function setUp()
75
71
$ this ->imageHelper = $ this ->getMock ('\Magento\Catalog\Helper\Image ' , [], [], '' , false );
76
72
$ this ->urlBuilder = $ this ->getMock ('\Magento\Framework\UrlInterface ' );
77
73
78
- $ this ->context ->expects ($ this ->any ())->method ('getScopeConfig ' )->willReturn ($ this ->scopeConfig );
79
- $ this ->context ->expects ($ this ->any ())->method ('getImageHelper ' )->willReturn ($ this ->imageHelper );
80
- $ this ->context ->expects ($ this ->any ())->method ('getUrlBuilder ' )->willReturn ($ this ->urlBuilder );
81
-
82
74
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
83
75
$ this ->configurable = $ objectManager ->getObject (
84
76
'\Magento\Swatches\Block\Product\Renderer\Configurable ' ,
85
77
[
86
- 'context ' => $ this ->context ,
78
+ 'scopeConfig ' => $ this ->scopeConfig ,
79
+ 'imageHelper ' => $ this ->imageHelper ,
80
+ 'urlBuilder ' => $ this ->urlBuilder ,
87
81
'arrayUtils ' => $ this ->arrayUtils ,
88
82
'jsonEncoder ' => $ this ->jsonEncoder ,
89
83
'helper ' => $ this ->helper ,
@@ -92,7 +86,6 @@ public function setUp()
92
86
'catalogProduct ' => $ this ->catalogProduct ,
93
87
'currentCustomer ' => $ this ->currentCustomer ,
94
88
'priceCurrency ' => $ this ->priceCurrency ,
95
- 'data ' => [],
96
89
]
97
90
);
98
91
}
@@ -146,8 +139,48 @@ public function testSetIsProductListingContext()
146
139
);
147
140
}
148
141
142
+ private function prepareGetJsonSwatchConfig ()
143
+ {
144
+ $ product1 = $ this ->getMock ('\Magento\Catalog\Model\Product ' , [], [], '' , false );
145
+ $ product1 ->expects ($ this ->atLeastOnce ())->method ('isSaleable ' )->willReturn (true );
146
+ $ product1 ->expects ($ this ->atLeastOnce ())->method ('getData ' )->with ('code ' )->willReturn (1 );
147
+
148
+ $ product2 = $ this ->getMock ('\Magento\Catalog\Model\Product ' , [], [], '' , false );
149
+ $ product2 ->expects ($ this ->atLeastOnce ())->method ('isSaleable ' )->willReturn (true );
150
+ $ product2 ->expects ($ this ->atLeastOnce ())->method ('getData ' )->with ('code ' )->willReturn (3 );
151
+
152
+ $ simpleProducts = [$ product1 , $ product2 ];
153
+ $ configurableType = $ this ->getMock (
154
+ '\Magento\ConfigurableProduct\Model\Product\Type\Configurable ' ,
155
+ [],
156
+ [],
157
+ '' ,
158
+ false
159
+ );
160
+ $ configurableType ->expects ($ this ->atLeastOnce ())->method ('getUsedProducts ' )->with ($ this ->product , null )
161
+ ->willReturn ($ simpleProducts );
162
+ $ this ->product ->expects ($ this ->any ())->method ('getTypeInstance ' )->willReturn ($ configurableType );
163
+
164
+ $ productAttribute1 = $ this ->getMock ('\Magento\Eav\Model\Entity\Attribute\AbstractAttribute ' , [], [], '' , false );
165
+ $ productAttribute1 ->expects ($ this ->any ())->method ('getId ' )->willReturn (1 );
166
+ $ productAttribute1 ->expects ($ this ->any ())->method ('getAttributeCode ' )->willReturn ('code ' );
167
+
168
+ $ attribute1 = $ this ->getMock (
169
+ '\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute ' ,
170
+ ['getProductAttribute ' ],
171
+ [],
172
+ '' ,
173
+ false
174
+ );
175
+ $ attribute1 ->expects ($ this ->any ())->method ('getProductAttribute ' )->willReturn ($ productAttribute1 );
176
+
177
+ $ this ->helper ->expects ($ this ->any ())->method ('getAllowAttributes ' )->with ($ this ->product )
178
+ ->willReturn ([$ attribute1 ]);
179
+ }
180
+
149
181
public function testGetJsonSwatchConfigNotVisualImageType ()
150
182
{
183
+ $ this ->prepareGetJsonSwatchConfig ();
151
184
$ this ->configurable ->setProduct ($ this ->product );
152
185
153
186
$ this ->swatchHelper ->expects ($ this ->once ())->method ('getSwatchAttributesAsArray ' )
@@ -167,7 +200,7 @@ public function testGetJsonSwatchConfigNotVisualImageType()
167
200
]);
168
201
169
202
$ this ->swatchHelper ->expects ($ this ->once ())->method ('loadFirstVariationWithSwatchImage ' )
170
- ->with ($ this ->product , [ 'code ' => 3 ] )
203
+ ->with ($ this ->product , 'code ' , 3 )
171
204
->willReturn ($ this ->product );
172
205
173
206
$ this ->product ->expects ($ this ->exactly (4 ))->method ('getData ' )
@@ -187,6 +220,7 @@ public function testGetJsonSwatchConfigNotVisualImageType()
187
220
188
221
public function testGetJsonSwatchConfigVisualImageType ()
189
222
{
223
+ $ this ->prepareGetJsonSwatchConfig ();
190
224
$ this ->configurable ->setProduct ($ this ->product );
191
225
192
226
$ this ->swatchHelper ->expects ($ this ->once ())->method ('getSwatchAttributesAsArray ' )
@@ -206,7 +240,7 @@ public function testGetJsonSwatchConfigVisualImageType()
206
240
]);
207
241
208
242
$ this ->swatchHelper ->expects ($ this ->once ())->method ('loadFirstVariationWithSwatchImage ' )
209
- ->with ($ this ->product , [ 'code ' => 3 ] )
243
+ ->with ($ this ->product , 'code ' , 3 )
210
244
->willReturn ($ this ->product );
211
245
212
246
$ this ->swatchMediaHelper ->expects ($ this ->exactly (2 ))->method ('getSwatchAttributeImage ' )
@@ -233,6 +267,8 @@ public function testGetJsonSwatchConfigVisualImageType()
233
267
234
268
public function testGetJsonSwatchConfigWithoutVisualImageType ()
235
269
{
270
+ $ this ->prepareGetJsonSwatchConfig ();
271
+
236
272
$ this ->configurable ->setProduct ($ this ->product );
237
273
238
274
$ this ->swatchHelper ->expects ($ this ->once ())->method ('getSwatchAttributesAsArray ' )
@@ -252,7 +288,7 @@ public function testGetJsonSwatchConfigWithoutVisualImageType()
252
288
]);
253
289
254
290
$ this ->swatchHelper ->expects ($ this ->once ())->method ('loadFirstVariationWithSwatchImage ' )
255
- ->with ($ this ->product , [ 'code ' => 3 ] )
291
+ ->with ($ this ->product , 'code ' , 3 )
256
292
->willReturn ($ this ->product );
257
293
258
294
$ this ->swatchMediaHelper ->expects ($ this ->exactly (2 ))->method ('getSwatchAttributeImage ' )
0 commit comments