/**
  * Get attribute model by attribute data object
  *
  * @param string $entityType
  * @param AttributeMetadataInterface $attribute
  * @return Attribute
  * @throws NoSuchEntityException
  */
 public function getModelByAttribute($entityType, AttributeMetadataInterface $attribute)
 {
     /** @var Attribute $model */
     $model = $this->attributeMetadataDataProvider->getAttribute($entityType, $attribute->getAttributeCode());
     if ($model) {
         return $model;
     } else {
         throw new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_DOUBLE_FIELDS, ['fieldName' => 'entityType', 'fieldValue' => $entityType, 'field2Name' => 'attributeCode', 'field2Value' => $attribute->getAttributeCode()]));
     }
 }
 /**
  * Create Form Element
  *
  * @param \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute
  * @param string|int|bool $value
  * @param string $entityTypeCode
  * @param bool $isAjax
  * @return \Magento\Customer\Model\Metadata\Form\AbstractData
  */
 public function create(\Magento\Customer\Api\Data\AttributeMetadataInterface $attribute, $value, $entityTypeCode, $isAjax = false)
 {
     $dataModelClass = $attribute->getDataModel();
     $params = ['entityTypeCode' => $entityTypeCode, 'value' => is_null($value) ? false : $value, 'isAjax' => $isAjax, 'attribute' => $attribute];
     /** TODO fix when Validation is implemented MAGETWO-17341 */
     if ($dataModelClass == 'Magento\\Customer\\Model\\Attribute\\Data\\Postcode') {
         $dataModelClass = 'Magento\\Customer\\Model\\Metadata\\Form\\Postcode';
     }
     if (!empty($dataModelClass)) {
         $dataModel = $this->_objectManager->create($dataModelClass, $params);
     } else {
         $dataModelClass = sprintf('Magento\\Customer\\Model\\Metadata\\Form\\%s', $this->_string->upperCaseWords($attribute->getFrontendInput()));
         $dataModel = $this->_objectManager->create($dataModelClass, $params);
     }
     return $dataModel;
 }
 /**
  * @param AttributeMetadataInterface $attribute
  * @return array
  */
 protected function _getAttributeOptionsArray(AttributeMetadataInterface $attribute)
 {
     $options = $attribute->getOptions();
     $result = [];
     foreach ($options as $option) {
         $result[] = $this->dataObjectProcessor->buildOutputDataArray($option, 'Magento\\Customer\\Api\\Data\\OptionInterface');
     }
     return $result;
 }
 public function testGetList()
 {
     $attributeCode = 'attribute_code';
     $billingPrefix = 'billing_';
     $this->customerMetadata->expects($this->once())->method('getAllAttributesMetadata')->willReturn([]);
     $this->addressMetadata->expects($this->once())->method('getAllAttributesMetadata')->willReturn([$this->attribute]);
     $this->addressMetadataManagement->expects($this->once())->method('canBeFilterableInGrid')->with($this->attribute)->willReturn(true);
     $this->addressMetadataManagement->expects($this->once())->method('canBeSearchableInGrid')->with($this->attribute)->willReturn(true);
     $this->attribute->expects($this->atLeastOnce())->method('getAttributeCode')->willReturn($attributeCode);
     $this->attribute->expects($this->once())->method('getFrontendInput')->willReturn('frontend-input');
     $this->attribute->expects($this->once())->method('getFrontendLabel')->willReturn('frontend-label');
     $this->attribute->expects($this->once())->method('getBackendType')->willReturn('backend-type');
     $this->attribute->expects($this->once())->method('getOptions')->willReturn([$this->option]);
     $this->attribute->expects($this->once())->method('getIsUsedInGrid')->willReturn(true);
     $this->attribute->expects($this->once())->method('getIsVisibleInGrid')->willReturn(true);
     $this->attribute->expects($this->once())->method('getValidationRules')->willReturn([]);
     $this->attribute->expects($this->once())->method('isRequired')->willReturn(false);
     $this->option->expects($this->once())->method('getLabel')->willReturn('Label');
     $this->option->expects($this->once())->method('getValue')->willReturn('Value');
     $this->attributeFilter->expects($this->once())->method('filter')->willReturnArgument(0);
     $this->assertEquals([$billingPrefix . $attributeCode => ['attribute_code' => 'billing_attribute_code', 'frontend_input' => 'frontend-input', 'frontend_label' => 'frontend-label', 'backend_type' => 'backend-type', 'options' => [['label' => 'Label', 'value' => 'Value']], 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true, 'validation_rules' => [], 'required' => false, 'entity_type_code' => 'customer_address']], $this->component->getList());
 }
Esempio n. 5
0
 /**
  * @param array $validationRules The date Min/Max validation rules
  * @param int $expectedValue The value we expect from Dob::getMaxDateRange()
  *
  * @dataProvider getMaxDateRangeDataProvider
  */
 public function testGetMaxDateRange($validationRules, $expectedValue)
 {
     $this->attribute->expects($this->once())->method('getValidationRules')->will($this->returnValue($validationRules));
     $this->assertEquals($expectedValue, $this->_block->getMaxDateRange());
 }
Esempio n. 6
0
 /**
  * @param bool $isRequired Determines whether the 'taxvat' attribute is required
  * @param bool $expectedValue The value we expect from Taxvat::isRequired()
  * @return void
  *
  * @dataProvider isRequiredDataProvider
  */
 public function testIsRequired($isRequired, $expectedValue)
 {
     $this->attribute->expects($this->once())->method('isRequired')->will($this->returnValue($isRequired));
     $this->assertSame($expectedValue, $this->_block->isRequired());
 }