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

Public Member Functions

 testGetCustomAttributesMetadata ()
 
 testGetCustomAttributesMetadataWithCustomAttribute ()
 
 testGetAllAttributesMetadataWithCustomAttribute ()
 
 testGetAddressAttributeMetadata ()
 
 testGetAddressAttributeMetadataNoSuchEntity ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Detailed Description

Definition at line 12 of file AddressMetadataTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

Definition at line 20 of file AddressMetadataTest.php.

21  {
24  $objectManager->configure(
25  [
26  \Magento\Framework\Api\ExtensionAttribute\Config\Reader::class => [
27  'arguments' => [
28  'fileResolver' => ['instance' => \Magento\Customer\Model\FileResolverStub::class],
29  ],
30  ],
31  ]
32  );
33  $this->service = $objectManager->create(\Magento\Customer\Api\AddressMetadataInterface::class);
34  $this->serviceTwo = $objectManager->create(\Magento\Customer\Api\AddressMetadataInterface::class);
35  }
$objectManager
Definition: bootstrap.php:17

◆ tearDown()

tearDown ( )
protected

Definition at line 270 of file AddressMetadataTest.php.

271  {
273 
274  /* @var \Magento\Framework\Config\CacheInterface $cache */
275  $cache = $objectManager->create(\Magento\Framework\Config\CacheInterface::class);
276  $cache->remove('extension_attributes_config');
277  }
$objectManager
Definition: bootstrap.php:17

◆ testGetAddressAttributeMetadata()

testGetAddressAttributeMetadata ( )

Definition at line 139 of file AddressMetadataTest.php.

140  {
141  $vatValidMetadata = $this->service->getAttributeMetadata('vat_is_valid');
142  $this->assertNotNull($vatValidMetadata);
143  $this->assertEquals('vat_is_valid', $vatValidMetadata->getAttributeCode());
144  $this->assertEquals('text', $vatValidMetadata->getFrontendInput());
145  $this->assertEquals('VAT number validity', $vatValidMetadata->getStoreLabel());
146 
147  // Verify the consistency of attribute metadata from two calls of the same service
148  $vatValidMetadata2 = $this->service->getAttributeMetadata('vat_is_valid');
149  $this->assertEquals(
150  $vatValidMetadata,
151  $vatValidMetadata2,
152  'Different attribute metadata returned from the 2nd call of the same service'
153  );
154 
155  // Verify the consistency of attribute metadata from two services
156  $vatValidMetadata3 = $this->serviceTwo->getAttributeMetadata('vat_is_valid');
157  $this->assertEquals('vat_is_valid', $vatValidMetadata3->getAttributeCode());
158  $this->assertEquals(
159  $vatValidMetadata,
160  $vatValidMetadata3,
161  'Different attribute metadata returned from the 2nd service'
162  );
163  }

◆ testGetAddressAttributeMetadataNoSuchEntity()

testGetAddressAttributeMetadataNoSuchEntity ( )

Definition at line 165 of file AddressMetadataTest.php.

166  {
167  try {
168  $this->service->getAttributeMetadata('1');
169  $this->fail('Expected exception not thrown.');
170  } catch (NoSuchEntityException $e) {
171  $this->assertEquals(
172  'No such entity with entityType = customer_address, attributeCode = 1',
173  $e->getMessage()
174  );
175  }
176 
177  // Verify the consistency of getAttributeMetadata() function from the 2nd call of the same service
178  try {
179  $this->service->getAttributeMetadata('1');
180  $this->fail('Expected exception not thrown when called the 2nd time.');
181  } catch (NoSuchEntityException $e) {
182  $this->assertEquals(
183  'No such entity with entityType = customer_address, attributeCode = 1',
184  $e->getMessage()
185  );
186  }
187 
188  // Verify the consistency of getAttributeMetadata() function from the 2nd service
189  try {
190  $this->serviceTwo->getAttributeMetadata('1');
191  $this->fail('Expected exception not thrown when called with the 2nd service.');
192  } catch (NoSuchEntityException $e) {
193  $this->assertEquals(
194  'No such entity with entityType = customer_address, attributeCode = 1',
195  $e->getMessage()
196  );
197  }
198  }

◆ testGetAllAttributesMetadataWithCustomAttribute()

testGetAllAttributesMetadataWithCustomAttribute ( )

@magentoDataFixture Magento/Customer/_files/attribute_user_defined_address_custom_attribute.php

Definition at line 118 of file AddressMetadataTest.php.

119  {
120  $allAttributesMetadata = $this->service->getAllAttributesMetadata();
121 
122  // Verify the consistency of getAllAttributesMetadata() function from the 2nd call of the same service
123  $allAttributesMetadata2 = $this->service->getAllAttributesMetadata();
124  $this->assertEquals(
125  $allAttributesMetadata,
126  $allAttributesMetadata2,
127  'Different attribute metadata returned from the 2nd call of the same service'
128  );
129 
130  // Verify the consistency of getAllAttributesMetadata() function from the 2nd service
131  $allAttributesMetadata3 = $this->serviceTwo->getAllAttributesMetadata();
132  $this->assertEquals(
133  $allAttributesMetadata,
134  $allAttributesMetadata3,
135  'Different attribute metadata returned from the 2nd service'
136  );
137  }

◆ testGetCustomAttributesMetadata()

testGetCustomAttributesMetadata ( )

Definition at line 37 of file AddressMetadataTest.php.

38  {
39  $customAttributesMetadata = $this->service->getCustomAttributesMetadata();
40  $this->assertCount(0, $customAttributesMetadata, "Invalid number of attributes returned.");
41 
42  // Verify the consistency of getCustomAttributeMetadata() function from the 2nd call of the same service
43  $customAttributesMetadata2 = $this->service->getCustomAttributesMetadata();
44  $this->assertCount(0, $customAttributesMetadata2, "Invalid number of attributes returned.");
45 
46  // Verify the consistency of getCustomAttributesMetadata() function from the 2nd service
47  $customAttributesMetadata3 = $this->serviceTwo->getCustomAttributesMetadata();
48  $this->assertCount(0, $customAttributesMetadata3, "Invalid number of attributes returned.");
49  }

◆ testGetCustomAttributesMetadataWithCustomAttribute()

testGetCustomAttributesMetadataWithCustomAttribute ( )

@magentoDataFixture Magento/Customer/_files/attribute_user_defined_address_custom_attribute.php

Definition at line 54 of file AddressMetadataTest.php.

55  {
56  $customAttributesMetadata = $this->service->getCustomAttributesMetadata();
57  // Verify the consistency of getCustomAttributeMetadata() function from the 2nd call of the same service
58  $customAttributesMetadata1 = $this->service->getCustomAttributesMetadata();
59  $this->assertEquals(
60  $customAttributesMetadata,
61  $customAttributesMetadata1,
62  'Different custom attribute metadata returned from the 2nd call of the same service'
63  );
64  // Verify the consistency of getCustomAttributesMetadata() function from the 2nd service
65  $customAttributesMetadata2 = $this->serviceTwo->getCustomAttributesMetadata();
66  $this->assertEquals(
67  $customAttributesMetadata,
68  $customAttributesMetadata2,
69  'Different custom attribute metadata returned from the 2nd service'
70  );
71 
72  $customAttributeCodeOne = 'custom_attribute1';
73  $customAttributeFound = false;
74  $customAttributeCodeTwo = 'custom_attribute2';
75  $customAttributesFound = false;
76  foreach ($customAttributesMetadata as $attribute) {
77  if ($attribute->getAttributeCode() == $customAttributeCodeOne) {
78  $customAttributeFound = true;
79  }
80  if ($attribute->getAttributeCode() == $customAttributeCodeTwo) {
81  $customAttributesFound = true;
82  }
83  }
84  if (!$customAttributeFound) {
85  $this->fail("Custom attribute declared in the config not found.");
86  }
87  if (!$customAttributesFound) {
88  $this->fail("Custom attributes declared in the config not found.");
89  }
90  $this->assertCount(2, $customAttributesMetadata, "Invalid number of attributes returned.");
91 
92  // Verify the consistency of the custom attribute metadata from two calls of the same service
93  // after getAttributeCode was called
94  foreach ($customAttributesMetadata1 as $attribute1) {
95  $attribute1->getAttributeCode();
96  }
97  $this->assertEquals(
98  $customAttributesMetadata,
99  $customAttributesMetadata1,
100  'Custom attribute metadata from the same service became different after getAttributeCode was called'
101  );
102 
103  // Verify the consistency of the custom attribute metadata from two services
104  // after getAttributeCode was called
105  foreach ($customAttributesMetadata2 as $attribute2) {
106  $attribute2->getAttributeCode();
107  }
108  $this->assertEquals(
109  $customAttributesMetadata,
110  $customAttributesMetadata2,
111  'Custom attribute metadata from two services are different after getAttributeCode was called'
112  );
113  }

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