@@ -72,7 +72,16 @@ protected function setUp()
72
72
73
73
$ this ->itemMock = $ this ->getMock (
74
74
'Magento\Quote\Model\Quote\Item ' ,
75
- ['getId ' , 'setOptions ' , '__wakeup ' , 'setProduct ' , 'addQty ' , 'setCustomPrice ' , 'setOriginalCustomPrice ' ],
75
+ [
76
+ 'getId ' ,
77
+ 'setOptions ' ,
78
+ '__wakeup ' ,
79
+ 'setProduct ' ,
80
+ 'addQty ' ,
81
+ 'setCustomPrice ' ,
82
+ 'setOriginalCustomPrice ' ,
83
+ 'setData '
84
+ ],
76
85
[],
77
86
'' ,
78
87
false
@@ -109,7 +118,7 @@ protected function setUp()
109
118
110
119
$ this ->productMock = $ this ->getMock (
111
120
'Magento\Catalog\Model\Product ' ,
112
- ['getCustomOptions ' , '__wakeup ' , 'getParentProductId ' , 'getCartQty ' ],
121
+ ['getCustomOptions ' , '__wakeup ' , 'getParentProductId ' , 'getCartQty ' , ' getStickWithinParent ' ],
113
122
[],
114
123
'' ,
115
124
false
@@ -148,8 +157,12 @@ public function testInitWithQtyModification()
148
157
->will ($ this ->returnValue ($ itemId ));
149
158
$ this ->itemMock ->expects ($ this ->any ())
150
159
->method ('setData ' )
151
- ->with ($ this ->equalTo ('qty ' ), $ this ->equalTo (0 ));
152
-
160
+ ->willReturnMap (
161
+ [
162
+ ['store_id ' , $ storeId ],
163
+ ['qty ' , 0 ],
164
+ ]
165
+ );
153
166
154
167
$ this ->storeMock ->expects ($ this ->any ())
155
168
->method ('getId ' )
@@ -177,15 +190,20 @@ public function testInitWithoutModification()
177
190
->method ('getParentProductId ' )
178
191
->will ($ this ->returnValue (true ));
179
192
180
-
181
193
$ this ->itemMock ->expects ($ this ->never ())->method ('setOptions ' );
182
194
$ this ->itemMock ->expects ($ this ->never ())->method ('setProduct ' );
183
195
184
196
$ this ->itemMock ->expects ($ this ->any ())
185
197
->method ('getId ' )
186
198
->will ($ this ->returnValue ($ itemId ));
187
199
188
- $ this ->itemMock ->expects ($ this ->never ())->method ('setData ' );
200
+ $ this ->itemMock ->expects ($ this ->any ())
201
+ ->method ('setData ' )
202
+ ->willReturnMap (
203
+ [
204
+ ['store_id ' , $ storeId ],
205
+ ]
206
+ );
189
207
190
208
$ this ->storeMock ->expects ($ this ->any ())
191
209
->method ('getId ' )
@@ -222,7 +240,13 @@ public function testInitWithoutModificationAdminhtmlAreaCode()
222
240
->method ('getId ' )
223
241
->will ($ this ->returnValue ($ itemId ));
224
242
225
- $ this ->itemMock ->expects ($ this ->never ())->method ('setData ' );
243
+ $ this ->itemMock ->expects ($ this ->any ())
244
+ ->method ('setData ' )
245
+ ->willReturnMap (
246
+ [
247
+ ['store_id ' , $ storeId ],
248
+ ]
249
+ );
226
250
227
251
$ this ->storeMock ->expects ($ this ->any ())
228
252
->method ('getId ' )
@@ -238,58 +262,171 @@ public function testPrepare()
238
262
{
239
263
$ qty = 3000000000 ;
240
264
$ customPrice = 400000000 ;
265
+ $ itemId = 1 ;
266
+ $ requestItemId = 1 ;
241
267
242
268
$ this ->productMock ->expects ($ this ->any ())
243
269
->method ('getCartQty ' )
244
270
->will ($ this ->returnValue ($ qty ));
271
+ $ this ->productMock ->expects ($ this ->any ())
272
+ ->method ('getStickWithinParent ' )
273
+ ->will ($ this ->returnValue (false ));
245
274
246
- $ this ->itemMock ->expects ($ this ->any ())
275
+ $ this ->itemMock ->expects ($ this ->once ())
247
276
->method ('addQty ' )
248
277
->with ($ qty );
278
+ $ this ->itemMock ->expects ($ this ->any ())
279
+ ->method ('getId ' )
280
+ ->will ($ this ->returnValue ($ itemId ));
281
+ $ this ->itemMock ->expects ($ this ->never ())
282
+ ->method ('setData ' );
249
283
250
284
$ this ->objectMock ->expects ($ this ->any ())
251
285
->method ('getCustomPrice ' )
252
286
->will ($ this ->returnValue ($ customPrice ));
287
+ $ this ->objectMock ->expects ($ this ->any ())
288
+ ->method ('getResetCount ' )
289
+ ->will ($ this ->returnValue (false ));
290
+ $ this ->objectMock ->expects ($ this ->any ())
291
+ ->method ('getId ' )
292
+ ->will ($ this ->returnValue ($ requestItemId ));
293
+
294
+ $ this ->itemMock ->expects ($ this ->once ())
295
+ ->method ('setCustomPrice ' )
296
+ ->will ($ this ->returnValue ($ customPrice ));
297
+ $ this ->itemMock ->expects ($ this ->once ())
298
+ ->method ('setOriginalCustomPrice ' )
299
+ ->will ($ this ->returnValue ($ customPrice ));
253
300
301
+ $ this ->processor ->prepare ($ this ->itemMock , $ this ->objectMock , $ this ->productMock );
302
+ }
303
+
304
+ public function testPrepareWithResetCountAndStick ()
305
+ {
306
+ $ qty = 3000000000 ;
307
+ $ customPrice = 400000000 ;
308
+ $ itemId = 1 ;
309
+ $ requestItemId = 1 ;
310
+
311
+ $ this ->productMock ->expects ($ this ->any ())
312
+ ->method ('getCartQty ' )
313
+ ->will ($ this ->returnValue ($ qty ));
314
+ $ this ->productMock ->expects ($ this ->any ())
315
+ ->method ('getStickWithinParent ' )
316
+ ->will ($ this ->returnValue (true ));
317
+
318
+ $ this ->itemMock ->expects ($ this ->once ())
319
+ ->method ('addQty ' )
320
+ ->with ($ qty );
254
321
$ this ->itemMock ->expects ($ this ->any ())
322
+ ->method ('getId ' )
323
+ ->will ($ this ->returnValue ($ itemId ));
324
+ $ this ->itemMock ->expects ($ this ->never ())
325
+ ->method ('setData ' );
326
+
327
+ $ this ->objectMock ->expects ($ this ->any ())
328
+ ->method ('getCustomPrice ' )
329
+ ->will ($ this ->returnValue ($ customPrice ));
330
+ $ this ->objectMock ->expects ($ this ->any ())
331
+ ->method ('getResetCount ' )
332
+ ->will ($ this ->returnValue (true ));
333
+ $ this ->objectMock ->expects ($ this ->any ())
334
+ ->method ('getId ' )
335
+ ->will ($ this ->returnValue ($ requestItemId ));
336
+
337
+ $ this ->itemMock ->expects ($ this ->once ())
255
338
->method ('setCustomPrice ' )
256
339
->will ($ this ->returnValue ($ customPrice ));
340
+ $ this ->itemMock ->expects ($ this ->once ())
341
+ ->method ('setOriginalCustomPrice ' )
342
+ ->will ($ this ->returnValue ($ customPrice ));
343
+
344
+ $ this ->processor ->prepare ($ this ->itemMock , $ this ->objectMock , $ this ->productMock );
345
+ }
346
+
347
+ public function testPrepareWithResetCountAndNotStickAndOtherItemId ()
348
+ {
349
+ $ qty = 3000000000 ;
350
+ $ customPrice = 400000000 ;
351
+ $ itemId = 1 ;
352
+ $ requestItemId = 2 ;
353
+
354
+ $ this ->productMock ->expects ($ this ->any ())
355
+ ->method ('getCartQty ' )
356
+ ->will ($ this ->returnValue ($ qty ));
357
+ $ this ->productMock ->expects ($ this ->any ())
358
+ ->method ('getStickWithinParent ' )
359
+ ->will ($ this ->returnValue (false ));
360
+
361
+ $ this ->itemMock ->expects ($ this ->once ())
362
+ ->method ('addQty ' )
363
+ ->with ($ qty );
257
364
$ this ->itemMock ->expects ($ this ->any ())
365
+ ->method ('getId ' )
366
+ ->will ($ this ->returnValue ($ itemId ));
367
+ $ this ->itemMock ->expects ($ this ->never ())
368
+ ->method ('setData ' );
369
+
370
+ $ this ->objectMock ->expects ($ this ->any ())
371
+ ->method ('getCustomPrice ' )
372
+ ->will ($ this ->returnValue ($ customPrice ));
373
+ $ this ->objectMock ->expects ($ this ->any ())
374
+ ->method ('getResetCount ' )
375
+ ->will ($ this ->returnValue (true ));
376
+ $ this ->objectMock ->expects ($ this ->any ())
377
+ ->method ('getId ' )
378
+ ->will ($ this ->returnValue ($ requestItemId ));
379
+
380
+ $ this ->itemMock ->expects ($ this ->once ())
381
+ ->method ('setCustomPrice ' )
382
+ ->will ($ this ->returnValue ($ customPrice ));
383
+ $ this ->itemMock ->expects ($ this ->once ())
258
384
->method ('setOriginalCustomPrice ' )
259
385
->will ($ this ->returnValue ($ customPrice ));
260
386
261
387
$ this ->processor ->prepare ($ this ->itemMock , $ this ->objectMock , $ this ->productMock );
262
388
}
263
389
264
- public function testPrepareResetCount ()
390
+ public function testPrepareWithResetCountAndNotStickAndSameItemId ()
265
391
{
266
392
$ qty = 3000000000 ;
267
393
$ customPrice = 400000000 ;
394
+ $ itemId = 1 ;
395
+ $ requestItemId = 1 ;
268
396
269
397
$ this ->objectMock ->expects ($ this ->any ())
270
398
->method ('getResetCount ' )
271
399
->will ($ this ->returnValue (true ));
272
400
273
401
$ this ->itemMock ->expects ($ this ->any ())
402
+ ->method ('getId ' )
403
+ ->will ($ this ->returnValue ($ itemId ));
404
+ $ this ->itemMock ->expects ($ this ->once ())
274
405
->method ('setData ' )
275
406
->with (CartItemInterface::KEY_QTY , 0 );
276
407
277
408
$ this ->productMock ->expects ($ this ->any ())
278
409
->method ('getCartQty ' )
279
410
->will ($ this ->returnValue ($ qty ));
411
+ $ this ->productMock ->expects ($ this ->any ())
412
+ ->method ('getStickWithinParent ' )
413
+ ->will ($ this ->returnValue (false ));
280
414
281
- $ this ->itemMock ->expects ($ this ->any ())
415
+ $ this ->itemMock ->expects ($ this ->once ())
282
416
->method ('addQty ' )
283
417
->with ($ qty );
284
418
285
419
$ this ->objectMock ->expects ($ this ->any ())
286
420
->method ('getCustomPrice ' )
287
421
->will ($ this ->returnValue ($ customPrice ));
422
+ $ this ->objectMock ->expects ($ this ->any ())
423
+ ->method ('getId ' )
424
+ ->will ($ this ->returnValue ($ requestItemId ));
288
425
289
- $ this ->itemMock ->expects ($ this ->any ())
426
+ $ this ->itemMock ->expects ($ this ->once ())
290
427
->method ('setCustomPrice ' )
291
428
->will ($ this ->returnValue ($ customPrice ));
292
- $ this ->itemMock ->expects ($ this ->any ())
429
+ $ this ->itemMock ->expects ($ this ->once ())
293
430
->method ('setOriginalCustomPrice ' )
294
431
->will ($ this ->returnValue ($ customPrice ));
295
432
0 commit comments