8
8
9
9
namespace Magento \ConfigurableProduct \Test \Unit \Model \Product ;
10
10
11
+ use Magento \Catalog \Model \Product \Type ;
11
12
use Magento \ConfigurableProduct \Model \Product \VariationHandler ;
12
13
13
14
/**
@@ -162,23 +163,30 @@ public function testPrepareAttributeSet()
162
163
163
164
/**
164
165
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
166
+ * @dataProvider dataProviderTestGenerateSimpleProducts
167
+ * @param int|string|null $weight
168
+ * @param string $typeId
165
169
*/
166
- public function testGenerateSimpleProducts ()
170
+ public function testGenerateSimpleProducts ($ weight , $ typeId )
167
171
{
168
172
$ productsData = [
169
- 6 =>
170
- [
171
- 'image ' => 'image.jpg ' ,
172
- 'name ' => 'config-red ' ,
173
- 'configurable_attribute ' => '{"new_attr":"6"} ' ,
174
- 'sku ' => 'config-red ' ,
175
- 'quantity_and_stock_status ' =>
176
- [
177
- 'qty ' => '' ,
178
- ],
179
- 'weight ' => '333 ' ,
180
- ]
173
+ [
174
+ 'image ' => 'image.jpg ' ,
175
+ 'name ' => 'config-red ' ,
176
+ 'configurable_attribute ' => '{"new_attr":"6"} ' ,
177
+ 'sku ' => 'config-red ' ,
178
+ 'quantity_and_stock_status ' =>
179
+ [
180
+ 'qty ' => '' ,
181
+ ],
182
+ ]
181
183
];
184
+
185
+ // Do not add 'weight' attribute if it's value is null!
186
+ if ($ weight !== null ) {
187
+ $ productsData [0 ]['weight ' ] = $ weight ;
188
+ }
189
+
182
190
$ stockData = [
183
191
'manage_stock ' => '0 ' ,
184
192
'use_config_enable_qty_increments ' => '1 ' ,
@@ -218,7 +226,7 @@ public function testGenerateSimpleProducts()
218
226
)
219
227
->disableOriginalConstructor ()
220
228
->getMock ();
221
- $ productTypeMock = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ Product \ Type::class)
229
+ $ productTypeMock = $ this ->getMockBuilder (Type::class)
222
230
->setMethods (['getSetAttributes ' ])
223
231
->disableOriginalConstructor ()
224
232
->getMock ();
@@ -236,7 +244,7 @@ public function testGenerateSimpleProducts()
236
244
->willReturn ('new_attr_set_id ' );
237
245
$ this ->productFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ newSimpleProductMock );
238
246
$ newSimpleProductMock ->expects ($ this ->once ())->method ('setStoreId ' )->with (0 )->willReturnSelf ();
239
- $ newSimpleProductMock ->expects ($ this ->once ())->method ('setTypeId ' )->with (' simple ' )->willReturnSelf ();
247
+ $ newSimpleProductMock ->expects ($ this ->once ())->method ('setTypeId ' )->with ($ typeId )->willReturnSelf ();
240
248
$ newSimpleProductMock ->expects ($ this ->once ())
241
249
->method ('setAttributeSetId ' )
242
250
->with ('new_attr_set_id ' )
@@ -265,6 +273,27 @@ public function testGenerateSimpleProducts()
265
273
$ this ->assertEquals (['product_id ' ], $ this ->model ->generateSimpleProducts ($ parentProductMock , $ productsData ));
266
274
}
267
275
276
+ /**
277
+ * @return array
278
+ */
279
+ public function dataProviderTestGenerateSimpleProducts ()
280
+ {
281
+ return [
282
+ [
283
+ 'weight ' => 333 ,
284
+ 'type_id ' => Type::TYPE_SIMPLE ,
285
+ ],
286
+ [
287
+ 'weight ' => '' ,
288
+ 'type_id ' => Type::TYPE_VIRTUAL ,
289
+ ],
290
+ [
291
+ 'weight ' => null ,
292
+ 'type_id ' => Type::TYPE_VIRTUAL ,
293
+ ],
294
+ ];
295
+ }
296
+
268
297
public function testProcessMediaGalleryWithImagesAndGallery ()
269
298
{
270
299
$ this ->product ->expects ($ this ->atLeastOnce ())->method ('getMediaGallery ' )->with ('images ' )->willReturn ([]);
0 commit comments