@@ -207,4 +207,57 @@ public function testGetListNotConfigurableProduct()
207
207
208
208
$ this ->model ->getList ($ productSku );
209
209
}
210
+
211
+ /**
212
+ * @param int $attributeId
213
+ * @param string $label
214
+ * @param array $optionValues
215
+ * @param string $msg
216
+ * @dataProvider validateOptionDataProvider
217
+ * @throws \Magento\Framework\Exception\InputException
218
+ */
219
+ public function testValidateNewOptionData ($ attributeId , $ label , $ optionValues , $ msg )
220
+ {
221
+ $ this ->setExpectedException ('Magento\Framework\Exception\InputException ' , $ msg );
222
+ $ optionValueMock = $ this ->getMock ('\Magento\ConfigurableProduct\Api\Data\OptionValueInterface ' );
223
+ $ optionValuesMock = [];
224
+ if (!empty ($ optionValues )) {
225
+ $ optionValueMock ->expects ($ this ->any ())
226
+ ->method ('getValueIndex ' )
227
+ ->willReturn ($ optionValues ['v ' ]);
228
+ $ optionValueMock ->expects ($ this ->any ())
229
+ ->method ('getPricingValue ' )
230
+ ->willReturn ($ optionValues ['p ' ]);
231
+ $ optionValueMock ->expects ($ this ->any ())
232
+ ->method ('getIsPercent ' )
233
+ ->willReturn ($ optionValues ['r ' ]);
234
+ $ optionValuesMock = [$ optionValueMock ];
235
+ }
236
+
237
+ $ optionMock = $ this ->getMock ('\Magento\ConfigurableProduct\Api\Data\OptionInterface ' );
238
+ $ optionMock ->expects ($ this ->any ())
239
+ ->method ('getAttributeId ' )
240
+ ->willReturn ($ attributeId );
241
+ $ optionMock ->expects ($ this ->any ())
242
+ ->method ('getLabel ' )
243
+ ->willReturn ($ label );
244
+ $ optionMock ->expects ($ this ->any ())
245
+ ->method ('getValues ' )
246
+ ->willReturn ($ optionValuesMock );
247
+
248
+ $ this ->model ->validateNewOptionData ($ optionMock );
249
+ }
250
+
251
+ public function validateOptionDataProvider ()
252
+ {
253
+ return [
254
+ [null , '' , ['v ' => null , 'p ' => null , 'r ' => null ], 'One or more input exceptions have occurred. ' ],
255
+ [1 , 'Label ' , [], 'Option values are not specified. ' ],
256
+ [null , 'Label ' , ['v ' => 1 , 'p ' => 1 , 'r ' => 1 ], 'Option attribute ID is not specified. ' ],
257
+ [1 , '' , ['v ' => 1 , 'p ' => 1 , 'r ' => 1 ], 'Option label is not specified. ' ],
258
+ [1 , 'Label ' , ['v ' => null , 'p ' => 1 , 'r ' => 1 ], 'Value index is not specified for an option. ' ],
259
+ [1 , 'Label ' , ['v ' => 1 , 'p ' => null , 'r ' => 1 ], 'Price is not specified for an option. ' ],
260
+ [1 , 'Label ' , ['v ' => 1 , 'p ' => 1 , 'r ' => null ], 'Percent/absolute is not specified for an option. ' ],
261
+ ];
262
+ }
210
263
}
0 commit comments