2020use Magento \GroupedImportExport ;
2121use Magento \GroupedImportExport \Model \Import \Product \Type \Grouped ;
2222use Magento \GroupedImportExport \Model \Import \Product \Type \Grouped \Links ;
23+ use Magento \Catalog \Model \ProductTypes \ConfigInterface ;
2324use Magento \ImportExport \Test \Unit \Model \Import \AbstractImportTestCase ;
2425use PHPUnit \Framework \MockObject \MockObject ;
2526
@@ -73,6 +74,11 @@ class GroupedTest extends AbstractImportTestCase
7374 */
7475 protected $ links ;
7576
77+ /**
78+ * @var ConfigInterface|MockObject
79+ */
80+ private $ configMock ;
81+
7682 /**
7783 * @var Product|MockObject
7884 */
@@ -117,6 +123,10 @@ protected function setUp(): void
117123 1 => 'grouped '
118124 ];
119125 $ 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 ' ]);
120130 $ entityAttributes = [
121131 [
122132 'attribute_set_name ' => 'attribute_id ' ,
@@ -156,7 +166,8 @@ protected function setUp(): void
156166 'prodAttrColFac ' => $ this ->attrCollectionFactory ,
157167 'resource ' => $ this ->resource ,
158168 'params ' => $ this ->params ,
159- 'links ' => $ this ->links
169+ 'links ' => $ this ->links ,
170+ 'config ' => $ this ->configMock
160171 ]
161172 );
162173 $ metadataPoolMock = $ this ->createMock (MetadataPool::class);
@@ -214,10 +225,10 @@ public function saveDataProvider(): array
214225 [
215226 'skus ' => [
216227 'newSku ' => [
217- 'sku_assoc1 ' => ['entity_id ' => 1 ],
228+ 'sku_assoc1 ' => ['entity_id ' => 1 , ' type_id ' => ' simple ' ],
218229 'productsku ' => ['entity_id ' => 3 , 'attr_set_code ' => 'Default ' , 'type_id ' => 'grouped ' ]
219230 ],
220- 'oldSku ' => ['sku_assoc2 ' => ['entity_id ' => 2 ]]
231+ 'oldSku ' => ['sku_assoc2 ' => ['entity_id ' => 2 , ' type_id ' => ' simple ' ]]
221232 ],
222233 'bunch ' => [
223234 'associated_skus ' => 'sku_assoc1=1, sku_assoc2=2 ' ,
@@ -249,7 +260,7 @@ public function saveDataProvider(): array
249260 [
250261 'skus ' => [
251262 'newSku ' => [
252- 'sku_assoc1 ' => ['entity_id ' => 1 ],
263+ 'sku_assoc1 ' => ['entity_id ' => 1 , ' type_id ' => ' simple ' ],
253264 'productsku ' => ['entity_id ' => 3 , 'attr_set_code ' => 'Default ' , 'type_id ' => 'grouped ' ]
254265 ],
255266 'oldSku ' => []
@@ -272,13 +283,13 @@ public function testSaveDataScopeStore(): void
272283 {
273284 $ this ->entityModel ->expects ($ this ->once ())->method ('getNewSku ' )->willReturn (
274285 [
275- 'sku_assoc1 ' => ['entity_id ' => 1 ],
286+ 'sku_assoc1 ' => ['entity_id ' => 1 , ' type_id ' => ' simple ' ],
276287 'productsku ' => ['entity_id ' => 2 , 'attr_set_code ' => 'Default ' , 'type_id ' => 'grouped ' ]
277288 ]
278289 );
279290 $ this ->entityModel ->expects ($ this ->once ())->method ('getOldSku ' )->willReturn (
280291 [
281- 'sku_assoc2 ' => ['entity_id ' => 3 ]
292+ 'sku_assoc2 ' => ['entity_id ' => 3 , ' type_id ' => ' simple ' ]
282293 ]
283294 );
284295 $ attributes = ['position ' => ['id ' => 0 ], 'qty ' => ['id ' => 0 ]];
@@ -302,4 +313,48 @@ public function testSaveDataScopeStore(): void
302313 $ this ->links ->expects ($ this ->once ())->method ('saveLinksData ' );
303314 $ this ->grouped ->saveData ();
304315 }
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+ }
305360}
0 commit comments