Skip to content

Commit fe03e24

Browse files
author
Sergii Kovalenko
committed
Merge branch 'MAGETWO-49518' into BUGS
2 parents 9c5eca1 + 3e29e22 commit fe03e24

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

app/code/Magento/Customer/Helper/Address.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,19 @@ public function isVatAttributeVisible()
373373
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
374374
);
375375
}
376+
377+
/**
378+
* Retrieve attribute visibility
379+
*
380+
* @param string $code
381+
* @return bool
382+
*/
383+
public function isAttributeVisible($code)
384+
{
385+
$attributeMetadata = $this->_addressMetadataService->getAttributeMetadata($code);
386+
if ($attributeMetadata) {
387+
return $attributeMetadata->isVisible();
388+
}
389+
return false;
390+
}
376391
}

app/code/Magento/Customer/Test/Unit/Helper/AddressTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,34 @@ public function getFormatDataProvider()
372372
['invalid_code', '']
373373
];
374374
}
375+
376+
/**
377+
* @param string $attributeCode
378+
* @param bool $isMetadataExists
379+
* @dataProvider isAttributeVisibleDataProvider
380+
*/
381+
public function testIsAttributeVisible($attributeCode, $isMetadataExists)
382+
{
383+
$attributeMetadata = null;
384+
if ($isMetadataExists) {
385+
$attributeMetadata = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
386+
->getMockForAbstractClass();
387+
$attributeMetadata->expects($this->once())
388+
->method('isVisible')
389+
->willReturn(true);
390+
}
391+
$this->addressMetadataService->expects($this->once())
392+
->method('getAttributeMetadata')
393+
->with($attributeCode)
394+
->willReturn($attributeMetadata);
395+
$this->assertEquals($isMetadataExists, $this->helper->isAttributeVisible($attributeCode));
396+
}
397+
398+
public function isAttributeVisibleDataProvider()
399+
{
400+
return [
401+
['fax', true],
402+
['invalid_code', false]
403+
];
404+
}
375405
}

0 commit comments

Comments
 (0)