2525class ProductAttributeOptionManagementInterfaceTest extends WebapiAbstract
2626{
2727 private const ATTRIBUTE_CODE = 'select_attribute ' ;
28+ private const SERVICE_NAME_UPDATE = 'catalogProductAttributeOptionUpdateV1 ' ;
2829 private const SERVICE_NAME = 'catalogProductAttributeOptionManagementV1 ' ;
2930 private const SERVICE_VERSION = 'V1 ' ;
3031 private const RESOURCE_PATH = '/V1/products/attributes ' ;
@@ -47,7 +48,8 @@ public function testAdd(
4748 int $ expectedSwatchType ,
4849 string $ expectedLabel ,
4950 string $ expectedValue
50- ) {
51+ )
52+ {
5153 $ objectManager = Bootstrap::getObjectManager ();
5254 /** @var $attributeRepository AttributeRepository */
5355 $ attributeRepository = $ objectManager ->get (AttributeRepository::class);
@@ -74,7 +76,7 @@ public function testAdd(
7476 );
7577
7678 $ this ->assertNotNull ($ response );
77- $ optionId = (int ) ltrim ($ response , 'id_ ' );
79+ $ optionId = (int )ltrim ($ response , 'id_ ' );
7880 $ swatch = $ this ->getSwatch ($ optionId );
7981 $ this ->assertEquals ($ expectedValue , $ swatch ->getValue ());
8082 $ this ->assertEquals ($ expectedSwatchType , $ swatch ->getType ());
@@ -83,6 +85,41 @@ public function testAdd(
8385 $ this ->assertEquals ($ expectedLabel , $ options [2 ]->getLabel ());
8486 }
8587
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+
86123 /**
87124 * @return array
88125 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -222,4 +259,85 @@ private function getSwatch(int $optionId)
222259 $ collection ->setPageSize (1 );
223260 return $ collection ->getFirstItem ();
224261 }
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+ }
225343}
0 commit comments