12
12
*/
13
13
class ConfigurationTest extends \PHPUnit_Framework_TestCase
14
14
{
15
- /** @var \Magento\Framework\Pricing\Helper\Data|\PHPUnit_Framework_MockObject_MockObject */
16
- protected $ pricingHelper ;
15
+ /**
16
+ * @var \Magento\Framework\Pricing\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
17
+ */
18
+ private $ pricingHelper ;
17
19
18
- /** @var \Magento\Catalog\Helper\Product\Configuration|\PHPUnit_Framework_MockObject_MockObject */
19
- protected $ productConfiguration ;
20
+ /**
21
+ * @var \Magento\Catalog\Helper\Product\Configuration|\PHPUnit_Framework_MockObject_MockObject
22
+ */
23
+ private $ productConfiguration ;
20
24
21
- /** @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject */
22
- protected $ escaper ;
25
+ /**
26
+ * @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject
27
+ */
28
+ private $ escaper ;
23
29
24
- /** @var \Magento\Bundle\Helper\Catalog\Product\Configuration */
25
- protected $ helper ;
30
+ /**
31
+ * @var \Magento\Bundle\Helper\Catalog\Product\Configuration
32
+ */
33
+ private $ helper ;
26
34
27
- /** @var \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface|\PHPUnit_Framework_MockObject_MockObject */
28
- protected $ item ;
35
+ /**
36
+ * @var \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface|\PHPUnit_Framework_MockObject_MockObject
37
+ */
38
+ private $ item ;
29
39
30
40
/**
31
41
* @var \Magento\Framework\Serialize\Serializer\Json
@@ -48,7 +58,13 @@ protected function setUp()
48
58
'' ,
49
59
false
50
60
);
51
- $ this ->escaper = $ this ->getMock (\Magento \Framework \Escaper::class, ['escapeHtml ' ], [], '' , false );
61
+ $ this ->escaper = $ this ->getMock (
62
+ \Magento \Framework \Escaper::class,
63
+ ['escapeHtml ' ],
64
+ [],
65
+ '' ,
66
+ false
67
+ );
52
68
$ this ->item = $ this ->getMock (
53
69
\Magento \Catalog \Model \Product \Configuration \Item \ItemInterface::class,
54
70
['getQty ' , 'getProduct ' , 'getOptionByCode ' , 'getFileDownloadParams ' ]
@@ -79,12 +95,28 @@ public function testGetSelectionQty()
79
95
{
80
96
$ selectionId = 15 ;
81
97
$ selectionQty = 35 ;
82
- $ product = $ this ->getMock (\Magento \Catalog \Model \Product::class, [], [], '' , false );
83
- $ option = $ this ->getMock (\Magento \Catalog \Model \Product \Option::class, ['__wakeup ' , 'getValue ' ], [], '' , false );
98
+ $ product = $ this ->getMock (
99
+ \Magento \Catalog \Model \Product::class,
100
+ [],
101
+ [],
102
+ '' ,
103
+ false
104
+ );
105
+ $ option = $ this ->getMock (
106
+ \Magento \Catalog \Model \Product \Option::class,
107
+ ['__wakeup ' , 'getValue ' ],
108
+ [],
109
+ '' ,
110
+ false
111
+ );
84
112
85
- $ product ->expects ($ this ->once ())->method ('getCustomOption ' )->with ('selection_qty_ ' . $ selectionId )
86
- ->will ($ this ->returnValue ($ option ));
87
- $ option ->expects ($ this ->once ())->method ('getValue ' )->will ($ this ->returnValue ($ selectionQty ));
113
+ $ product ->expects ($ this ->once ())
114
+ ->method ('getCustomOption ' )
115
+ ->with ('selection_qty_ ' . $ selectionId )
116
+ ->willReturn ($ option );
117
+ $ option ->expects ($ this ->once ())
118
+ ->method ('getValue ' )
119
+ ->willReturn ($ selectionQty );
88
120
89
121
$ this ->assertEquals ($ selectionQty , $ this ->helper ->getSelectionQty ($ product , $ selectionId ));
90
122
}
@@ -100,9 +132,6 @@ public function testGetSelectionQtyIfCustomOptionIsNotSet()
100
132
$ this ->assertEquals (0 , $ this ->helper ->getSelectionQty ($ product , $ selectionId ));
101
133
}
102
134
103
- /**
104
- * @covers \Magento\Bundle\Helper\Catalog\Product\Configuration::getSelectionFinalPrice
105
- */
106
135
public function testGetSelectionFinalPrice ()
107
136
{
108
137
$ itemQty = 2 ;
@@ -144,7 +173,13 @@ public function testGetBundleOptionsEmptyBundleOptionsIds()
144
173
public function testGetBundleOptionsEmptyBundleSelectionIds ()
145
174
{
146
175
$ optionIds = '{"0":"1"} ' ;
147
- $ collection = $ this ->getMock (\Magento \Bundle \Model \ResourceModel \Option \Collection::class, [], [], '' , false );
176
+ $ collection = $ this ->getMock (
177
+ \Magento \Bundle \Model \ResourceModel \Option \Collection::class,
178
+ [],
179
+ [],
180
+ '' ,
181
+ false
182
+ );
148
183
$ product = $ this ->getMock (
149
184
\Magento \Catalog \Model \Product::class,
150
185
['getTypeInstance ' ,
@@ -153,28 +188,49 @@ public function testGetBundleOptionsEmptyBundleSelectionIds()
153
188
'' ,
154
189
false
155
190
);
156
- $ typeInstance = $ this ->getMock (\Magento \Bundle \Model \Product \Type::class, ['getOptionsByIds ' ], [], '' , false );
157
- $ selectionOption =
158
- $ this ->getMock (
159
- \Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface::class,
160
- ['getValue ' ]
161
- );
162
- $ itemOption =
163
- $ this ->getMock (
164
- \Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface::class,
165
- ['getValue ' ]
166
- );
191
+ $ typeInstance = $ this ->getMock (
192
+ \Magento \Bundle \Model \Product \Type::class,
193
+ ['getOptionsByIds ' ],
194
+ [],
195
+ '' ,
196
+ false
197
+ );
198
+ $ selectionOption = $ this ->getMock (
199
+ \Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface::class,
200
+ ['getValue ' ]
201
+ );
202
+ $ itemOption = $ this ->getMock (
203
+ \Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface::class,
204
+ ['getValue ' ]
205
+ );
167
206
168
- $ selectionOption ->expects ($ this ->once ())->method ('getValue ' )->will ($ this ->returnValue ('' ));
169
- $ itemOption ->expects ($ this ->once ())->method ('getValue ' )->will ($ this ->returnValue ($ optionIds ));
170
- $ typeInstance ->expects ($ this ->once ())->method ('getOptionsByIds ' )->with (json_decode ($ optionIds , true ), $ product )
171
- ->will ($ this ->returnValue ($ collection ));
172
- $ product ->expects ($ this ->once ())->method ('getTypeInstance ' )->will ($ this ->returnValue ($ typeInstance ));
173
- $ this ->item ->expects ($ this ->once ())->method ('getProduct ' )->will ($ this ->returnValue ($ product ));
174
- $ this ->item ->expects ($ this ->at (1 ))->method ('getOptionByCode ' )->with ('bundle_option_ids ' )
175
- ->will ($ this ->returnValue ($ itemOption ));
176
- $ this ->item ->expects ($ this ->at (2 ))->method ('getOptionByCode ' )->with ('bundle_selection_ids ' )
177
- ->will ($ this ->returnValue ($ selectionOption ));
207
+ $ selectionOption ->expects ($ this ->once ())
208
+ ->method ('getValue ' )
209
+ ->willReturn ('[] ' );
210
+ $ itemOption ->expects ($ this ->once ())
211
+ ->method ('getValue ' )
212
+ ->willReturn ($ optionIds );
213
+ $ typeInstance ->expects ($ this ->once ())
214
+ ->method ('getOptionsByIds ' )
215
+ ->with (
216
+ json_decode ($ optionIds , true ),
217
+ $ product
218
+ )
219
+ ->willReturn ($ collection );
220
+ $ product ->expects ($ this ->once ())
221
+ ->method ('getTypeInstance ' )
222
+ ->willReturn ($ typeInstance );
223
+ $ this ->item ->expects ($ this ->once ())
224
+ ->method ('getProduct ' )
225
+ ->willReturn ($ product );
226
+ $ this ->item ->expects ($ this ->at (1 ))
227
+ ->method ('getOptionByCode ' )
228
+ ->with ('bundle_option_ids ' )
229
+ ->willReturn ($ itemOption );
230
+ $ this ->item ->expects ($ this ->at (2 ))
231
+ ->method ('getOptionByCode ' )
232
+ ->with ('bundle_selection_ids ' )
233
+ ->willReturn ($ selectionOption );
178
234
179
235
$ this ->assertEquals ([], $ this ->helper ->getBundleOptions ($ this ->item ));
180
236
}
@@ -201,38 +257,44 @@ public function testGetOptions()
201
257
'' ,
202
258
false
203
259
);
204
- $ priceModel =
205
- $ this ->getMock (\Magento \Bundle \Model \Product \Price::class, ['getSelectionFinalTotalPrice ' ], [], '' , false );
206
- $ selectionQty =
207
- $ this ->getMock (\Magento \Quote \Model \Quote \Item \Option::class, ['getValue ' , '__wakeup ' ], [], '' , false );
208
- $ bundleOption =
209
- $ this ->getMock (
210
- \Magento \Bundle \Model \Option::class,
211
- ['getSelections ' ,
212
- 'getTitle ' ,
213
- '__wakeup ' ],
214
- [],
215
- '' ,
216
- false
217
- );
218
- $ selectionOption =
219
- $ this ->getMock (
220
- \Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface::class,
221
- ['getValue ' ]
222
- );
223
- $ collection =
224
- $ this ->getMock (
225
- \Magento \Bundle \Model \ResourceModel \Option \Collection::class,
226
- ['appendSelections ' ],
227
- [],
228
- '' ,
229
- false
230
- );
231
- $ itemOption =
232
- $ this ->getMock (
233
- \Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface::class,
234
- ['getValue ' ]
235
- );
260
+ $ priceModel = $ this ->getMock (
261
+ \Magento \Bundle \Model \Product \Price::class,
262
+ ['getSelectionFinalTotalPrice ' ],
263
+ [],
264
+ '' ,
265
+ false
266
+ );
267
+ $ selectionQty = $ this ->getMock (
268
+ \Magento \Quote \Model \Quote \Item \Option::class,
269
+ ['getValue ' , '__wakeup ' ],
270
+ [],
271
+ '' ,
272
+ false
273
+ );
274
+ $ bundleOption = $ this ->getMock (
275
+ \Magento \Bundle \Model \Option::class,
276
+ ['getSelections ' ,
277
+ 'getTitle ' ,
278
+ '__wakeup ' ],
279
+ [],
280
+ '' ,
281
+ false
282
+ );
283
+ $ selectionOption = $ this ->getMock (
284
+ \Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface::class,
285
+ ['getValue ' ]
286
+ );
287
+ $ collection = $ this ->getMock (
288
+ \Magento \Bundle \Model \ResourceModel \Option \Collection::class,
289
+ ['appendSelections ' ],
290
+ [],
291
+ '' ,
292
+ false
293
+ );
294
+ $ itemOption = $ this ->getMock (
295
+ \Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface::class,
296
+ ['getValue ' ]
297
+ );
236
298
$ collection2 = $ this ->getMock (
237
299
\Magento \Bundle \Model \ResourceModel \Selection \Collection::class,
238
300
[],
@@ -241,7 +303,10 @@ public function testGetOptions()
241
303
false
242
304
);
243
305
244
- $ this ->escaper ->expects ($ this ->once ())->method ('escapeHtml ' )->with ('name ' )->will ($ this ->returnValue ('name ' ));
306
+ $ this ->escaper ->expects ($ this ->once ())
307
+ ->method ('escapeHtml ' )
308
+ ->with ('name ' )
309
+ ->willReturn ('name ' );
245
310
$ this ->pricingHelper ->expects ($ this ->once ())->method ('currency ' )->with (15 )
246
311
->will ($ this ->returnValue ('<span class="price">$15.00</span> ' ));
247
312
$ priceModel ->expects ($ this ->once ())->method ('getSelectionFinalTotalPrice ' )->will ($ this ->returnValue (15 ));
@@ -252,8 +317,13 @@ public function testGetOptions()
252
317
$ collection ->expects ($ this ->once ())->method ('appendSelections ' )->with ($ collection2 , true )
253
318
->will ($ this ->returnValue ([$ bundleOption ]));
254
319
$ itemOption ->expects ($ this ->once ())->method ('getValue ' )->will ($ this ->returnValue ($ optionIds ));
255
- $ typeInstance ->expects ($ this ->once ())->method ('getOptionsByIds ' )->with (json_decode ($ optionIds , true ), $ product )
256
- ->will ($ this ->returnValue ($ collection ));
320
+ $ typeInstance ->expects ($ this ->once ())
321
+ ->method ('getOptionsByIds ' )
322
+ ->with (
323
+ json_decode ($ optionIds , true ),
324
+ $ product
325
+ )
326
+ ->willReturn ($ collection );
257
327
$ typeInstance ->expects ($ this ->once ())
258
328
->method ('getSelectionsByIds ' )
259
329
->with (json_decode ($ selectionIds , true ), $ product )
0 commit comments