public function setUp() { $this->context = $this->getMockBuilder('Magento\\Framework\\App\\Helper\\Context')->disableOriginalConstructor()->getMock(); $this->customerMetadataService = $this->getMockBuilder('Magento\\Customer\\Service\\V1\\CustomerMetadataServiceInterface')->disableOriginalConstructor()->getMock(); $attributeMetadata = $this->getMockBuilder('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata')->disableOriginalConstructor()->getMock(); $attributeMetadata->expects($this->any())->method('isVisible')->will($this->returnValue(true)); $this->customerMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValue($attributeMetadata)); $this->object = new View($this->context, $this->customerMetadataService); }
/** * @param \Magento\Customer\Service\V1\Data\Customer $customerData * @param string $expectedCustomerName * @param bool $isPrefixAllowed * @param bool $isMiddleNameAllowed * @param bool $isSuffixAllowed * @dataProvider getCustomerNameDataProvider */ public function testGetCustomerName($customerData, $expectedCustomerName, $isPrefixAllowed = false, $isMiddleNameAllowed = false, $isSuffixAllowed = false) { $visibleAttribute = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata', array(), array(), '', false); $visibleAttribute->expects($this->any())->method('isVisible')->will($this->returnValue(true)); $invisibleAttribute = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata', array(), array(), '', false); $invisibleAttribute->expects($this->any())->method('isVisible')->will($this->returnValue(false)); $this->_customerMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValueMap(array(array('customer', 'prefix', $isPrefixAllowed ? $visibleAttribute : $invisibleAttribute), array('customer', 'middlename', $isMiddleNameAllowed ? $visibleAttribute : $invisibleAttribute), array('customer', 'suffix', $isSuffixAllowed ? $visibleAttribute : $invisibleAttribute)))); $this->assertEquals($expectedCustomerName, $this->_helper->getCustomerName($customerData), 'Full customer name is invalid'); }
/** * @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->metadataServiceMock->expects($this->once())->method('getAllAddressAttributeMetadata')->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)); }
/** * @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->returnValueMap(array(array('customer_address', $attrCode, $attributeMock), array('customer', $attrCode, $customAttrMock)))); $this->assertEquals($result, $this->helper->getAttributeValidationClass($attrCode)); }