Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductSwatchAttributeOptionManagementInterfaceTest.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Catalog\Api;
7 
11 
13 {
14  const SERVICE_NAME = 'catalogProductAttributeOptionManagementV1';
15  const SERVICE_VERSION = 'V1';
16  const RESOURCE_PATH = '/V1/products/attributes';
17 
22  public function testAdd($optionData)
23  {
24  $testAttributeCode = 'color_swatch';
25  $serviceInfo = [
26  'rest' => [
27  'resourcePath' => self::RESOURCE_PATH . '/' . $testAttributeCode . '/options',
29  ],
30  'soap' => [
31  'service' => self::SERVICE_NAME,
32  'serviceVersion' => self::SERVICE_VERSION,
33  'operation' => self::SERVICE_NAME . 'add',
34  ],
35  ];
36 
37  $response = $this->_webApiCall(
38  $serviceInfo,
39  [
40  'attributeCode' => $testAttributeCode,
41  'option' => $optionData,
42  ]
43  );
44 
45  $this->assertNotNull($response);
46  $updatedData = $this->getAttributeOptions($testAttributeCode);
47  $lastOption = array_pop($updatedData);
48  $this->assertEquals(
50  $lastOption['label']
51  );
52  }
53 
57  public function addDataProvider()
58  {
59  $optionPayload = [
60  AttributeOptionInterface::LABEL => 'new color',
64  [
67  ],
68  ],
70  ];
71 
72  return [
73  'option_without_value_node' => [
74  $optionPayload
75  ],
76  'option_with_value_node_that_starts_with_text' => [
77  array_merge($optionPayload, [AttributeOptionInterface::VALUE => 'some_text'])
78  ],
79  'option_with_value_node_that_starts_with_a_number' => [
80  array_merge($optionPayload, [AttributeOptionInterface::VALUE => '123_some_text'])
81  ],
82 
83  ];
84  }
85 
90  private function getAttributeOptions($testAttributeCode)
91  {
92  $serviceInfo = [
93  'rest' => [
94  'resourcePath' => self::RESOURCE_PATH . '/' . $testAttributeCode . '/options',
96  ],
97  'soap' => [
98  'service' => self::SERVICE_NAME,
99  'serviceVersion' => self::SERVICE_VERSION,
100  'operation' => self::SERVICE_NAME . 'getItems',
101  ],
102  ];
103  return $this->_webApiCall($serviceInfo, ['attributeCode' => $testAttributeCode]);
104  }
105 }
$response
Definition: 404.php:11
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$optionData