Skip to content

Commit a7a9100

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-91725' into EPAM-PR-19
2 parents 563488e + 436e3d3 commit a7a9100

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

app/code/Magento/Customer/Model/Metadata/CustomerMetadata.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,30 @@ class CustomerMetadata implements CustomerMetadataInterface
3333
*/
3434
private $attributeMetadataDataProvider;
3535

36+
/**
37+
* List of system attributes which should be available to the clients.
38+
*
39+
* @var string[]
40+
*/
41+
private $systemAttributes;
42+
3643
/**
3744
* @param AttributeMetadataConverter $attributeMetadataConverter
3845
* @param AttributeMetadataDataProvider $attributeMetadataDataProvider
46+
* @param string[] $systemAttributes
3947
*/
4048
public function __construct(
4149
AttributeMetadataConverter $attributeMetadataConverter,
42-
AttributeMetadataDataProvider $attributeMetadataDataProvider
50+
AttributeMetadataDataProvider $attributeMetadataDataProvider,
51+
array $systemAttributes = []
4352
) {
4453
$this->attributeMetadataConverter = $attributeMetadataConverter;
4554
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
55+
$this->systemAttributes = $systemAttributes;
4656
}
4757

4858
/**
49-
* {@inheritdoc}
59+
* @inheritdoc
5060
*/
5161
public function getAttributes($formCode)
5262
{
@@ -67,7 +77,7 @@ public function getAttributes($formCode)
6777
}
6878

6979
/**
70-
* {@inheritdoc}
80+
* @inheritdoc
7181
*/
7282
public function getAttributeMetadata($attributeCode)
7383
{
@@ -92,7 +102,7 @@ public function getAttributeMetadata($attributeCode)
92102
}
93103

94104
/**
95-
* {@inheritdoc}
105+
* @inheritdoc
96106
*/
97107
public function getAllAttributesMetadata()
98108
{
@@ -116,7 +126,7 @@ public function getAllAttributesMetadata()
116126
}
117127

118128
/**
119-
* {@inheritdoc}
129+
* @inheritdoc
120130
*/
121131
public function getCustomAttributesMetadata($dataObjectClassName = self::DATA_INTERFACE_NAME)
122132
{
@@ -134,9 +144,10 @@ public function getCustomAttributesMetadata($dataObjectClassName = self::DATA_IN
134144
$isDataObjectMethod = isset($this->customerDataObjectMethods['get' . $camelCaseKey])
135145
|| isset($this->customerDataObjectMethods['is' . $camelCaseKey]);
136146

137-
/** Even though disable_auto_group_change is system attribute, it should be available to the clients */
138147
if (!$isDataObjectMethod
139-
&& (!$attributeMetadata->isSystem() || $attributeCode == 'disable_auto_group_change')
148+
&& (!$attributeMetadata->isSystem()
149+
|| in_array($attributeCode, $this->systemAttributes)
150+
)
140151
) {
141152
$customAttributes[] = $attributeMetadata;
142153
}

app/code/Magento/Customer/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@
127127
<argument name="groupManagement" xsi:type="object">Magento\Customer\Api\GroupManagementInterface\Proxy</argument>
128128
</arguments>
129129
</type>
130+
<type name="Magento\Customer\Model\Metadata\CustomerMetadata">
131+
<arguments>
132+
<argument name="systemAttributes" xsi:type="array">
133+
<item name="disable_auto_group_change" xsi:type="string">disable_auto_group_change</item>
134+
</argument>
135+
</arguments>
136+
</type>
130137
<virtualType name="SectionInvalidationConfigReader" type="Magento\Framework\Config\Reader\Filesystem">
131138
<arguments>
132139
<argument name="idAttributes" xsi:type="array">

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Customer\Api\Data\CustomerInterface as Customer;
1010
use Magento\Customer\Model\Data\AttributeMetadata;
1111
use Magento\TestFramework\TestCase\WebapiAbstract;
12+
use Magento\TestFramework\Helper\Bootstrap;
1213

1314
/**
1415
* Class CustomerMetadataTest
@@ -19,6 +20,19 @@ class CustomerMetadataTest extends WebapiAbstract
1920
const SERVICE_VERSION = "V1";
2021
const RESOURCE_PATH = "/V1/attributeMetadata/customer";
2122

23+
/**
24+
* @var CustomerMetadataInterface
25+
*/
26+
private $customerMetadata;
27+
28+
/**
29+
* Execute per test initialization.
30+
*/
31+
public function setUp()
32+
{
33+
$this->customerMetadata = Bootstrap::getObjectManager()->create(CustomerMetadataInterface::class);
34+
}
35+
2236
/**
2337
* Test retrieval of attribute metadata for the customer entity type.
2438
*
@@ -200,8 +214,7 @@ public function testGetCustomAttributesMetadata()
200214

201215
$attributeMetadata = $this->_webApiCall($serviceInfo);
202216

203-
// There are no default custom attributes.
204-
$this->assertCount(0, $attributeMetadata);
217+
$this->assertCount(count($this->customerMetadata->getCustomAttributesMetadata()), $attributeMetadata);
205218
}
206219

207220
/**

dev/tests/integration/testsuite/Magento/Customer/Model/CustomerMetadataTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,23 @@ protected function setUp()
5151

5252
public function testGetCustomAttributesMetadata()
5353
{
54-
$customAttributesMetadata = $this->service->getCustomAttributesMetadata();
55-
$this->assertCount(0, $customAttributesMetadata, "Invalid number of attributes returned.");
54+
$customAttributesMetadataQty = count($this->service->getCustomAttributesMetadata()) ;
5655

5756
// Verify the consistency of getCustomerAttributeMetadata() function from the 2nd call of the same service
58-
$customAttributesMetadata1 = $this->service->getCustomAttributesMetadata();
59-
$this->assertCount(0, $customAttributesMetadata1, "Invalid number of attributes returned.");
57+
$customAttributesMetadata1Qty = count($this->service->getCustomAttributesMetadata());
58+
$this->assertEquals(
59+
$customAttributesMetadataQty,
60+
$customAttributesMetadata1Qty,
61+
"Invalid number of attributes returned."
62+
);
6063

6164
// Verify the consistency of getCustomAttributesMetadata() function from the 2nd service
62-
$customAttributesMetadata2 = $this->serviceTwo->getCustomAttributesMetadata();
63-
$this->assertCount(0, $customAttributesMetadata2, "Invalid number of attributes returned.");
65+
$customAttributesMetadata2Qty = count($this->serviceTwo->getCustomAttributesMetadata());
66+
$this->assertEquals(
67+
$customAttributesMetadataQty,
68+
$customAttributesMetadata2Qty,
69+
"Invalid number of attributes returned."
70+
);
6471
}
6572

6673
public function testGetNestedOptionsCustomerAttributesMetadata()

0 commit comments

Comments
 (0)