Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
AddressMetadataTest Class Reference
Inheritance diagram for AddressMetadataTest:
WebapiAbstract

Public Member Functions

 testGetAttributeMetadata ($attributeCode, $expectedMetadata)
 
 getAttributeMetadataDataProvider ()
 
 testGetAllAttributesMetadata ()
 
 testGetCustomAttributesMetadata ()
 
 testGetAttributes ($formCode, $expectedMetadata)
 
 getAttributesDataProvider ()
 
 checkValidationRules ($expectedResult, $actualResult)
 
 checkMultipleAttributesValidationRules ($expectedResult, $actualResultSet)
 
- Public Member Functions inherited from WebapiAbstract
 addModelToDelete ($model, $secure=false)
 
 processRestExceptionResult (\Exception $e)
 

Data Fields

const SERVICE_NAME = "customerAddressMetadataV1"
 
const SERVICE_VERSION = "V1"
 
const RESOURCE_PATH = "/V1/attributeMetadata/customerAddress"
 
- Data Fields inherited from WebapiAbstract
const AUTO_TEAR_DOWN_DISABLED = 0
 
const AUTO_TEAR_DOWN_AFTER_METHOD = 1
 
const AUTO_TEAR_DOWN_AFTER_CLASS = 2
 
const ADAPTER_SOAP = 'soap'
 
const ADAPTER_REST = 'rest'
 

Additional Inherited Members

- Static Public Member Functions inherited from WebapiAbstract
static setUpBeforeClass ()
 
static tearDownAfterClass ()
 
static setFixture ($key, $fixture, $tearDown=self::AUTO_TEAR_DOWN_AFTER_METHOD)
 
static getFixture ($key)
 
static callModelDelete ($model, $secure=false)
 
static deleteFixture ($key, $secure=false)
 
- Protected Member Functions inherited from WebapiAbstract
 tearDown ()
 
 _webApiCall ( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
 
 _markTestAsSoapOnly ($message=null)
 
 _markTestAsRestOnly ($message=null)
 
 _getWebApiAdapter ($webApiAdapterCode)
 
 _assertMessagesEqual ($expectedMessages, $receivedMessages)
 
 _cleanAppConfigCache ()
 
 _restoreAppConfig ()
 
 checkSoapFault ( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)
 
 _checkFaultParams ($expectedErrorParams, $errorDetails)
 
 _checkWrappedErrors ($expectedWrappedErrors, $errorDetails)
 
- Static Protected Member Functions inherited from WebapiAbstract
static _setFixtureNamespace ()
 
static _unsetFixtureNamespace ()
 
static _getFixtureNamespace ()
 
static _deleteFixtures ($fixtures)
 
- Protected Attributes inherited from WebapiAbstract
 $_appCache
 
 $_modelsToDelete = []
 
 $_origConfigValues = []
 
 $_webApiAdapters
 
 $_webApiAdaptersMap
 
- Static Protected Attributes inherited from WebapiAbstract
static $_fixturesNamespace
 
static $_fixtures = []
 
static $_methodLevelFixtures = []
 
static $_classLevelFixtures = []
 

Detailed Description

Class AddressMetadataTest

Definition at line 16 of file AddressMetadataTest.php.

Member Function Documentation

◆ checkMultipleAttributesValidationRules()

checkMultipleAttributesValidationRules (   $expectedResult,
  $actualResultSet 
)

Check specific attribute validation rules in set of multiple attributes

Parameters
array$expectedResultSet of expected attribute metadata
array$actualResultSetSet of actual attribute metadata
Returns
array

Definition at line 246 of file AddressMetadataTest.php.

247  {
248  if (is_array($expectedResult) && is_array($actualResultSet)) {
249  if (isset($expectedResult[AttributeMetadata::ATTRIBUTE_CODE])) {
250  foreach ($actualResultSet as $actualAttributeKey => $actualAttribute) {
251  if (isset($actualAttribute[AttributeMetadata::ATTRIBUTE_CODE])
252  && $expectedResult[AttributeMetadata::ATTRIBUTE_CODE]
253  == $actualAttribute[AttributeMetadata::ATTRIBUTE_CODE]
254  ) {
255  $this->checkValidationRules($expectedResult, $actualAttribute);
256  unset($actualResultSet[$actualAttributeKey][AttributeMetadata::VALIDATION_RULES]);
257  }
258  }
259  unset($expectedResult[AttributeMetadata::VALIDATION_RULES]);
260  }
261  }
262  return [$expectedResult, $actualResultSet];
263  }
checkValidationRules($expectedResult, $actualResult)

◆ checkValidationRules()

checkValidationRules (   $expectedResult,
  $actualResult 
)

Checks that expected and actual attribute metadata validation rules are equal and removes the validation rules entry from expected and actual attribute metadata

Parameters
array$expectedResult
array$actualResult
Returns
array @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 204 of file AddressMetadataTest.php.

205  {
206  $expectedRules = [];
207  $actualRules = [];
208 
209  if (isset($expectedResult[AttributeMetadata::VALIDATION_RULES])) {
210  $expectedRules = $expectedResult[AttributeMetadata::VALIDATION_RULES];
211  unset($expectedResult[AttributeMetadata::VALIDATION_RULES]);
212  }
213  if (isset($actualResult[AttributeMetadata::VALIDATION_RULES])) {
214  $actualRules = $actualResult[AttributeMetadata::VALIDATION_RULES];
215  unset($actualResult[AttributeMetadata::VALIDATION_RULES]);
216  }
217 
218  if (is_array($expectedRules) && is_array($actualRules)) {
219  foreach ($expectedRules as $expectedRule) {
220  if (isset($expectedRule['name']) && isset($expectedRule['value'])) {
221  $found = false;
222  foreach ($actualRules as $actualRule) {
223  if (isset($actualRule['name']) && isset($actualRule['value'])) {
224  if ($expectedRule['name'] == $actualRule['name']
225  && $expectedRule['value'] == $actualRule['value']
226  ) {
227  $found = true;
228  break;
229  }
230  }
231  }
232  $this->assertTrue($found);
233  }
234  }
235  }
236  return [$expectedResult, $actualResult];
237  }

◆ getAttributeMetadataDataProvider()

getAttributeMetadataDataProvider ( )

Data provider for testGetAttributeMetadata.

Returns
array

Definition at line 58 of file AddressMetadataTest.php.

59  {
60  return [
61  Address::POSTCODE => [
62  Address::POSTCODE,
63  [
66  AttributeMetadata::STORE_LABEL => 'Zip/Postal Code',
71  AttributeMetadata::DATA_MODEL => \Magento\Customer\Model\Attribute\Data\Postcode::class,
76  AttributeMetadata::FRONTEND_LABEL => 'Zip/Postal Code',
85  ],
86  ]
87  ];
88  }

◆ getAttributesDataProvider()

getAttributesDataProvider ( )

Data provider for testGetAttributes.

Returns
array

Definition at line 184 of file AddressMetadataTest.php.

185  {
186  $attributeMetadata = $this->getAttributeMetadataDataProvider();
187  return [
188  [
189  'customer_address_edit',
190  $attributeMetadata[Address::POSTCODE][1],
191  ]
192  ];
193  }

◆ testGetAllAttributesMetadata()

testGetAllAttributesMetadata ( )

Test retrieval of all address attribute metadata.

Definition at line 93 of file AddressMetadataTest.php.

94  {
95  $serviceInfo = [
96  'rest' => [
97  'resourcePath' => self::RESOURCE_PATH,
99  ],
100  'soap' => [
101  'service' => self::SERVICE_NAME,
102  'serviceVersion' => self::SERVICE_VERSION,
103  'operation' => self::SERVICE_NAME . 'GetAllAttributesMetadata',
104  ],
105  ];
106 
107  $attributeMetadata = $this->_webApiCall($serviceInfo);
108  $this->assertCount(19, $attributeMetadata);
109  $postcode = $this->getAttributeMetadataDataProvider()[Address::POSTCODE][1];
110  $validationResult = $this->checkMultipleAttributesValidationRules($postcode, $attributeMetadata);
111  list($postcode, $attributeMetadata) = $validationResult;
112  $this->assertContains($postcode, $attributeMetadata);
113  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
checkMultipleAttributesValidationRules($expectedResult, $actualResultSet)

◆ testGetAttributeMetadata()

testGetAttributeMetadata (   $attributeCode,
  $expectedMetadata 
)

Test retrieval of attribute metadata for the address entity type.

Parameters
string$attributeCodeThe attribute code of the requested metadata.
array$expectedMetadataExpected entity metadata for the attribute code. @dataProvider getAttributeMetadataDataProvider

Definition at line 29 of file AddressMetadataTest.php.

30  {
31  $serviceInfo = [
32  'rest' => [
33  'resourcePath' => self::RESOURCE_PATH . "/attribute/$attributeCode",
35  ],
36  'soap' => [
37  'service' => self::SERVICE_NAME,
38  'serviceVersion' => self::SERVICE_VERSION,
39  'operation' => self::SERVICE_NAME . 'GetAttributeMetadata',
40  ],
41  ];
42 
43  $requestData = [
44  'attributeCode' => $attributeCode,
45  ];
46 
47  $attributeMetadata = $this->_webapiCall($serviceInfo, $requestData);
48  $validationResult = $this->checkValidationRules($expectedMetadata, $attributeMetadata);
49  list($expectedMetadata, $attributeMetadata) = $validationResult;
50  $this->assertEquals($expectedMetadata, $attributeMetadata);
51  }
$attributeCode
Definition: extend.phtml:12
checkValidationRules($expectedResult, $actualResult)

◆ testGetAttributes()

testGetAttributes (   $formCode,
  $expectedMetadata 
)

Test retrieval of attributes

Parameters
string$formCodeForm code
array$expectedMetadataThe expected attribute metadata @dataProvider getAttributesDataProvider

Definition at line 148 of file AddressMetadataTest.php.

149  {
150  $serviceInfo = [
151  'rest' => [
152  'resourcePath' => self::RESOURCE_PATH . "/form/$formCode",
154  ],
155  'soap' => [
156  'service' => self::SERVICE_NAME,
157  'serviceVersion' => self::SERVICE_VERSION,
158  'operation' => self::SERVICE_NAME . 'GetAttributes',
159  ],
160  ];
161 
162  $requestData = [
163  'formCode' => $formCode,
164  ];
165 
166  $attributeMetadataList = $this->_webApiCall($serviceInfo, $requestData);
167  foreach ($attributeMetadataList as $attributeMetadata) {
168  if (isset($attributeMetadata['attribute_code'])
169  && $attributeMetadata['attribute_code'] == $expectedMetadata['attribute_code']
170  ) {
171  $validationResult = $this->checkValidationRules($expectedMetadata, $attributeMetadata);
172  list($expectedMetadata, $attributeMetadata) = $validationResult;
173  $this->assertEquals($expectedMetadata, $attributeMetadata);
174  break;
175  }
176  }
177  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
checkValidationRules($expectedResult, $actualResult)

◆ testGetCustomAttributesMetadata()

testGetCustomAttributesMetadata ( )

Test retrieval of custom address attribute metadata.

@magentoApiDataFixture Magento/Customer/_files/attribute_user_defined_address_custom_attribute.php

Definition at line 120 of file AddressMetadataTest.php.

121  {
122  $customAttributeCode = 'custom_attribute1';
123  $serviceInfo = [
124  'rest' => [
125  'resourcePath' => self::RESOURCE_PATH . '/custom',
127  ],
128  'soap' => [
129  'service' => self::SERVICE_NAME,
130  'serviceVersion' => self::SERVICE_VERSION,
131  'operation' => self::SERVICE_NAME . 'GetCustomAttributesMetadata',
132  ],
133  ];
134 
135  $requestData = ['attribute_code' => $customAttributeCode];
136  $attributeMetadata = $this->_webApiCall($serviceInfo, $requestData);
137  $this->assertCount(2, $attributeMetadata);
138  $this->assertEquals($customAttributeCode, $attributeMetadata[0]['attribute_code']);
139  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

Field Documentation

◆ RESOURCE_PATH

const RESOURCE_PATH = "/V1/attributeMetadata/customerAddress"

Definition at line 20 of file AddressMetadataTest.php.

◆ SERVICE_NAME

const SERVICE_NAME = "customerAddressMetadataV1"

Definition at line 18 of file AddressMetadataTest.php.

◆ SERVICE_VERSION

const SERVICE_VERSION = "V1"

Definition at line 19 of file AddressMetadataTest.php.


The documentation for this class was generated from the following file: