public function testExtract() { $customerData = ['firstname' => 'firstname', 'lastname' => 'firstname', 'email' => 'email.example.com']; $this->formFactory->expects($this->once())->method('create')->with('customer', 'form-code')->willReturn($this->customerForm); $this->customerForm->expects($this->once())->method('extractData')->with($this->request)->willReturn($customerData); $this->customerForm->expects($this->once())->method('getAllowedAttributes')->willReturn(['group_id' => 'attribute object']); $this->customerFactory->expects($this->once())->method('create')->willReturn($this->customerData); $this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($this->customerData, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($this->customerData); $this->storeManager->expects($this->once())->method('getStore')->willReturn($this->store); $this->store->expects($this->exactly(2))->method('getId')->willReturn(1); $this->customerGroupManagement->expects($this->once())->method('getDefaultGroup')->with(1)->willReturn($this->customerGroup); $this->customerGroup->expects($this->once())->method('getId')->willReturn(1); $this->customerData->expects($this->once())->method('setGroupId')->with(1); $this->store->expects($this->once())->method('getWebsiteId')->willReturn(1); $this->customerData->expects($this->once())->method('setWebsiteId')->with(1); $this->customerData->expects($this->once())->method('setStoreId')->with(1); $this->assertSame($this->customerData, $this->customerExtractor->extract('form-code', $this->request)); }
public function setUp() { $this->_dataHelper = $this->getMockBuilder('\\Magento\\Customer\\Helper\\Data')->disableOriginalConstructor()->setMethods(array('__construct'))->getMock(); $this->_mockRequest = $this->getMock('Magento\\Framework\\App\\RequestInterface', ['getPost', 'getModuleName', 'setModuleName', 'getActionName', 'setActionName', 'getParam', 'getCookie'], [], '', false); $this->_additionalAttributes = array('is_in_request_data', 'is_not_in_request_data'); $this->_mockMetadataForm = $this->getMockBuilder('\\Magento\\Customer\\Model\\Metadata\\Form')->disableOriginalConstructor()->getMock(); $filteredData = array('filter_key' => 'filter_value', 'attribute_is_not_front_end_input' => false, 'attribute_is_front_end_input' => true); $this->_mockMetadataForm->expects($this->once())->method('extractData')->with($this->_mockRequest, self::SCOPE)->will($this->returnValue($filteredData)); $requestData = array('is_in_request_data' => 'request_data_value'); $this->_mockRequest->expects($this->once())->method('getPost')->with(self::SCOPE)->will($this->returnValue($requestData)); $attributeIsFrontEndInput = $this->getMockBuilder('\\Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata')->disableOriginalConstructor()->getMock(); $attributeIsFrontEndInput->expects($this->once())->method('getAttributeCode')->will($this->returnValue('attribute_is_front_end_input')); $attributeIsFrontEndInput->expects($this->once())->method('getFrontendInput')->will($this->returnValue('boolean')); $attributeIsNotFrontEndInput = $this->getMockBuilder('\\Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata')->disableOriginalConstructor()->getMock(); $attributeIsNotFrontEndInput->expects($this->once())->method('getAttributeCode')->will($this->returnValue('attribute_is_not_front_end_input')); $attributeIsNotFrontEndInput->expects($this->once())->method('getFrontendInput')->will($this->returnValue(false)); $formAttributes = array($attributeIsFrontEndInput, $attributeIsNotFrontEndInput); $this->_mockMetadataForm->expects($this->once())->method('getAttributes')->will($this->returnValue($formAttributes)); }
public function testExecuteWithException() { $this->request->expects($this->once())->method('getPost')->willReturn(null); $this->form->expects($this->once())->method('setInvisibleIgnored'); $this->form->expects($this->atLeastOnce())->method('extractData')->willReturn([]); $this->form->expects($this->never())->method('validateData'); $this->extensibleDataObjectConverter->expects($this->once())->method('toFlatArray')->willReturn([]); $validationResult = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\ValidationResultsInterface', [], '', false, true, true); $error = $this->getMock('Magento\\Framework\\Message\\Error', [], [], '', false); $error->expects($this->once())->method('getText')->willReturn('Error text'); $exception = $this->getMock('Magento\\Framework\\Validator\\Exception', [], [], '', false); $exception->expects($this->once())->method('getMessages')->willReturn([$error]); $validationResult->expects($this->once())->method('getMessages')->willThrowException($exception); $this->customerAccountManagement->expects($this->once())->method('validate')->willReturn($validationResult); $this->controller->execute(); }