20
20
use Magento \GroupedImportExport ;
21
21
use Magento \GroupedImportExport \Model \Import \Product \Type \Grouped ;
22
22
use Magento \GroupedImportExport \Model \Import \Product \Type \Grouped \Links ;
23
+ use Magento \Catalog \Model \ProductTypes \ConfigInterface ;
23
24
use Magento \ImportExport \Test \Unit \Model \Import \AbstractImportTestCase ;
24
25
use PHPUnit \Framework \MockObject \MockObject ;
25
26
@@ -73,6 +74,11 @@ class GroupedTest extends AbstractImportTestCase
73
74
*/
74
75
protected $ links ;
75
76
77
+ /**
78
+ * @var ConfigInterface|MockObject
79
+ */
80
+ private $ configMock ;
81
+
76
82
/**
77
83
* @var Product|MockObject
78
84
*/
@@ -117,6 +123,10 @@ protected function setUp(): void
117
123
1 => 'grouped '
118
124
];
119
125
$ this ->links = $ this ->createMock (Links::class);
126
+ $ this ->configMock = $ this ->getMockForAbstractClass (ConfigInterface::class);
127
+ $ this ->configMock ->expects ($ this ->once ())
128
+ ->method ('getComposableTypes ' )
129
+ ->willReturn (['simple ' , 'virtual ' , 'downloadable ' ]);
120
130
$ entityAttributes = [
121
131
[
122
132
'attribute_set_name ' => 'attribute_id ' ,
@@ -156,7 +166,8 @@ protected function setUp(): void
156
166
'prodAttrColFac ' => $ this ->attrCollectionFactory ,
157
167
'resource ' => $ this ->resource ,
158
168
'params ' => $ this ->params ,
159
- 'links ' => $ this ->links
169
+ 'links ' => $ this ->links ,
170
+ 'config ' => $ this ->configMock
160
171
]
161
172
);
162
173
$ metadataPoolMock = $ this ->createMock (MetadataPool::class);
@@ -214,10 +225,10 @@ public function saveDataProvider(): array
214
225
[
215
226
'skus ' => [
216
227
'newSku ' => [
217
- 'sku_assoc1 ' => ['entity_id ' => 1 ],
228
+ 'sku_assoc1 ' => ['entity_id ' => 1 , ' type_id ' => ' simple ' ],
218
229
'productsku ' => ['entity_id ' => 3 , 'attr_set_code ' => 'Default ' , 'type_id ' => 'grouped ' ]
219
230
],
220
- 'oldSku ' => ['sku_assoc2 ' => ['entity_id ' => 2 ]]
231
+ 'oldSku ' => ['sku_assoc2 ' => ['entity_id ' => 2 , ' type_id ' => ' simple ' ]]
221
232
],
222
233
'bunch ' => [
223
234
'associated_skus ' => 'sku_assoc1=1, sku_assoc2=2 ' ,
@@ -249,7 +260,7 @@ public function saveDataProvider(): array
249
260
[
250
261
'skus ' => [
251
262
'newSku ' => [
252
- 'sku_assoc1 ' => ['entity_id ' => 1 ],
263
+ 'sku_assoc1 ' => ['entity_id ' => 1 , ' type_id ' => ' simple ' ],
253
264
'productsku ' => ['entity_id ' => 3 , 'attr_set_code ' => 'Default ' , 'type_id ' => 'grouped ' ]
254
265
],
255
266
'oldSku ' => []
@@ -272,13 +283,13 @@ public function testSaveDataScopeStore(): void
272
283
{
273
284
$ this ->entityModel ->expects ($ this ->once ())->method ('getNewSku ' )->willReturn (
274
285
[
275
- 'sku_assoc1 ' => ['entity_id ' => 1 ],
286
+ 'sku_assoc1 ' => ['entity_id ' => 1 , ' type_id ' => ' simple ' ],
276
287
'productsku ' => ['entity_id ' => 2 , 'attr_set_code ' => 'Default ' , 'type_id ' => 'grouped ' ]
277
288
]
278
289
);
279
290
$ this ->entityModel ->expects ($ this ->once ())->method ('getOldSku ' )->willReturn (
280
291
[
281
- 'sku_assoc2 ' => ['entity_id ' => 3 ]
292
+ 'sku_assoc2 ' => ['entity_id ' => 3 , ' type_id ' => ' simple ' ]
282
293
]
283
294
);
284
295
$ attributes = ['position ' => ['id ' => 0 ], 'qty ' => ['id ' => 0 ]];
@@ -302,4 +313,48 @@ public function testSaveDataScopeStore(): void
302
313
$ this ->links ->expects ($ this ->once ())->method ('saveLinksData ' );
303
314
$ this ->grouped ->saveData ();
304
315
}
316
+
317
+ /**
318
+ * Test saveData() with composite product associated with a grouped product
319
+ *
320
+ * @return void
321
+ */
322
+ public function testSaveDataAssociatedComposite (): void
323
+ {
324
+ $ this ->entityModel ->expects ($ this ->once ())->method ('getNewSku ' )->willReturn (
325
+ [
326
+ 'sku_assoc1 ' => ['entity_id ' => 1 , 'type_id ' => 'configurable ' ],
327
+ 'productsku ' => ['entity_id ' => 2 , 'attr_set_code ' => 'Default ' , 'type_id ' => 'grouped ' ]
328
+ ]
329
+ );
330
+ $ this ->entityModel ->expects ($ this ->once ())->method ('getOldSku ' )->willReturn ([]);
331
+ $ attributes = ['position ' => ['id ' => 0 ], 'qty ' => ['id ' => 0 ]];
332
+ $ this ->links ->expects ($ this ->once ())->method ('getAttributes ' )->willReturn ($ attributes );
333
+
334
+ $ bunch = [
335
+ [
336
+ 'associated_skus ' => 'sku_assoc1=1 ' ,
337
+ 'sku ' => 'productsku ' ,
338
+ 'product_type ' => 'grouped '
339
+ ]
340
+ ];
341
+
342
+ $ this ->entityModel ->expects ($ this ->any ())->method ('isRowAllowedToImport ' )->willReturn (true );
343
+ $ this ->entityModel
344
+ ->method ('getNextBunch ' )
345
+ ->willReturnOnConsecutiveCalls ($ bunch );
346
+ $ this ->entityModel
347
+ ->method ('getRowScope ' )
348
+ ->willReturnOnConsecutiveCalls (Product::SCOPE_DEFAULT , Product::SCOPE_STORE );
349
+
350
+ $ expectedLinkData = [
351
+ 'product_ids ' => [],
352
+ 'attr_product_ids ' => [],
353
+ 'position ' => [],
354
+ 'qty ' => [],
355
+ 'relation ' => []
356
+ ];
357
+ $ this ->links ->expects ($ this ->once ())->method ('saveLinksData ' )->with ($ expectedLinkData );
358
+ $ this ->grouped ->saveData ();
359
+ }
305
360
}
0 commit comments