File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -319,11 +319,14 @@ public function isStockSpecified(array $productData)
319319 *
320320 * @return array
321321 */
322- private function setStock (array $ productData )
322+ public function setStock (array $ productData )
323323 {
324324 $ newProductData = $ productData ;
325- $ newProductData [self ::QTY_COLUMN_HEADING ] = 1 ;
326- $ newProductData [self ::IS_IN_STOCK_COLUMN_HEADING ] = 1 ;
325+ if (isset ($ productData [self ::IS_IN_STOCK_COLUMN_HEADING ]) &&
326+ $ productData [self ::IS_IN_STOCK_COLUMN_HEADING ] == 1 &&
327+ isset ($ productData [self ::QTY_COLUMN_HEADING ]) == false ) {
328+ $ newProductData [self ::QTY_COLUMN_HEADING ] = 1 ;
329+ }
327330 return $ newProductData ;
328331 }
329332
Original file line number Diff line number Diff line change @@ -212,6 +212,37 @@ public function testStockIsNotSet()
212212 $ this ->assertFalse ($ this ->component ->isStockSpecified ($ testData ));
213213 }
214214
215+ public function testSetStock ()
216+ {
217+ $ testData = [
218+ 'sku ' => 1 ,
219+ 'name ' => 'Test ' ,
220+ 'is_in_stock ' => 1
221+ ];
222+ $ expectedData = [
223+ 'sku ' => 1 ,
224+ 'name ' => 'Test ' ,
225+ 'is_in_stock ' => 1 ,
226+ 'qty ' => 1
227+ ];
228+ $ this ->assertEquals ($ expectedData , $ this ->component ->setStock ($ testData ));
229+ }
230+
231+ public function testNotSetStock ()
232+ {
233+ $ testData = [
234+ 'sku ' => 1 ,
235+ 'name ' => 'Test ' ,
236+ 'is_in_stock ' => 0
237+ ];
238+ $ expectedData = [
239+ 'sku ' => 1 ,
240+ 'name ' => 'Test ' ,
241+ 'is_in_stock ' => 0 ,
242+ ];
243+ $ this ->assertEquals ($ expectedData , $ this ->component ->setStock ($ testData ));
244+ }
245+
215246 private function createProduct ($ productId )
216247 {
217248 $ productMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product ' )
You can’t perform that action at this time.
0 commit comments