/** * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function testCreateAddressFromModelWithCustomerId() { $defaultBillingId = 1; $defaultShippingId = 1; $customerId = 1; $attributeCode = 'attribute_code'; $addressModelMock = $this->getAddressMockForCreate(); $addressModelMock->expects($this->once())->method('getId')->will($this->returnValue(null)); $addressModelMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($customerId)); $addressModelMock->expects($this->any())->method('getParentId'); $getData = function ($key, $index = null) use($attributeCode, $customerId) { $result = null; switch ($key) { case $attributeCode: $result = 'some_data'; break; case 'customer_id': $result = $customerId; break; } return $result; }; $addressModelMock->expects($this->any())->method('getData')->will($this->returnCallback($getData)); $attributeMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata', array('getAttributeCode'), array(), '', false); $attributeMock->expects($this->once())->method('getAttributeCode')->will($this->returnValue($attributeCode)); $addressMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Address', array(), array(), '', false); $this->addressMetadataServiceMock->expects($this->once())->method('getAllAttributesMetadata')->will($this->returnValue(array($attributeMock))); $this->addressBuilderMock->expects($this->once())->method('create')->will($this->returnValue($addressMock)); $this->addressBuilderMock->expects($this->once())->method('setCustomerId')->with($this->equalTo($customerId)); $this->assertEquals($addressMock, $this->model->createAddressFromModel($addressModelMock, $defaultBillingId, $defaultShippingId)); }
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->_customerHelper = $this->getMock('Magento\\Customer\\Helper\\Data', [], [], '', false); $this->_attributeMetadata = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata', [], [], '', false); $this->customerMetadataService = $this->getMockBuilder('Magento\\Customer\\Service\\V1\\CustomerMetadataService')->disableOriginalConstructor()->getMock(); $this->customerMetadataService->expects($this->any())->method('getCustomAttributesMetadata')->will($this->returnValue([])); $this->customerMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValue($this->_attributeMetadata)); $this->addressMetadataService = $this->getMockBuilder('Magento\\Customer\\Service\\V1\\AddressMetadataService')->disableOriginalConstructor()->getMock(); $this->addressMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValue($this->_attributeMetadata)); $this->_block = new Name($context, $addressHelper, $this->customerMetadataService, $this->addressMetadataService, $this->_customerHelper); }
/** * @param $attrCode * @param $attrClass * @param $customAttrClass * @param $result * @dataProvider getAttributeValidationClassDataProvider */ public function testGetAttributeValidationClass($attrCode, $attrClass, $customAttrClass, $result) { $attributeMock = $this->getMockBuilder('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata')->disableOriginalConstructor()->getMock(); $attributeMock->expects($this->any())->method('getFrontendClass')->will($this->returnValue($attrClass)); $customAttrMock = $this->getMockBuilder('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata')->disableOriginalConstructor()->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)); }