25
25
class ProductAttributeOptionManagementInterfaceTest extends WebapiAbstract
26
26
{
27
27
private const ATTRIBUTE_CODE = 'select_attribute ' ;
28
+ private const SERVICE_NAME_UPDATE = 'catalogProductAttributeOptionUpdateV1 ' ;
28
29
private const SERVICE_NAME = 'catalogProductAttributeOptionManagementV1 ' ;
29
30
private const SERVICE_VERSION = 'V1 ' ;
30
31
private const RESOURCE_PATH = '/V1/products/attributes ' ;
@@ -47,7 +48,8 @@ public function testAdd(
47
48
int $ expectedSwatchType ,
48
49
string $ expectedLabel ,
49
50
string $ expectedValue
50
- ) {
51
+ )
52
+ {
51
53
$ objectManager = Bootstrap::getObjectManager ();
52
54
/** @var $attributeRepository AttributeRepository */
53
55
$ attributeRepository = $ objectManager ->get (AttributeRepository::class);
@@ -74,7 +76,7 @@ public function testAdd(
74
76
);
75
77
76
78
$ this ->assertNotNull ($ response );
77
- $ optionId = (int ) ltrim ($ response , 'id_ ' );
79
+ $ optionId = (int )ltrim ($ response , 'id_ ' );
78
80
$ swatch = $ this ->getSwatch ($ optionId );
79
81
$ this ->assertEquals ($ expectedValue , $ swatch ->getValue ());
80
82
$ this ->assertEquals ($ expectedSwatchType , $ swatch ->getType ());
@@ -83,6 +85,41 @@ public function testAdd(
83
85
$ this ->assertEquals ($ expectedLabel , $ options [2 ]->getLabel ());
84
86
}
85
87
88
+ /**
89
+ * @magentoApiDataFixture Magento/Swatches/_files/text_swatch_attribute.php
90
+ */
91
+ public function testUpdate ()
92
+ {
93
+ $ testAttributeCode = 'test_configurable ' ;
94
+ $ optionData = [
95
+ AttributeOptionInterface::LABEL => 'Fixture Option Changed ' ,
96
+ AttributeOptionInterface::VALUE => 'option_value ' ,
97
+ ];
98
+
99
+ $ existOptionLabel = 'option 1 ' ;
100
+ $ existAttributeOption = $ this ->getAttributeOption ($ testAttributeCode , $ existOptionLabel );
101
+ $ optionId = $ existAttributeOption ['value ' ];
102
+
103
+ $ response = $ this ->webApiCallAttributeOptions (
104
+ $ testAttributeCode ,
105
+ Request::HTTP_METHOD_PUT ,
106
+ 'update ' ,
107
+ [
108
+ 'attributeCode ' => $ testAttributeCode ,
109
+ 'optionId ' => $ optionId ,
110
+ 'option ' => $ optionData ,
111
+ ],
112
+ $ optionId
113
+ );
114
+ $ this ->assertTrue ($ response );
115
+ $ this ->assertNotNull (
116
+ $ this ->getAttributeOption (
117
+ $ testAttributeCode ,
118
+ $ optionData [AttributeOptionLabelInterface::LABEL ]
119
+ )
120
+ );
121
+ }
122
+
86
123
/**
87
124
* @return array
88
125
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -222,4 +259,85 @@ private function getSwatch(int $optionId)
222
259
$ collection ->setPageSize (1 );
223
260
return $ collection ->getFirstItem ();
224
261
}
262
+
263
+ /**
264
+ * Perform Web API call to the system under test
265
+ *
266
+ * @param string $attributeCode
267
+ * @param string $httpMethod
268
+ * @param string $soapMethod
269
+ * @param array $arguments
270
+ * @param null $storeCode
271
+ * @param null $optionId
272
+ * @return array|bool|float|int|string
273
+ */
274
+ private function webApiCallAttributeOptions (
275
+ string $ attributeCode ,
276
+ string $ httpMethod ,
277
+ string $ soapMethod ,
278
+ array $ arguments = [],
279
+ $ optionId = null ,
280
+ $ storeCode = null
281
+ ) {
282
+ $ resourcePath = self ::RESOURCE_PATH . "/ {$ attributeCode }/options " ;
283
+ if ($ optionId ) {
284
+ $ resourcePath .= '/ ' . $ optionId ;
285
+ }
286
+ $ serviceName = $ soapMethod === 'update ' ? self ::SERVICE_NAME_UPDATE : self ::SERVICE_NAME ;
287
+ $ serviceInfo = [
288
+ 'rest ' => [
289
+ 'resourcePath ' => $ resourcePath ,
290
+ 'httpMethod ' => $ httpMethod ,
291
+ ],
292
+ 'soap ' => [
293
+ 'service ' => $ serviceName ,
294
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
295
+ 'operation ' => $ serviceName . $ soapMethod ,
296
+ ],
297
+ ];
298
+
299
+ return $ this ->_webApiCall ($ serviceInfo , $ arguments , null , $ storeCode );
300
+ }
301
+
302
+ /**
303
+ * @param string $testAttributeCode
304
+ * @param string|null $storeCode
305
+ * @return array|bool|float|int|string
306
+ */
307
+ private function getAttributeOptions (string $ testAttributeCode , ?string $ storeCode = null )
308
+ {
309
+ return $ this ->webApiCallAttributeOptions (
310
+ $ testAttributeCode ,
311
+ Request::HTTP_METHOD_GET ,
312
+ 'getItems ' ,
313
+ ['attributeCode ' => $ testAttributeCode ],
314
+ null ,
315
+ $ storeCode
316
+ );
317
+ }
318
+
319
+ /**
320
+ * @param string $attributeCode
321
+ * @param string $optionLabel
322
+ * @param string|null $storeCode
323
+ * @return array|null
324
+ */
325
+ private function getAttributeOption (
326
+ string $ attributeCode ,
327
+ string $ optionLabel ,
328
+ ?string $ storeCode = null
329
+ ): ?array
330
+ {
331
+ $ attributeOptions = $ this ->getAttributeOptions ($ attributeCode , $ storeCode );
332
+ $ option = null ;
333
+ /** @var array $attributeOption */
334
+ foreach ($ attributeOptions as $ attributeOption ) {
335
+ if ($ attributeOption ['label ' ] === $ optionLabel ) {
336
+ $ option = $ attributeOption ;
337
+ break ;
338
+ }
339
+ }
340
+
341
+ return $ option ;
342
+ }
225
343
}
0 commit comments