File tree Expand file tree Collapse file tree 3 files changed +58
-3
lines changed
app/code/Magento/Customer Expand file tree Collapse file tree 3 files changed +58
-3
lines changed Original file line number Diff line number Diff line change @@ -391,4 +391,23 @@ public function isAttributeVisible($code)
391
391
}
392
392
return false ;
393
393
}
394
+
395
+ /**
396
+ * Retrieve attribute required
397
+ *
398
+ * @param string $code
399
+ * @return bool
400
+ * @throws NoSuchEntityException
401
+ * @throws \Magento\Framework\Exception\LocalizedException
402
+ */
403
+ public function isAttributeRequired ($ code )
404
+ {
405
+ $ attributeMetadata = $ this ->_addressMetadataService ->getAttributeMetadata ($ code );
406
+
407
+ if ($ attributeMetadata ) {
408
+ return $ attributeMetadata ->isRequired ();
409
+ }
410
+
411
+ return false ;
412
+ }
394
413
}
Original file line number Diff line number Diff line change @@ -414,4 +414,43 @@ public function isAttributeVisibleDataProvider()
414
414
['invalid_code ' , false ]
415
415
];
416
416
}
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
+ }
417
456
}
Original file line number Diff line number Diff line change 486
486
</item >
487
487
</argument >
488
488
<settings >
489
- <validation >
490
- <rule name =" required-entry" xsi : type =" boolean" >true</rule >
491
- </validation >
492
489
<dataType >text</dataType >
493
490
</settings >
494
491
</field >
You can’t perform that action at this time.
0 commit comments