8
8
use Magento \GroupedProduct \Model \Product \Type \Grouped ;
9
9
10
10
/**
11
+ * Tests for Grouped product
12
+ *
11
13
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12
14
*/
13
15
class GroupedTest extends \PHPUnit \Framework \TestCase
@@ -42,6 +44,9 @@ class GroupedTest extends \PHPUnit\Framework\TestCase
42
44
*/
43
45
private $ serializer ;
44
46
47
+ /**
48
+ * @inheritdoc
49
+ */
45
50
protected function setUp ()
46
51
{
47
52
$ this ->objectHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
@@ -74,12 +79,22 @@ protected function setUp()
74
79
);
75
80
}
76
81
77
- public function testHasWeightFalse ()
82
+ /**
83
+ * Verify has weight is false
84
+ *
85
+ * @return void
86
+ */
87
+ public function testHasWeightFalse (): void
78
88
{
79
89
$ this ->assertFalse ($ this ->_model ->hasWeight (), 'This product has weight, but it should not ' );
80
90
}
81
91
82
- public function testGetChildrenIds ()
92
+ /**
93
+ * Verify children ids.
94
+ *
95
+ * @return void
96
+ */
97
+ public function testGetChildrenIds (): void
83
98
{
84
99
$ parentId = 12345 ;
85
100
$ childrenIds = [100 , 200 , 300 ];
@@ -96,7 +111,12 @@ public function testGetChildrenIds()
96
111
$ this ->assertEquals ($ childrenIds , $ this ->_model ->getChildrenIds ($ parentId ));
97
112
}
98
113
99
- public function testGetParentIdsByChild ()
114
+ /**
115
+ * Verify get parents by child products
116
+ *
117
+ * @return void
118
+ */
119
+ public function testGetParentIdsByChild (): void
100
120
{
101
121
$ childId = 12345 ;
102
122
$ parentIds = [100 , 200 , 300 ];
@@ -113,7 +133,12 @@ public function testGetParentIdsByChild()
113
133
$ this ->assertEquals ($ parentIds , $ this ->_model ->getParentIdsByChild ($ childId ));
114
134
}
115
135
116
- public function testGetAssociatedProducts ()
136
+ /**
137
+ * Verify get associated products
138
+ *
139
+ * @return void
140
+ */
141
+ public function testGetAssociatedProducts (): void
117
142
{
118
143
$ cached = true ;
119
144
$ associatedProducts = [5 , 7 , 11 , 13 , 17 ];
@@ -123,27 +148,36 @@ public function testGetAssociatedProducts()
123
148
}
124
149
125
150
/**
151
+ * Verify able to set status filter
152
+ *
126
153
* @param int $status
127
154
* @param array $filters
128
155
* @param array $result
129
156
* @dataProvider addStatusFilterDataProvider
130
157
*/
131
- public function testAddStatusFilter ($ status , $ filters , $ result )
158
+ public function testAddStatusFilter ($ status , $ filters , $ result ): void
132
159
{
133
160
$ this ->product ->expects ($ this ->once ())->method ('getData ' )->will ($ this ->returnValue ($ filters ));
134
161
$ this ->product ->expects ($ this ->once ())->method ('setData ' )->with ('_cache_instance_status_filters ' , $ result );
135
162
$ this ->assertEquals ($ this ->_model , $ this ->_model ->addStatusFilter ($ status , $ this ->product ));
136
163
}
137
164
138
165
/**
166
+ * Data Provider for Status Filter
167
+ *
139
168
* @return array
140
169
*/
141
- public function addStatusFilterDataProvider ()
170
+ public function addStatusFilterDataProvider (): array
142
171
{
143
172
return [[1 , [], [1 ]], [1 , false , [1 ]]];
144
173
}
145
174
146
- public function testSetSaleableStatus ()
175
+ /**
176
+ * Verify able to set salable status
177
+ *
178
+ * @return void
179
+ */
180
+ public function testSetSaleableStatus (): void
147
181
{
148
182
$ key = '_cache_instance_status_filters ' ;
149
183
$ saleableIds = [300 , 800 , 500 ];
@@ -159,7 +193,12 @@ public function testSetSaleableStatus()
159
193
$ this ->assertEquals ($ this ->_model , $ this ->_model ->setSaleableStatus ($ this ->product ));
160
194
}
161
195
162
- public function testGetStatusFiltersNoData ()
196
+ /**
197
+ * Verify status filter with no data.
198
+ *
199
+ * @return void
200
+ */
201
+ public function testGetStatusFiltersNoData (): void
163
202
{
164
203
$ result = [
165
204
\Magento \Catalog \Model \Product \Attribute \Source \Status::STATUS_ENABLED ,
@@ -169,7 +208,12 @@ public function testGetStatusFiltersNoData()
169
208
$ this ->assertEquals ($ result , $ this ->_model ->getStatusFilters ($ this ->product ));
170
209
}
171
210
172
- public function testGetStatusFiltersWithData ()
211
+ /**
212
+ * Verify status filter with data
213
+ *
214
+ * @return void
215
+ */
216
+ public function testGetStatusFiltersWithData (): void
173
217
{
174
218
$ result = [
175
219
\Magento \Catalog \Model \Product \Attribute \Source \Status::STATUS_ENABLED ,
@@ -180,7 +224,12 @@ public function testGetStatusFiltersWithData()
180
224
$ this ->assertEquals ($ result , $ this ->_model ->getStatusFilters ($ this ->product ));
181
225
}
182
226
183
- public function testGetAssociatedProductIdsCached ()
227
+ /**
228
+ * Verify AssociatedProducts Ids with cache
229
+ *
230
+ * @return void
231
+ */
232
+ public function testGetAssociatedProductIdsCached (): void
184
233
{
185
234
$ key = '_cache_instance_associated_product_ids ' ;
186
235
$ cachedData = [300 , 303 , 306 ];
@@ -192,7 +241,12 @@ public function testGetAssociatedProductIdsCached()
192
241
$ this ->assertEquals ($ cachedData , $ this ->_model ->getAssociatedProductIds ($ this ->product ));
193
242
}
194
243
195
- public function testGetAssociatedProductIdsNonCached ()
244
+ /**
245
+ * Verify AssociatedProducts Ids with no cached.
246
+ *
247
+ * @return void
248
+ */
249
+ public function testGetAssociatedProductIdsNonCached (): void
196
250
{
197
251
$ args = $ this ->objectHelper ->getConstructArguments (
198
252
\Magento \GroupedProduct \Model \Product \Type \Grouped::class,
@@ -236,7 +290,12 @@ public function testGetAssociatedProductIdsNonCached()
236
290
$ this ->assertEquals ($ associatedIds , $ model ->getAssociatedProductIds ($ this ->product ));
237
291
}
238
292
239
- public function testGetAssociatedProductCollection ()
293
+ /**
294
+ * Verify Associated Product collection
295
+ *
296
+ * @return void
297
+ */
298
+ public function testGetAssociatedProductCollection (): void
240
299
{
241
300
$ link = $ this ->createPartialMock (
242
301
\Magento \Catalog \Model \Product \Link::class,
@@ -261,6 +320,8 @@ public function testGetAssociatedProductCollection()
261
320
}
262
321
263
322
/**
323
+ * Verify Proccess buy request
324
+ *
264
325
* @param array $superGroup
265
326
* @param array $result
266
327
* @dataProvider processBuyRequestDataProvider
@@ -274,9 +335,11 @@ public function testProcessBuyRequest($superGroup, $result)
274
335
}
275
336
276
337
/**
338
+ * dataProvider for buy request
339
+ *
277
340
* @return array
278
341
*/
279
- public function processBuyRequestDataProvider ()
342
+ public function processBuyRequestDataProvider (): array
280
343
{
281
344
return [
282
345
'positive ' => [[1 , 2 , 3 ], ['super_group ' => [1 , 2 , 3 ]]],
@@ -285,9 +348,12 @@ public function processBuyRequestDataProvider()
285
348
}
286
349
287
350
/**
351
+ * Get Children Msrp when children product with Msrp
352
+ *
353
+ * @return void
288
354
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
289
355
*/
290
- public function testGetChildrenMsrpWhenNoChildrenWithMsrp ()
356
+ public function testGetChildrenMsrpWhenNoChildrenWithMsrp (): void
291
357
{
292
358
$ key = '_cache_instance_associated_products ' ;
293
359
@@ -298,7 +364,12 @@ public function testGetChildrenMsrpWhenNoChildrenWithMsrp()
298
364
$ this ->assertEquals (0 , $ this ->_model ->getChildrenMsrp ($ this ->product ));
299
365
}
300
366
301
- public function testPrepareForCartAdvancedEmpty ()
367
+ /**
368
+ * Prepare for card method with advanced empty
369
+ *
370
+ * @return void
371
+ */
372
+ public function testPrepareForCartAdvancedEmpty (): void
302
373
{
303
374
$ this ->product = $ this ->createMock (\Magento \Catalog \Model \Product::class);
304
375
$ buyRequest = new \Magento \Framework \DataObject ();
@@ -381,7 +452,12 @@ public function testPrepareForCartAdvancedEmpty()
381
452
);
382
453
}
383
454
384
- public function testPrepareForCartAdvancedNoProductsStrictTrue ()
455
+ /**
456
+ * Prepare for card with no products set strict option true
457
+ *
458
+ * @return void
459
+ */
460
+ public function testPrepareForCartAdvancedNoProductsStrictTrue (): void
385
461
{
386
462
$ buyRequest = new \Magento \Framework \DataObject ();
387
463
$ buyRequest ->setSuperGroup ([0 => 0 ]);
@@ -404,7 +480,12 @@ public function testPrepareForCartAdvancedNoProductsStrictTrue()
404
480
);
405
481
}
406
482
407
- public function testPrepareForCartAdvancedNoProductsStrictFalse ()
483
+ /**
484
+ * Prepare for card with no products and set strict to false
485
+ *
486
+ * @return void
487
+ */
488
+ public function testPrepareForCartAdvancedNoProductsStrictFalse (): void
408
489
{
409
490
$ buyRequest = new \Magento \Framework \DataObject ();
410
491
$ buyRequest ->setSuperGroup ([0 => 0 ]);
@@ -429,7 +510,12 @@ public function testPrepareForCartAdvancedNoProductsStrictFalse()
429
510
);
430
511
}
431
512
432
- public function testPrepareForCartAdvancedWithProductsStrictFalseStringResult ()
513
+ /**
514
+ * Verify Prepare for cart product with Product strict flase and string result
515
+ *
516
+ * @return false
517
+ */
518
+ public function testPrepareForCartAdvancedWithProductsStrictFalseStringResult (): void
433
519
{
434
520
$ associatedProduct = $ this ->createMock (\Magento \Catalog \Model \Product::class);
435
521
$ associatedId = 9384 ;
@@ -463,7 +549,12 @@ public function testPrepareForCartAdvancedWithProductsStrictFalseStringResult()
463
549
);
464
550
}
465
551
466
- public function testPrepareForCartAdvancedWithProductsStrictFalseEmptyArrayResult ()
552
+ /**
553
+ * Verify prepare for cart with strict option set to false and empty array
554
+ *
555
+ * @return void
556
+ */
557
+ public function testPrepareForCartAdvancedWithProductsStrictFalseEmptyArrayResult (): void
467
558
{
468
559
$ expectedMsg = "Cannot process the item. " ;
469
560
$ associatedProduct = $ this ->createMock (\Magento \Catalog \Model \Product::class);
@@ -498,7 +589,12 @@ public function testPrepareForCartAdvancedWithProductsStrictFalseEmptyArrayResul
498
589
);
499
590
}
500
591
501
- public function testPrepareForCartAdvancedWithProductsStrictFalse ()
592
+ /**
593
+ * Prepare for cart product with Product strict option st to false.
594
+ *
595
+ * @return void
596
+ */
597
+ public function testPrepareForCartAdvancedWithProductsStrictFalse (): void
502
598
{
503
599
$ associatedProduct = $ this ->createMock (\Magento \Catalog \Model \Product::class);
504
600
$ associatedId = 9384 ;
@@ -541,7 +637,12 @@ public function testPrepareForCartAdvancedWithProductsStrictFalse()
541
637
);
542
638
}
543
639
544
- public function testPrepareForCartAdvancedWithProductsStrictTrue ()
640
+ /**
641
+ * Verify prepare for cart with Product strict option true
642
+ *
643
+ * @return void
644
+ */
645
+ public function testPrepareForCartAdvancedWithProductsStrictTrue (): void
545
646
{
546
647
$ associatedProduct = $ this ->createMock (\Magento \Catalog \Model \Product::class);
547
648
$ associatedId = 9384 ;
@@ -587,15 +688,20 @@ public function testPrepareForCartAdvancedWithProductsStrictTrue()
587
688
);
588
689
}
589
690
590
- public function testPrepareForCartAdvancedZeroQty ()
691
+ /**
692
+ * Verify prepare for card with sold out option
693
+ *
694
+ * @return void
695
+ */
696
+ public function testPrepareForCartAdvancedZeroQtyAndSoldOutOption (): void
591
697
{
592
698
$ expectedMsg = "Please specify the quantity of product(s). " ;
593
- $ associatedId = 9384 ;
699
+ $ associatedId = 91 ;
594
700
$ associatedProduct = $ this ->createMock (\Magento \Catalog \Model \Product::class);
595
- $ associatedProduct ->expects ($ this ->atLeastOnce ())->method ('getId ' )->will ($ this ->returnValue ($ associatedId ));
596
-
701
+ $ associatedProduct ->expects ($ this ->atLeastOnce ())->method ('getId ' )->will ($ this ->returnValue (90 ));
702
+ $ associatedProduct -> expects ( $ this -> once ())-> method ( ' isSalable ' )-> willReturn ( true );
597
703
$ buyRequest = new \Magento \Framework \DataObject ();
598
- $ buyRequest ->setSuperGroup ([$ associatedId => 0 ]);
704
+ $ buyRequest ->setSuperGroup ([$ associatedId => 90 ]);
599
705
600
706
$ cached = true ;
601
707
$ this ->product
@@ -609,7 +715,12 @@ public function testPrepareForCartAdvancedZeroQty()
609
715
$ this ->assertEquals ($ expectedMsg , $ this ->_model ->prepareForCartAdvanced ($ buyRequest , $ this ->product ));
610
716
}
611
717
612
- public function testFlushAssociatedProductsCache ()
718
+ /**
719
+ * Verify flush cache for associated products
720
+ *
721
+ * @return void
722
+ */
723
+ public function testFlushAssociatedProductsCache (): void
613
724
{
614
725
$ productMock = $ this ->createPartialMock (\Magento \Catalog \Model \Product::class, ['unsetData ' ]);
615
726
$ productMock ->expects ($ this ->once ())
0 commit comments