File tree Expand file tree Collapse file tree 3 files changed +68
-3
lines changed
app/code/Magento/Customer Expand file tree Collapse file tree 3 files changed +68
-3
lines changed Original file line number Diff line number Diff line change @@ -127,27 +127,35 @@ public function getBookUrl()
127
127
}
128
128
129
129
/**
130
+ * Retrieve edit url.
131
+ *
130
132
* @return void
131
133
*/
132
134
public function getEditUrl ()
133
135
{
134
136
}
135
137
136
138
/**
139
+ * Retrieve delete url.
140
+ *
137
141
* @return void
138
142
*/
139
143
public function getDeleteUrl ()
140
144
{
141
145
}
142
146
143
147
/**
148
+ * Retrieve create url.
149
+ *
144
150
* @return void
145
151
*/
146
152
public function getCreateUrl ()
147
153
{
148
154
}
149
155
150
156
/**
157
+ * Retrieve block renderer.
158
+ *
151
159
* @param string $renderer
152
160
* @return \Magento\Framework\View\Element\BlockInterface
153
161
*/
@@ -204,6 +212,8 @@ public function getStreetLines($store = null)
204
212
}
205
213
206
214
/**
215
+ * Retrieve address format.
216
+ *
207
217
* @param string $code
208
218
* @return Format|string
209
219
*/
@@ -391,4 +401,23 @@ public function isAttributeVisible($code)
391
401
}
392
402
return false ;
393
403
}
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
+ }
394
423
}
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