Skip to content

Commit bdcc16a

Browse files
committed
Merge remote-tracking branch 'github-magento2ce/MAGETWO-91659' into EPAM-PR-12
2 parents a103585 + 1d91243 commit bdcc16a

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,35 @@ public function getBookUrl()
127127
}
128128

129129
/**
130+
* Retrieve edit url.
131+
*
130132
* @return void
131133
*/
132134
public function getEditUrl()
133135
{
134136
}
135137

136138
/**
139+
* Retrieve delete url.
140+
*
137141
* @return void
138142
*/
139143
public function getDeleteUrl()
140144
{
141145
}
142146

143147
/**
148+
* Retrieve create url.
149+
*
144150
* @return void
145151
*/
146152
public function getCreateUrl()
147153
{
148154
}
149155

150156
/**
157+
* Retrieve block renderer.
158+
*
151159
* @param string $renderer
152160
* @return \Magento\Framework\View\Element\BlockInterface
153161
*/
@@ -204,6 +212,8 @@ public function getStreetLines($store = null)
204212
}
205213

206214
/**
215+
* Retrieve address format.
216+
*
207217
* @param string $code
208218
* @return Format|string
209219
*/
@@ -391,4 +401,23 @@ public function isAttributeVisible($code)
391401
}
392402
return false;
393403
}
404+
405+
/**
406+
* Retrieve attribute required
407+
*
408+
* @param string $code
409+
* @return bool
410+
* @throws NoSuchEntityException
411+
* @throws \Magento\Framework\Exception\LocalizedException
412+
*/
413+
public function isAttributeRequired($code)
414+
{
415+
$attributeMetadata = $this->_addressMetadataService->getAttributeMetadata($code);
416+
417+
if ($attributeMetadata) {
418+
return $attributeMetadata->isRequired();
419+
}
420+
421+
return false;
422+
}
394423
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,43 @@ public function isAttributeVisibleDataProvider()
414414
['invalid_code', false]
415415
];
416416
}
417+
418+
/**
419+
* Test is required filed by attribute code
420+
*
421+
* @param string $attributeCode
422+
* @param bool $isMetadataExists
423+
* @dataProvider isAttributeRequiredDataProvider
424+
* @covers \Magento\Customer\Helper\Address::isAttributeRequired()
425+
* @return void
426+
*/
427+
public function testIsAttributeRequired($attributeCode, $isMetadataExists)
428+
{
429+
$attributeMetadata = null;
430+
if ($isMetadataExists) {
431+
$attributeMetadata = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
432+
->getMockForAbstractClass();
433+
$attributeMetadata->expects($this->once())
434+
->method('isRequired')
435+
->willReturn(true);
436+
}
437+
$this->addressMetadataService->expects($this->once())
438+
->method('getAttributeMetadata')
439+
->with($attributeCode)
440+
->willReturn($attributeMetadata);
441+
$this->assertEquals($isMetadataExists, $this->helper->isAttributeRequired($attributeCode));
442+
}
443+
444+
/**
445+
* Data provider for test testIsAttributeRequire
446+
*
447+
* @return array
448+
*/
449+
public function isAttributeRequiredDataProvider()
450+
{
451+
return [
452+
['fax', true],
453+
['invalid_code', false]
454+
];
455+
}
417456
}

app/code/Magento/Customer/view/base/ui_component/customer_form.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,6 @@
486486
</item>
487487
</argument>
488488
<settings>
489-
<validation>
490-
<rule name="required-entry" xsi:type="boolean">true</rule>
491-
</validation>
492489
<dataType>text</dataType>
493490
</settings>
494491
</field>

0 commit comments

Comments
 (0)