public function testGetAttributes() { $formAttributesMetadata = $this->_service->getAttributes('adminhtml_customer'); $this->assertCount(14, $formAttributesMetadata, "Invalid number of attributes for the specified form."); /** Check some fields of one attribute metadata */ $attributeMetadata = $formAttributesMetadata['firstname']; $this->assertInstanceOf('Magento\\Customer\\Model\\Data\\AttributeMetadata', $attributeMetadata); $this->assertEquals('firstname', $attributeMetadata->getAttributeCode(), 'Attribute code is invalid'); $this->assertNotEmpty($attributeMetadata->getValidationRules(), 'Validation rules are not set'); $this->assertEquals('1', $attributeMetadata->isSystem(), '"Is system" field value is invalid'); $this->assertEquals('40', $attributeMetadata->getSortOrder(), 'Sort order is invalid'); }
/** * Retrieve attributes metadata for the form * * @return \Magento\Customer\Api\Data\AttributeMetadataInterface[] * @throws \LogicException For undefined entity type */ public function getAttributes() { if (!isset($this->_attributes)) { if ($this->_entityType === \Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER) { $this->_attributes = $this->_customerMetadataService->getAttributes($this->_formCode); } elseif ($this->_entityType === \Magento\Customer\Api\AddressMetadataInterface::ENTITY_TYPE_ADDRESS) { $this->_attributes = $this->_addressMetadataService->getAttributes($this->_formCode); } else { throw new \LogicException('Undefined entity type: ' . $this->_entityType); } } return $this->_attributes; }