예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function getAttributeMetadata($attributeCode)
 {
     /** @var AbstractAttribute $attribute */
     $attribute = $this->attributeMetadataDataProvider->getAttribute(AddressMetadataInterface::ENTITY_TYPE_ADDRESS, $attributeCode);
     if ($attribute && ($attributeCode === 'id' || $attribute->getId() !== null)) {
         $attributeMetadata = $this->attributeMetadataConverter->createMetadataAttribute($attribute);
         return $attributeMetadata;
     } else {
         throw new NoSuchEntityException(__('No such entity with %fieldName = %fieldValue, %field2Name = %field2Value', ['fieldName' => 'entityType', 'fieldValue' => AddressMetadataInterface::ENTITY_TYPE_ADDRESS, 'field2Name' => 'attributeCode', 'field2Value' => $attributeCode]));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getAttributeMetadata($attributeCode)
 {
     /** @var AbstractAttribute $attribute */
     $attribute = $this->attributeMetadataDataProvider->getAttribute(self::ENTITY_TYPE_CUSTOMER, $attributeCode);
     if ($attribute && ($attributeCode === 'id' || $attribute->getId() !== null)) {
         $attributeMetadata = $this->attributeMetadataConverter->createMetadataAttribute($attribute);
         return $attributeMetadata;
     } else {
         throw new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_DOUBLE_FIELDS, ['fieldName' => 'entityType', 'fieldValue' => self::ENTITY_TYPE_CUSTOMER, 'field2Name' => 'attributeCode', 'field2Value' => $attributeCode]));
     }
 }
 public function testGetCustomAttributesMetadataWithoutAttributes()
 {
     $attributeCode = 'id';
     $attributeCodes = [$attributeCode];
     $this->attributeProviderMock->expects($this->once())->method('getAllAttributeCodes')->with(AddressMetadataInterface::ENTITY_TYPE_ADDRESS, AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS)->willReturn($attributeCodes);
     /** @var AbstractAttribute|\PHPUnit_Framework_MockObject_MockObject $attributeMock */
     $attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->attributeProviderMock->expects($this->once())->method('getAttribute')->with(AddressMetadataInterface::ENTITY_TYPE_ADDRESS, $attributeCode)->willReturn($attributeMock);
     /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $metadataMock */
     $metadataMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock();
     $result = [];
     $this->attributeConverterMock->expects($this->once())->method('createMetadataAttribute')->with($attributeMock)->willReturn($metadataMock);
     $metadataMock->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode);
     $this->assertEquals($result, $this->model->getCustomAttributesMetadata());
 }