Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
magento2-base
dev
tests
api-functional
testsuite
Magento
Catalog
Api
ProductSwatchAttributeOptionManagementInterfaceTest.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Catalog\Api
;
7
8
use
Magento\Eav\Api\Data\AttributeOptionInterface
;
9
use
Magento\Eav\Api\Data\AttributeOptionLabelInterface
;
10
use
Magento\TestFramework\TestCase\WebapiAbstract
;
11
12
class
ProductSwatchAttributeOptionManagementInterfaceTest
extends
WebapiAbstract
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'
,
28
'httpMethod'
=>
\Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST
,
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(
49
$optionData
[
AttributeOptionInterface::STORE_LABELS
][0][
AttributeOptionLabelInterface::LABEL
],
50
$lastOption[
'label'
]
51
);
52
}
53
57
public
function
addDataProvider
()
58
{
59
$optionPayload = [
60
AttributeOptionInterface::LABEL
=>
'new color'
,
61
AttributeOptionInterface::SORT_ORDER
=> 100,
62
AttributeOptionInterface::IS_DEFAULT
=>
true
,
63
AttributeOptionInterface::STORE_LABELS
=> [
64
[
65
AttributeOptionLabelInterface::LABEL
=>
'DE label'
,
66
AttributeOptionLabelInterface::STORE_ID
=> 1,
67
],
68
],
69
AttributeOptionInterface::VALUE
=>
''
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'
,
95
'httpMethod'
=>
\Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET
,
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
}
Magento\Catalog\Api
Definition:
AttributeSetManagementTest.php:7
Magento\Eav\Api\Data\AttributeOptionLabelInterface\STORE_ID
const STORE_ID
Definition:
AttributeOptionLabelInterface.php:18
$response
$response
Definition:
404.php:11
Magento\Catalog\Api\ProductSwatchAttributeOptionManagementInterfaceTest
Definition:
ProductSwatchAttributeOptionManagementInterfaceTest.php:12
Magento\Eav\Api\Data\AttributeOptionLabelInterface
Definition:
AttributeOptionLabelInterface.php:14
Magento\TestFramework\TestCase\WebapiAbstract\_webApiCall
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
Definition:
WebapiAbstract.php:165
Magento\Eav\Api\Data\AttributeOptionInterface\IS_DEFAULT
const IS_DEFAULT
Definition:
AttributeOptionInterface.php:28
$optionData
$optionData
Definition:
select_attribute.php:21
Magento\Catalog\Api\ProductSwatchAttributeOptionManagementInterfaceTest\SERVICE_NAME
const SERVICE_NAME
Definition:
ProductSwatchAttributeOptionManagementInterfaceTest.php:14
Magento\Eav\Api\Data\AttributeOptionInterface\LABEL
const LABEL
Definition:
AttributeOptionInterface.php:20
Magento\Eav\Api\Data\AttributeOptionLabelInterface\LABEL
const LABEL
Definition:
AttributeOptionLabelInterface.php:16
Magento\Eav\Api\Data\AttributeOptionInterface\SORT_ORDER
const SORT_ORDER
Definition:
AttributeOptionInterface.php:24
Magento\Framework\Webapi\Rest\Request\HTTP_METHOD_GET
const HTTP_METHOD_GET
Definition:
Request.php:19
Magento\Catalog\Api\ProductSwatchAttributeOptionManagementInterfaceTest\testAdd
testAdd($optionData)
Definition:
ProductSwatchAttributeOptionManagementInterfaceTest.php:22
Magento\Eav\Api\Data\AttributeOptionInterface
Definition:
AttributeOptionInterface.php:15
Magento\Catalog\Api\ProductSwatchAttributeOptionManagementInterfaceTest\SERVICE_VERSION
const SERVICE_VERSION
Definition:
ProductSwatchAttributeOptionManagementInterfaceTest.php:15
Magento\Eav\Api\Data\AttributeOptionInterface\STORE_LABELS
const STORE_LABELS
Definition:
AttributeOptionInterface.php:26
Magento\Framework\Webapi\Rest\Request\HTTP_METHOD_POST
const HTTP_METHOD_POST
Definition:
Request.php:22
Magento\TestFramework\TestCase\WebapiAbstract
Definition:
WebapiAbstract.php:19
Magento\Eav\Api\Data\AttributeOptionInterface\VALUE
const VALUE
Definition:
AttributeOptionInterface.php:22
Magento\Catalog\Api\ProductSwatchAttributeOptionManagementInterfaceTest\addDataProvider
addDataProvider()
Definition:
ProductSwatchAttributeOptionManagementInterfaceTest.php:57
Magento\Catalog\Api\ProductSwatchAttributeOptionManagementInterfaceTest\RESOURCE_PATH
const RESOURCE_PATH
Definition:
ProductSwatchAttributeOptionManagementInterfaceTest.php:16