public function testSetAccountData() { $taxClassId = 1; $attributes = array(array('email', '*****@*****.**'), array('group_id', 1)); $attributeMocks = array(); foreach ($attributes as $attribute) { $attributeMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata', array(), array(), '', false); $attributeMock->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attribute[0])); $attributeMocks[] = $attributeMock; } $customerGroupMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\CustomerGroup', array(), array(), '', false); $customerGroupMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue($taxClassId)); $customerFormMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', array(), array(), '', false); $customerFormMock->expects($this->any())->method('getAttributes')->will($this->returnValue($attributeMocks)); $customerFormMock->expects($this->any())->method('extractData')->will($this->returnValue(array())); $customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue(array())); $customerFormMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->getMock('Magento\\Framework\\App\\RequestInterface'))); $customerMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Customer', array(), array(), '', false); $customerMock->expects($this->any())->method('__toArray')->will($this->returnValue(array('email' => '*****@*****.**', 'group_id' => 1))); $quoteMock = $this->getMock('Magento\\Sales\\Model\\Quote', array(), array(), '', false); $quoteMock->expects($this->any())->method('getCustomerData')->will($this->returnValue($customerMock)); $quoteMock->expects($this->once())->method('addData')->with(array('customer_email' => $attributes[0][1], 'customer_group_id' => $attributes[1][1], 'customer_tax_class_id' => $taxClassId)); $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerFormMock)); $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); $this->customerBuilderMock->expects($this->any())->method('populateWithArray')->will($this->returnSelf()); $this->customerBuilderMock->expects($this->any())->method('create')->will($this->returnValue($customerMock)); $this->customerBuilderMock->expects($this->any())->method('mergeDataObjectWithArray')->will($this->returnArgument(0)); $this->customerGroupServiceMock->expects($this->once())->method('getGroup')->will($this->returnValue($customerGroupMock)); $this->adminOrderCreate->setAccountData(array()); }
/** * test getCustomer method, method returns depersonalized customer Data */ public function testGetCustomerDepersonalizeCustomerData() { $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true)); $this->viewMock->expects($this->once())->method('isLayoutLoaded')->will($this->returnValue(true)); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true)); $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($this->customerGroupId)); $this->customerDataBuilderMock->expects($this->once())->method('create')->will($this->returnValue($this->customerDataMock)); $this->customerDataBuilderMock->expects($this->once())->method('setGroupId')->with($this->equalTo($this->customerGroupId))->will($this->returnSelf()); $this->assertEquals($this->customerDataMock, $this->currentCustomer->getCustomer()); }
/** * @param $customerData * @param $isSingleStoreMode * @param $canModifyCustomer */ private function _setupStoreMode($customerData, $isSingleStoreMode, $canModifyCustomer) { $backendSessionMock = $this->getMock('\\Magento\\Backend\\Model\\Session', ['getCustomerData'], [], '', false); $backendSessionMock->expects($this->any())->method('getCustomerData')->will($this->returnValue([])); $layoutMock = $this->getMock('\\Magento\\Framework\\View\\Layout\\Element\\Layout', ['createBlock'], [], '', false); $layoutMock->expects($this->at(0))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group')->will($this->returnValue($this->objectManagerHelper->getObject('\\Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group'))); $layoutMock->expects($this->at(1))->method('createBlock')->with('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element'))); if (empty($customerData['id'])) { $layoutMock->expects($this->at(2))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail'))); } $urlBuilderMock = $this->getMock('\\Magento\\Backend\\Model\\Url', ['getBaseUrl'], [], '', false); $urlBuilderMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('someUrl')); $storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false); $storeManagerMock->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue($isSingleStoreMode)); $customerObject = $this->getMockBuilder('\\Magento\\Customer\\Service\\V1\\Data\\Customer')->setMethods(['__toArray', 'getId'])->disableOriginalConstructor()->getMock(); $customerObject->expects($this->any())->method('__toArray')->will($this->returnValue($customerData)); if (!empty($customerData['id'])) { $customerObject->expects($this->any())->method('getId')->will($this->returnValue($customerData['id'])); } $fieldset = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Fieldset')->setMethods(['getForm', 'addField', 'removeField'])->disableOriginalConstructor()->getMock(); $accountForm = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->setMethods(['create', 'addFieldset', 'getElement', 'setValues'])->disableOriginalConstructor()->getMock(); $accountForm->expects($this->any())->method('addFieldset')->with('base_fieldset')->will($this->returnValue($fieldset)); $accountForm->expects($this->any())->method('setValues')->will($this->returnValue($accountForm)); $fieldset->expects($this->any())->method('getForm')->will($this->returnValue($accountForm)); $formElement = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Select')->setMethods(['setRenderer', 'addClass', 'setDisabled'])->disableOriginalConstructor()->getMock(); $formElement->expects($this->any())->method('setRenderer')->will($this->returnValue(null)); $formElement->expects($this->any())->method('addClass')->will($this->returnValue(null)); $formElement->expects($this->any())->method('setDisabled')->will($this->returnValue(null)); $accountForm->expects($this->any())->method('getElement')->withAnyParameters()->will($this->returnValue($formElement)); $fieldset->expects($this->any())->method('addField')->will($this->returnValue($formElement)); $customerForm = $this->getMock('\\Magento\\Customer\\Model\\Metadata\\Form', ['getAttributes'], [], '', false); $customerForm->expects($this->any())->method('getAttributes')->will($this->returnValue([])); $this->contextMock->expects($this->any())->method('getBackendSession')->will($this->returnValue($backendSessionMock)); $this->contextMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $this->contextMock->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($urlBuilderMock)); $this->contextMock->expects($this->any())->method('getStoreManager')->will($this->returnValue($storeManagerMock)); $this->customerBuilderMock->expects($this->any())->method('populateWithArray')->will($this->returnValue($this->customerBuilderMock)); $this->customerBuilderMock->expects($this->any())->method('create')->will($this->returnValue($customerObject)); $this->customerHelperMock->expects($this->any())->method('getNamePrefixOptions')->will($this->returnValue(['Pref1', 'Pref2'])); $this->customerHelperMock->expects($this->any())->method('getNameSuffixOptions')->will($this->returnValue(['Suf1', 'Suf2'])); $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($accountForm)); $this->customerFormFactoryMock->expects($this->any())->method('create')->with('customer', 'adminhtml_customer')->will($this->returnValue($customerForm)); $this->customerAccountServiceInterfaceMock->expects($this->any())->method('canModify')->withAnyParameters()->will($this->returnValue($canModifyCustomer)); $this->customerAccountServiceInterfaceMock->expects($this->any())->method('getConfirmationStatus')->withAnyParameters()->will($this->returnValue(CustomerAccountServiceInterface::ACCOUNT_CONFIRMED)); }
/** * @dataProvider saveBillingDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function testSaveBilling($data, $customerAddressId, $quoteCustomerId, $addressCustomerId, $isAddress, $validateDataResult, $validateResult, $checkoutMethod, $customerPassword, $confirmPassword, $validationResultMessages, $isEmailAvailable, $isVirtual, $getStepDataResult, $expected) { $passwordHash = 'password hash'; $this->requestMock->expects($this->any())->method('isAjax')->will($this->returnValue(false)); $customerValidationResultMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\CustomerValidationResults', [], [], '', false); $customerValidationResultMock->expects($this->any())->method('isValid')->will($this->returnValue(empty($validationResultMessages))); $customerValidationResultMock->expects($this->any())->method('getMessages')->will($this->returnValue($validationResultMessages)); $this->customerAccountServiceMock->expects($this->any())->method('getPasswordHash')->with($customerPassword)->will($this->returnValue($passwordHash)); $this->customerAccountServiceMock->expects($this->any())->method('validateCustomerData')->will($this->returnValue($customerValidationResultMock)); $this->customerAccountServiceMock->expects($this->any())->method('isEmailAvailable')->will($this->returnValue($isEmailAvailable)); /** @var \Magento\Sales\Model\Quote|\PHPUnit_Framework_MockObject_MockObject $quoteMock */ $quoteMock = $this->getMock('Magento\\Sales\\Model\\Quote', ['getCustomerId', '__wakeup', 'getBillingAddress', 'setPasswordHash', 'getCheckoutMethod', 'isVirtual', 'getShippingAddress', 'getCustomerData', 'collectTotals', 'save'], [], '', false); $shippingAddressMock = $this->getMock('Magento\\Sales\\Model\\Quote\\Address', ['setSameAsBilling', '__wakeup', 'unserialize'], [], '', false); $shippingAddressMock->expects($this->any())->method('setSameAsBilling')->with((int) $data['use_for_shipping']); $quoteMock->expects($this->any())->method('setPasswordHash')->with($passwordHash); $quoteMock->expects($this->any())->method('getCheckoutMethod')->will($this->returnValue($checkoutMethod)); $quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue($isVirtual)); $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock)); $addressMock = $this->getMock('Magento\\Sales\\Model\\Quote\\Address', ['setSaveInAddressBook', 'getData', 'setEmail', '__wakeup', 'importCustomerAddressData', 'validate'], [], '', false); $addressMock->expects($this->any())->method('importCustomerAddressData')->will($this->returnSelf()); $addressMock->expects($this->atLeastOnce())->method('validate')->will($this->returnValue($validateResult)); $addressMock->expects($this->any())->method('getData')->will($this->returnValue([])); $quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock)); $quoteMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($quoteCustomerId)); $formMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false); $formMock->expects($this->atLeastOnce())->method('validateData')->will($this->returnValue($validateDataResult)); $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap([['customer_password', $customerPassword], ['confirm_password', $confirmPassword]])); $formMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->requestMock)); $this->customerFormFactoryMock->expects($this->any())->method('create')->will($this->returnValue($formMock)); $customerDataMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Customer', [], [], '', false); $customerDataMock->expects($this->any())->method('__toArray')->will($this->returnValue([])); $this->customerBuilderMock->expects($this->any())->method('create')->will($this->returnValue($customerDataMock)); $quoteMock->expects($this->atLeastOnce())->method('getCustomerData')->will($this->returnValue($customerDataMock)); $this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); $this->checkoutSessionMock->expects($this->any())->method('getStepData')->will($this->returnValue((int) $data['use_for_shipping'] === 1 ? true : $getStepDataResult)); $this->checkoutSessionMock->expects($this->any())->method('setStepData')->will($this->returnSelf()); $customerAddressMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Address', [], [], '', false); $customerAddressMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($addressCustomerId)); $this->customerAddressServiceMock->expects($this->any())->method('getAddress')->will($isAddress ? $this->returnValue($customerAddressMock) : $this->throwException(new \Exception())); $this->customerBuilderMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once())->method('populate'); $this->customerBuilderMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once())->method('setGroupId'); $websiteMock = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false); $this->storeManagerMock->expects($this->any())->method('getWebsite')->will($this->returnValue($websiteMock)); $this->assertEquals($expected, $this->onepage->saveBilling($data, $customerAddressId)); }