9
9
10
10
namespace Magento \Catalog \Api ;
11
11
12
+ use Magento \Catalog \Model \ProductRepository ;
12
13
use Magento \TestFramework \Helper \Bootstrap ;
13
14
use Magento \TestFramework \TestCase \WebapiAbstract ;
14
15
@@ -39,7 +40,7 @@ protected function setUp()
39
40
public function testRemove ()
40
41
{
41
42
$ sku = 'simple ' ;
42
- /** @var \Magento\Catalog\Model\ ProductRepository $productRepository */
43
+ /** @var ProductRepository $productRepository */
43
44
$ productRepository = $ this ->objectManager ->create (
44
45
'Magento\Catalog\Model\ProductRepository '
45
46
);
@@ -142,7 +143,7 @@ public function testGetList()
142
143
* @magentoApiDataFixture Magento/Catalog/_files/product_without_options.php
143
144
* @magentoAppIsolation enabled
144
145
* @dataProvider optionDataProvider
145
- * @SuppressWarnings(PHPMD.UnusedLocalVariable)
146
+ * @param array $optionData
146
147
*/
147
148
public function testSave ($ optionData )
148
149
{
@@ -166,7 +167,7 @@ public function testSave($optionData)
166
167
unset($ result ['product_sku ' ]);
167
168
unset($ result ['option_id ' ]);
168
169
if (!empty ($ result ['values ' ])) {
169
- foreach ($ result ['values ' ] as $ key => $ value ) {
170
+ foreach (array_keys ( $ result ['values ' ]) as $ key ) {
170
171
unset($ result ['values ' ][$ key ]['option_type_id ' ]);
171
172
}
172
173
}
@@ -240,7 +241,7 @@ public function optionNegativeDataProvider()
240
241
public function testUpdate ()
241
242
{
242
243
$ productSku = 'simple ' ;
243
- /** @var \Magento\Catalog\Model\ ProductRepository $productRepository */
244
+ /** @var ProductRepository $productRepository */
244
245
$ productRepository = $ this ->objectManager ->create (
245
246
'Magento\Catalog\Model\ProductRepository '
246
247
);
@@ -306,7 +307,7 @@ public function testUpdateOptionAddingNewValue($optionType)
306
307
'sort_order ' => 100 ,
307
308
];
308
309
309
- /** @var \Magento\Catalog\Model\ ProductRepository $productRepository */
310
+ /** @var ProductRepository $productRepository */
310
311
$ productRepository = $ this ->objectManager ->create (
311
312
'Magento\Catalog\Model\ProductRepository '
312
313
);
@@ -380,4 +381,48 @@ public function validOptionDataProvider()
380
381
'multiple ' => ['multiple ' ]
381
382
];
382
383
}
384
+
385
+ /**
386
+ * @magentoApiDataFixture Magento/Catalog/_files/product_with_options.php
387
+ * @magentoAppIsolation enabled
388
+ * @dataProvider optionNegativeUpdateDataProvider
389
+ * @param array $optionData
390
+ * @param string $message
391
+ */
392
+ public function testUpdateNegative ($ optionData , $ message )
393
+ {
394
+ $ productSku = 'simple ' ;
395
+ /** @var ProductRepository $productRepository */
396
+ $ productRepository = $ this ->objectManager ->create (ProductRepository::class);
397
+ $ options = $ productRepository ->get ($ productSku , true )->getOptions ();
398
+ $ option = array_shift ($ options );
399
+ $ optionId = $ option ->getOptionId ();
400
+
401
+ $ serviceInfo = [
402
+ 'rest ' => [
403
+ 'resourcePath ' => '/V1/products/options/ ' . $ optionId ,
404
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_PUT ,
405
+ ],
406
+ 'soap ' => [
407
+ 'service ' => self ::SERVICE_NAME ,
408
+ 'serviceVersion ' => 'V1 ' ,
409
+ 'operation ' => self ::SERVICE_NAME . 'Save ' ,
410
+ ],
411
+ ];
412
+
413
+ if (TESTS_WEB_API_ADAPTER == self ::ADAPTER_SOAP ) {
414
+ $ this ->setExpectedException ('SoapFault ' );
415
+ } else {
416
+ $ this ->setExpectedException ('Exception ' , $ message , 400 );
417
+ }
418
+ $ this ->_webApiCall ($ serviceInfo , ['option ' => $ optionData ]);
419
+ }
420
+
421
+ /**
422
+ * @return array
423
+ */
424
+ public function optionNegativeUpdateDataProvider ()
425
+ {
426
+ return include '_files/product_options_update_negative.php ' ;
427
+ }
383
428
}
0 commit comments