21
21
use Magento \GroupedProduct \Model \Product \Type \Grouped as GroupedProductType ;
22
22
use Magento \GroupedProduct \Ui \DataProvider \Product \Form \Modifier \Grouped ;
23
23
use Magento \Store \Api \Data \StoreInterface ;
24
+ use Magento \Catalog \Model \Product ;
25
+ use Magento \GroupedProduct \Model \Product \Link \CollectionProvider \Grouped as GroupedProducts ;
26
+ use Magento \Catalog \Api \Data \ProductLinkInterfaceFactory ;
24
27
25
28
/**
26
29
* Class GroupedTest
@@ -82,23 +85,38 @@ class GroupedTest extends AbstractModifierTest
82
85
*/
83
86
protected $ storeMock ;
84
87
88
+ /**
89
+ * @var GroupedProducts|\PHPUnit_Framework_MockObject_MockObject
90
+ */
91
+ private $ groupedProductsMock ;
92
+
93
+ /**
94
+ * @var ProductLinkInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
95
+ */
96
+ private $ productLinkFactoryMock ;
97
+
98
+ /**
99
+ * @inheritdoc
100
+ */
85
101
protected function setUp ()
86
102
{
87
103
$ this ->objectManager = new ObjectManager ($ this );
88
104
$ this ->locatorMock = $ this ->getMockBuilder (LocatorInterface::class)
89
105
->getMockForAbstractClass ();
90
- $ this ->productMock = $ this ->getMockBuilder (ProductInterface ::class)
106
+ $ this ->productMock = $ this ->getMockBuilder (Product ::class)
91
107
->setMethods (['getId ' , 'getTypeId ' ])
92
- ->getMockForAbstractClass ();
108
+ ->disableOriginalConstructor ()
109
+ ->getMock ();
93
110
$ this ->productMock ->expects ($ this ->any ())
94
111
->method ('getId ' )
95
112
->willReturn (self ::PRODUCT_ID );
96
113
$ this ->productMock ->expects ($ this ->any ())
97
114
->method ('getTypeId ' )
98
115
->willReturn (GroupedProductType::TYPE_CODE );
99
- $ this ->linkedProductMock = $ this ->getMockBuilder (ProductInterface ::class)
116
+ $ this ->linkedProductMock = $ this ->getMockBuilder (Product ::class)
100
117
->setMethods (['getId ' , 'getName ' , 'getPrice ' ])
101
- ->getMockForAbstractClass ();
118
+ ->disableOriginalConstructor ()
119
+ ->getMock ();
102
120
$ this ->linkedProductMock ->expects ($ this ->any ())
103
121
->method ('getId ' )
104
122
->willReturn (self ::LINKED_PRODUCT_ID );
@@ -135,7 +153,7 @@ protected function setUp()
135
153
$ this ->linkRepositoryMock ->expects ($ this ->any ())
136
154
->method ('getList ' )
137
155
->with ($ this ->productMock )
138
- ->willReturn ([$ this ->linkMock ]);
156
+ ->willReturn ([$ this ->linkedProductMock ]);
139
157
$ this ->productRepositoryMock = $ this ->getMockBuilder (ProductRepositoryInterface::class)
140
158
->setMethods (['get ' ])
141
159
->getMockForAbstractClass ();
@@ -155,7 +173,7 @@ protected function setUp()
155
173
}
156
174
157
175
/**
158
- * { @inheritdoc}
176
+ * @inheritdoc
159
177
*/
160
178
protected function createModel ()
161
179
{
@@ -169,6 +187,16 @@ protected function createModel()
169
187
->setMethods (['init ' , 'getUrl ' ])
170
188
->disableOriginalConstructor ()
171
189
->getMock ();
190
+
191
+ $ this ->groupedProductsMock = $ this ->getMockBuilder (GroupedProducts::class)
192
+ ->setMethods (['getLinkedProducts ' ])
193
+ ->disableOriginalConstructor ()
194
+ ->getMock ();
195
+ $ this ->productLinkFactoryMock = $ this ->getMockBuilder (ProductLinkInterfaceFactory::class)
196
+ ->setMethods (['create ' ])
197
+ ->disableOriginalConstructor ()
198
+ ->getMockForAbstractClass ();
199
+
172
200
$ this ->imageHelperMock ->expects ($ this ->any ())
173
201
->method ('init ' )
174
202
->willReturn ($ this ->imageHelperMock );
@@ -189,16 +217,23 @@ protected function createModel()
189
217
'localeCurrency ' => $ this ->currencyMock ,
190
218
'imageHelper ' => $ this ->imageHelperMock ,
191
219
'attributeSetRepository ' => $ this ->attributeSetRepositoryMock ,
220
+ 'groupedProducts ' => $ this ->groupedProductsMock ,
221
+ 'productLinkFactory ' => $ this ->productLinkFactoryMock ,
192
222
]);
193
223
}
194
224
225
+ /**
226
+ * Assert array has key
227
+ *
228
+ * @return void
229
+ */
195
230
public function testModifyMeta ()
196
231
{
197
232
$ this ->assertArrayHasKey (Grouped::GROUP_GROUPED , $ this ->getModel ()->modifyMeta ([]));
198
233
}
199
234
200
235
/**
201
- * { @inheritdoc}
236
+ * @inheritdoc
202
237
*/
203
238
public function testModifyData ()
204
239
{
@@ -226,6 +261,42 @@ public function testModifyData()
226
261
],
227
262
],
228
263
];
229
- $ this ->assertSame ($ expectedData , $ this ->getModel ()->modifyData ([]));
264
+ $ model = $ this ->getModel ();
265
+ $ linkedProductMock = $ this ->getMockBuilder (Product::class)
266
+ ->setMethods (['getId ' , 'getName ' , 'getPrice ' , 'getSku ' , 'getImage ' , 'getPosition ' , 'getQty ' ])
267
+ ->disableOriginalConstructor ()
268
+ ->getMock ();
269
+ $ linkedProductMock ->expects ($ this ->once ())
270
+ ->method ('getId ' )
271
+ ->willReturn (self ::LINKED_PRODUCT_ID );
272
+ $ linkedProductMock ->expects ($ this ->once ())
273
+ ->method ('getName ' )
274
+ ->willReturn (self ::LINKED_PRODUCT_NAME );
275
+ $ linkedProductMock ->expects ($ this ->once ())
276
+ ->method ('getPrice ' )
277
+ ->willReturn (self ::LINKED_PRODUCT_PRICE );
278
+ $ linkedProductMock ->expects ($ this ->once ())
279
+ ->method ('getSku ' )
280
+ ->willReturn (self ::LINKED_PRODUCT_SKU );
281
+ $ linkedProductMock ->expects ($ this ->once ())
282
+ ->method ('getImage ' )
283
+ ->willReturn ('' );
284
+ $ linkedProductMock ->expects ($ this ->exactly (2 ))
285
+ ->method ('getPosition ' )
286
+ ->willReturn (self ::LINKED_PRODUCT_POSITION );
287
+ $ linkedProductMock ->expects ($ this ->once ())
288
+ ->method ('getQty ' )
289
+ ->willReturn (self ::LINKED_PRODUCT_QTY );
290
+ $ this ->groupedProductsMock ->expects ($ this ->once ())
291
+ ->method ('getLinkedProducts ' )
292
+ ->willReturn ([$ linkedProductMock ]);
293
+ $ linkMock = $ this ->getMockBuilder (ProductLinkInterface::class)
294
+ ->getMockForAbstractClass ();
295
+
296
+ $ this ->productLinkFactoryMock ->expects ($ this ->once ())
297
+ ->method ('create ' )
298
+ ->willReturn ($ linkMock );
299
+
300
+ $ this ->assertSame ($ expectedData , $ model ->modifyData ([]));
230
301
}
231
302
}
0 commit comments