Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
CustomerMetadataTest Class Reference
Inheritance diagram for CustomerMetadataTest:
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 = "customerCustomerMetadataV1"
 
const SERVICE_VERSION = "V1"
 
const RESOURCE_PATH = "/V1/attributeMetadata/customer"
 
- 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 CustomerMetadataTest

Definition at line 16 of file CustomerMetadataTest.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 315 of file CustomerMetadataTest.php.

316  {
317  if (is_array($expectedResult) && is_array($actualResultSet)) {
318  if (isset($expectedResult[AttributeMetadata::ATTRIBUTE_CODE])) {
319  foreach ($actualResultSet as $actualAttributeKey => $actualAttribute) {
320  if (isset($actualAttribute[AttributeMetadata::ATTRIBUTE_CODE])
321  && $expectedResult[AttributeMetadata::ATTRIBUTE_CODE]
322  == $actualAttribute[AttributeMetadata::ATTRIBUTE_CODE]
323  ) {
324  $this->checkValidationRules($expectedResult, $actualAttribute);
325  unset($actualResultSet[$actualAttributeKey][AttributeMetadata::VALIDATION_RULES]);
326  }
327  }
328  unset($expectedResult[AttributeMetadata::VALIDATION_RULES]);
329  }
330  }
331  return [$expectedResult, $actualResultSet];
332  }
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 273 of file CustomerMetadataTest.php.

274  {
275  $expectedRules = [];
276  $actualRules = [];
277 
278  if (isset($expectedResult[AttributeMetadata::VALIDATION_RULES])) {
279  $expectedRules = $expectedResult[AttributeMetadata::VALIDATION_RULES];
280  unset($expectedResult[AttributeMetadata::VALIDATION_RULES]);
281  }
282  if (isset($actualResult[AttributeMetadata::VALIDATION_RULES])) {
283  $actualRules = $actualResult[AttributeMetadata::VALIDATION_RULES];
284  unset($actualResult[AttributeMetadata::VALIDATION_RULES]);
285  }
286 
287  if (is_array($expectedRules) && is_array($actualRules)) {
288  foreach ($expectedRules as $expectedRule) {
289  if (isset($expectedRule['name']) && isset($expectedRule['value'])) {
290  $found = false;
291  foreach ($actualRules as $actualRule) {
292  if (isset($actualRule['name']) && isset($actualRule['value'])) {
293  if ($expectedRule['name'] == $actualRule['name']
294  && $expectedRule['value'] == $actualRule['value']
295  ) {
296  $found = true;
297  break;
298  }
299  }
300  }
301  $this->assertTrue($found);
302  }
303  }
304  }
305  return [$expectedResult, $actualResult];
306  }

◆ getAttributeMetadataDataProvider()

getAttributeMetadataDataProvider ( )

Data provider for testGetAttributeMetadata.

Returns
array

Definition at line 59 of file CustomerMetadataTest.php.

60  {
61  return [
62  Customer::FIRSTNAME => [
63  Customer::FIRSTNAME,
64  [
67  AttributeMetadata::STORE_LABEL => 'First Name',
70  ['name' => 'min_text_length', 'value' => 1],
71  ['name' => 'max_text_length', 'value' => 255],
72  ],
77  AttributeMetadata::FRONTEND_CLASS => 'required-entry',
80  AttributeMetadata::FRONTEND_LABEL => 'First Name',
88  AttributeMetadata::ATTRIBUTE_CODE => 'firstname',
89 
90  ],
91  ],
92  Customer::GENDER => [
93  Customer::GENDER,
94  [
104  ['label' => ' ', 'value' => ''],
105  ['label' => 'Male', 'value' => '1'],
106  ['label' => 'Female', 'value' => '2'],
107  ['label' => 'Not Specified', 'value' => '3']
108  ],
114  AttributeMetadata::SYSTEM => false,
121  ],
122  ],
123  Customer::WEBSITE_ID => [
124  Customer::WEBSITE_ID,
125  [
128  AttributeMetadata::STORE_LABEL => 'Associate to Website',
135  ['label' => 'Main Website', 'value' => '1'],
136  ],
137  AttributeMetadata::FRONTEND_CLASS => 'required-entry',
140  AttributeMetadata::FRONTEND_LABEL => 'Associate to Website',
148  AttributeMetadata::ATTRIBUTE_CODE => 'website_id',
149  ],
150  ]
151  ];
152  }

◆ getAttributesDataProvider()

getAttributesDataProvider ( )

Data provider for testGetAttributes.

Returns
array

Definition at line 249 of file CustomerMetadataTest.php.

250  {
251  $attributeMetadata = $this->getAttributeMetadataDataProvider();
252  return [
253  [
254  'adminhtml_customer',
255  $attributeMetadata[Customer::FIRSTNAME][1],
256  ],
257  [
258  'adminhtml_customer',
259  $attributeMetadata[Customer::GENDER][1]
260  ]
261  ];
262  }

◆ testGetAllAttributesMetadata()

testGetAllAttributesMetadata ( )

Test retrieval of all customer attribute metadata.

Definition at line 157 of file CustomerMetadataTest.php.

158  {
159  $serviceInfo = [
160  'rest' => [
161  'resourcePath' => self::RESOURCE_PATH,
163  ],
164  'soap' => [
165  'service' => self::SERVICE_NAME,
166  'serviceVersion' => self::SERVICE_VERSION,
167  'operation' => self::SERVICE_NAME . 'GetAllAttributesMetadata',
168  ],
169  ];
170 
171  $attributeMetadata = $this->_webApiCall($serviceInfo);
172 
173  $firstName = $this->getAttributeMetadataDataProvider()[Customer::FIRSTNAME][1];
174  $validationResult = $this->checkMultipleAttributesValidationRules($firstName, $attributeMetadata);
175  list($firstName, $attributeMetadata) = $validationResult;
176  $this->assertContains($firstName, $attributeMetadata);
177 
178  $websiteId = $this->getAttributeMetadataDataProvider()[Customer::WEBSITE_ID][1];
179  $validationResult = $this->checkMultipleAttributesValidationRules($websiteId, $attributeMetadata);
180  list($websiteId, $attributeMetadata) = $validationResult;
181  $this->assertContains($websiteId, $attributeMetadata);
182  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
checkMultipleAttributesValidationRules($expectedResult, $actualResultSet)

◆ testGetAttributeMetadata()

testGetAttributeMetadata (   $attributeCode,
  $expectedMetadata 
)

Test retrieval of attribute metadata for the customer 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 CustomerMetadataTest.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 
49  $validationResult = $this->checkValidationRules($expectedMetadata, $attributeMetadata);
50  list($expectedMetadata, $attributeMetadata) = $validationResult;
51  $this->assertEquals($expectedMetadata, $attributeMetadata);
52  }
$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 214 of file CustomerMetadataTest.php.

215  {
216  $serviceInfo = [
217  'rest' => [
218  'resourcePath' => self::RESOURCE_PATH . "/form/$formCode",
220  ],
221  'soap' => [
222  'service' => self::SERVICE_NAME,
223  'serviceVersion' => self::SERVICE_VERSION,
224  'operation' => self::SERVICE_NAME . 'GetAttributes',
225  ],
226  ];
227 
228  $requestData = [
229  'formCode' => $formCode,
230  ];
231 
232  $attributeMetadataList = $this->_webApiCall($serviceInfo, $requestData);
233  foreach ($attributeMetadataList as $attributeMetadata) {
234  if (isset($attributeMetadata['attribute_code'])
235  && $attributeMetadata['attribute_code'] == $expectedMetadata['attribute_code']) {
236  $validationResult = $this->checkValidationRules($expectedMetadata, $attributeMetadata);
237  list($expectedMetadata, $attributeMetadata) = $validationResult;
238  $this->assertEquals($expectedMetadata, $attributeMetadata);
239  break;
240  }
241  }
242  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
checkValidationRules($expectedResult, $actualResult)

◆ testGetCustomAttributesMetadata()

testGetCustomAttributesMetadata ( )

Test retrieval of custom customer attribute metadata.

Definition at line 187 of file CustomerMetadataTest.php.

188  {
189  $serviceInfo = [
190  'rest' => [
191  'resourcePath' => self::RESOURCE_PATH . '/custom',
193  ],
194  'soap' => [
195  'service' => self::SERVICE_NAME,
196  'serviceVersion' => self::SERVICE_VERSION,
197  'operation' => self::SERVICE_NAME . 'GetCustomAttributesMetadata',
198  ],
199  ];
200 
201  $attributeMetadata = $this->_webApiCall($serviceInfo);
202 
203  // There are no default custom attributes.
204  $this->assertCount(0, $attributeMetadata);
205  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

Field Documentation

◆ RESOURCE_PATH

const RESOURCE_PATH = "/V1/attributeMetadata/customer"

Definition at line 20 of file CustomerMetadataTest.php.

◆ SERVICE_NAME

const SERVICE_NAME = "customerCustomerMetadataV1"

Definition at line 18 of file CustomerMetadataTest.php.

◆ SERVICE_VERSION

const SERVICE_VERSION = "V1"

Definition at line 19 of file CustomerMetadataTest.php.


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