Skip to content

Commit e779423

Browse files
committed
magento#24519: Web-Api test added.
1 parent 1da4f2a commit e779423

File tree

1 file changed

+129
-4
lines changed

1 file changed

+129
-4
lines changed

dev/tests/api-functional/testsuite/Magento/Customer/Api/AddressMetadataTest.php

Lines changed: 129 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
namespace Magento\Customer\Api;
88

9+
use Magento\Config\Model\ResourceModel\Config;
910
use Magento\Customer\Api\Data\AddressInterface as Address;
1011
use Magento\Customer\Model\Data\AttributeMetadata;
12+
use Magento\Framework\App\Config\ReinitableConfigInterface;
13+
use Magento\TestFramework\ObjectManager;
1114
use Magento\TestFramework\TestCase\WebapiAbstract;
1215

1316
/**
@@ -19,15 +22,40 @@ class AddressMetadataTest extends WebapiAbstract
1922
const SERVICE_VERSION = "V1";
2023
const RESOURCE_PATH = "/V1/attributeMetadata/customerAddress";
2124

25+
/**
26+
* @var Config $config
27+
*/
28+
private $resourceConfig;
29+
30+
/**
31+
* @var ReinitableConfigInterface
32+
*/
33+
private $reinitConfig;
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
protected function setUp()
39+
{
40+
parent::setUp();
41+
42+
$objectManager = ObjectManager::getInstance();
43+
$this->resourceConfig = $objectManager->get(Config::class);
44+
$this->reinitConfig = $objectManager->get(ReinitableConfigInterface::class);
45+
}
46+
2247
/**
2348
* Test retrieval of attribute metadata for the address entity type.
2449
*
2550
* @param string $attributeCode The attribute code of the requested metadata.
2651
* @param array $expectedMetadata Expected entity metadata for the attribute code.
2752
* @dataProvider getAttributeMetadataDataProvider
53+
* @magentoDbIsolation disabled
2854
*/
29-
public function testGetAttributeMetadata($attributeCode, $expectedMetadata)
55+
public function testGetAttributeMetadata($attributeCode, $configOptions, $expectedMetadata)
3056
{
57+
$this->initConfig($configOptions);
58+
3159
$serviceInfo = [
3260
'rest' => [
3361
'resourcePath' => self::RESOURCE_PATH . "/attribute/$attributeCode",
@@ -54,12 +82,14 @@ public function testGetAttributeMetadata($attributeCode, $expectedMetadata)
5482
* Data provider for testGetAttributeMetadata.
5583
*
5684
* @return array
85+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
5786
*/
5887
public function getAttributeMetadataDataProvider()
5988
{
6089
return [
6190
Address::POSTCODE => [
6291
Address::POSTCODE,
92+
[],
6393
[
6494
AttributeMetadata::FRONTEND_INPUT => 'text',
6595
AttributeMetadata::INPUT_FILTER => '',
@@ -83,7 +113,85 @@ public function getAttributeMetadataDataProvider()
83113
AttributeMetadata::IS_SEARCHABLE_IN_GRID => true,
84114
AttributeMetadata::ATTRIBUTE_CODE => 'postcode',
85115
],
86-
]
116+
],
117+
'prefix' => [
118+
'prefix',
119+
[
120+
['path' => 'customer/address/prefix_show', 'value' => 'opt'],
121+
['path' => 'customer/address/prefix_options', 'value' => 'prefA;prefB']
122+
],
123+
[
124+
AttributeMetadata::FRONTEND_INPUT => 'text',
125+
AttributeMetadata::INPUT_FILTER => '',
126+
AttributeMetadata::STORE_LABEL => 'Name Prefix',
127+
AttributeMetadata::MULTILINE_COUNT => 0,
128+
AttributeMetadata::VALIDATION_RULES => [],
129+
AttributeMetadata::VISIBLE => false,
130+
AttributeMetadata::REQUIRED => false,
131+
AttributeMetadata::DATA_MODEL => '',
132+
AttributeMetadata::OPTIONS => [
133+
[
134+
'label' => 'prefA',
135+
'value' => 'prefA',
136+
],
137+
[
138+
'label' => 'prefB',
139+
'value' => 'prefB',
140+
],
141+
],
142+
AttributeMetadata::FRONTEND_CLASS => '',
143+
AttributeMetadata::USER_DEFINED => false,
144+
AttributeMetadata::SORT_ORDER => 10,
145+
AttributeMetadata::FRONTEND_LABEL => 'Name Prefix',
146+
AttributeMetadata::NOTE => '',
147+
AttributeMetadata::SYSTEM => false,
148+
AttributeMetadata::BACKEND_TYPE => 'static',
149+
AttributeMetadata::IS_USED_IN_GRID => false,
150+
AttributeMetadata::IS_VISIBLE_IN_GRID => false,
151+
AttributeMetadata::IS_FILTERABLE_IN_GRID => false,
152+
AttributeMetadata::IS_SEARCHABLE_IN_GRID => false,
153+
AttributeMetadata::ATTRIBUTE_CODE => 'prefix',
154+
],
155+
],
156+
'suffix' => [
157+
'suffix',
158+
[
159+
['path' => 'customer/address/suffix_show', 'value' => 'opt'],
160+
['path' => 'customer/address/suffix_options', 'value' => 'suffA;suffB']
161+
],
162+
[
163+
AttributeMetadata::FRONTEND_INPUT => 'text',
164+
AttributeMetadata::INPUT_FILTER => '',
165+
AttributeMetadata::STORE_LABEL => 'Name Suffix',
166+
AttributeMetadata::MULTILINE_COUNT => 0,
167+
AttributeMetadata::VALIDATION_RULES => [],
168+
AttributeMetadata::VISIBLE => false,
169+
AttributeMetadata::REQUIRED => false,
170+
AttributeMetadata::DATA_MODEL => '',
171+
AttributeMetadata::OPTIONS => [
172+
[
173+
'label' => 'suffA',
174+
'value' => 'suffA',
175+
],
176+
[
177+
'label' => 'suffB',
178+
'value' => 'suffB',
179+
],
180+
],
181+
AttributeMetadata::FRONTEND_CLASS => '',
182+
AttributeMetadata::USER_DEFINED => false,
183+
AttributeMetadata::SORT_ORDER => 50,
184+
AttributeMetadata::FRONTEND_LABEL => 'Name Suffix',
185+
AttributeMetadata::NOTE => '',
186+
AttributeMetadata::SYSTEM => false,
187+
AttributeMetadata::BACKEND_TYPE => 'static',
188+
AttributeMetadata::IS_USED_IN_GRID => false,
189+
AttributeMetadata::IS_VISIBLE_IN_GRID => false,
190+
AttributeMetadata::IS_FILTERABLE_IN_GRID => false,
191+
AttributeMetadata::IS_SEARCHABLE_IN_GRID => false,
192+
AttributeMetadata::ATTRIBUTE_CODE => 'suffix',
193+
],
194+
],
87195
];
88196
}
89197

@@ -106,7 +214,7 @@ public function testGetAllAttributesMetadata()
106214

107215
$attributeMetadata = $this->_webApiCall($serviceInfo);
108216
$this->assertCount(19, $attributeMetadata);
109-
$postcode = $this->getAttributeMetadataDataProvider()[Address::POSTCODE][1];
217+
$postcode = $this->getAttributeMetadataDataProvider()[Address::POSTCODE][2];
110218
$validationResult = $this->checkMultipleAttributesValidationRules($postcode, $attributeMetadata);
111219
list($postcode, $attributeMetadata) = $validationResult;
112220
$this->assertContains($postcode, $attributeMetadata);
@@ -187,7 +295,7 @@ public function getAttributesDataProvider()
187295
return [
188296
[
189297
'customer_address_edit',
190-
$attributeMetadata[Address::POSTCODE][1],
298+
$attributeMetadata[Address::POSTCODE][2],
191299
]
192300
];
193301
}
@@ -200,6 +308,7 @@ public function getAttributesDataProvider()
200308
* @param array $actualResult
201309
* @return array
202310
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
311+
* phpcs:disable Generic.Metrics.NestingLevel
203312
*/
204313
public function checkValidationRules($expectedResult, $actualResult)
205314
{
@@ -235,6 +344,7 @@ public function checkValidationRules($expectedResult, $actualResult)
235344
}
236345
return [$expectedResult, $actualResult];
237346
}
347+
//phpcs:enable
238348

239349
/**
240350
* Check specific attribute validation rules in set of multiple attributes
@@ -277,4 +387,19 @@ public static function tearDownAfterClass()
277387
$attribute->delete();
278388
}
279389
}
390+
391+
/**
392+
* Set core config data.
393+
*
394+
* @param $configOptions
395+
*/
396+
private function initConfig(array $configOptions): void
397+
{
398+
if ($configOptions) {
399+
foreach ($configOptions as $option) {
400+
$this->resourceConfig->saveConfig($option['path'], $option['value']);
401+
}
402+
}
403+
$this->reinitConfig->reinit();
404+
}
280405
}

0 commit comments

Comments
 (0)