public function setUp() { $this->_objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_escaper = $this->getMock('Magento\\Framework\\Escaper', [], [], '', false); $context = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false); $context->expects($this->any())->method('getEscaper')->will($this->returnValue($this->_escaper)); $addressHelper = $this->getMock('Magento\\Customer\\Helper\\Address', [], [], '', false); $this->_options = $this->getMock('Magento\\Customer\\Model\\Options', [], [], '', false); $this->attribute = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->getMockForAbstractClass(); $this->customerMetadata = $this->getMockBuilder('\\Magento\\Customer\\Api\\CustomerMetadataInterface')->getMockForAbstractClass(); $this->customerMetadata->expects($this->any())->method('getAttributeMetadata')->will($this->returnValue($this->attribute)); $this->customerMetadata->expects($this->any())->method('getCustomAttributesMetadata')->will($this->returnValue([])); $this->addressMetadata = $this->getMockBuilder('\\Magento\\Customer\\Api\\AddressMetadataInterface')->getMockForAbstractClass(); $this->addressMetadata->expects($this->any())->method('getAttributeMetadata')->will($this->returnValue($this->attribute)); $this->_block = new Name($context, $addressHelper, $this->customerMetadata, $this->_options, $this->addressMetadata); }
/** * @param $attrCode * @param $attrClass * @param $customAttrClass * @param $result * @dataProvider getAttributeValidationClassDataProvider */ public function testGetAttributeValidationClass($attrCode, $attrClass, $customAttrClass, $result) { $attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->getMock(); $attributeMock->expects($this->any())->method('getFrontendClass')->will($this->returnValue($attrClass)); $customAttrMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->getMock(); $customAttrMock->expects($this->any())->method('isVisible')->will($this->returnValue(true)); $customAttrMock->expects($this->any())->method('getFrontendClass')->will($this->returnValue($customAttrClass)); $this->customerMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValue($customAttrMock)); $this->addressMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValue($attributeMock)); $this->assertEquals($result, $this->helper->getAttributeValidationClass($attrCode)); }
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()); }