Esempio n. 1
0
 public function setUp()
 {
     if (!function_exists('libxml_set_external_entity_loader')) {
         $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
     }
     $this->customer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false, true, true);
     $this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
     $this->customerDataFactory = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', ['create'], [], '', false);
     $this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
     $this->form = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false);
     $this->request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, ['getPost']);
     $this->response = $this->getMockForAbstractClass('Magento\\Framework\\App\\ResponseInterface', [], '', false);
     $this->formFactory = $this->getMock('Magento\\Customer\\Model\\Metadata\\FormFactory', ['create'], [], '', false);
     $this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
     $this->extensibleDataObjectConverter = $this->getMock('Magento\\Framework\\Api\\ExtensibleDataObjectConverter', [], [], '', false);
     $this->dataObjectHelper = $this->getMock('Magento\\Framework\\Api\\DataObjectHelper', [], [], '', false);
     $this->dataObjectHelper->expects($this->once())->method('populateWithArray');
     $this->customerAccountManagement = $this->getMockForAbstractClass('Magento\\Customer\\Api\\AccountManagementInterface', [], '', false, true, true);
     $this->resultJson = $this->getMock('Magento\\Framework\\Controller\\Result\\Json', [], [], '', false);
     $this->resultJson->expects($this->once())->method('setData');
     $this->resultJsonFactory = $this->getMock('Magento\\Framework\\Controller\\Result\\JsonFactory', ['create'], [], '', false);
     $this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->controller = $objectHelper->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Validate', ['request' => $this->request, 'response' => $this->response, 'customerDataFactory' => $this->customerDataFactory, 'formFactory' => $this->formFactory, 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverter, 'customerAccountManagement' => $this->customerAccountManagement, 'resultJsonFactory' => $this->resultJsonFactory, 'dataObjectHelper' => $this->dataObjectHelper]);
 }
 /**
  * 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->customerInterfaceFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->customerDataMock));
     $this->customerDataMock->expects($this->once())->method('setGroupId')->with($this->equalTo($this->customerGroupId))->will($this->returnSelf());
     $this->assertEquals($this->customerDataMock, $this->currentCustomer->getCustomer());
 }
Esempio n. 3
0
 public function testPrepareQuoteForNewCustomer()
 {
     $customerAddressMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
     $this->addressMock->expects($this->any())->method('exportCustomerAddress')->willReturn($customerAddressMock);
     $this->addressMock->expects($this->any())->method('getData')->willReturn([]);
     $this->addressFactoryMock->expects($this->any())->method('create')->willReturn($this->addressMock);
     $this->quoteMock->expects($this->any())->method('isVirtual')->willReturn(false);
     $this->quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($this->addressMock);
     $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressMock);
     $customerDataMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerFactoryMock->expects($this->once())->method('create')->willReturn($customerDataMock);
     $this->copyObjectMock->expects($this->any())->method('getDataFromFieldset')->willReturn([]);
     $this->dataObjectHelper->expects($this->any())->method('populateWithArray')->willReturnSelf();
     $this->assertInstanceOf('Magento\\Quote\\Model\\Quote', $this->quote->prepareQuoteForNewCustomer($this->quoteMock));
 }
Esempio n. 4
0
 public function testSetAccountData()
 {
     $taxClassId = 1;
     $attributes = [['email', '*****@*****.**'], ['group_id', 1]];
     $attributeMocks = [];
     foreach ($attributes as $attribute) {
         $attributeMock = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface', [], [], '', false);
         $attributeMock->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attribute[0]));
         $attributeMocks[] = $attributeMock;
     }
     $customerGroupMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\GroupInterface', [], '', false, true, true, ['getTaxClassId']);
     $customerGroupMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue($taxClassId));
     $customerFormMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false);
     $customerFormMock->expects($this->any())->method('getAttributes')->will($this->returnValue($attributeMocks));
     $customerFormMock->expects($this->any())->method('extractData')->will($this->returnValue([]));
     $customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue([]));
     $customerFormMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->getMock('Magento\\Framework\\App\\RequestInterface')));
     $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->customerMapper->expects($this->atLeastOnce())->method('toFlatArray')->willReturn(['email' => '*****@*****.**', 'group_id' => 1, 'gender' => 1]);
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock));
     $quoteMock->expects($this->once())->method('addData')->with(['customer_email' => $attributes[0][1], 'customer_group_id' => $attributes[1][1], 'customer_tax_class_id' => $taxClassId]);
     $this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($customerMock, ['email' => '*****@*****.**', 'group_id' => 1, 'gender' => 1], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerFormMock));
     $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
     $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerMock));
     $this->groupRepositoryMock->expects($this->once())->method('getById')->will($this->returnValue($customerGroupMock));
     $this->adminOrderCreate->setAccountData([]);
 }
Esempio n. 5
0
 /**
  * @dataProvider saveBillingDataProvider
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function testSaveBilling($data, $customerAddressId, $quoteCustomerId, $addressCustomerId, $isAddress, $validateDataResult, $validateResult, $checkoutMethod, $customerPassword, $confirmPassword, $validationResultMessages, $isEmailAvailable, $isVirtual, $getStepDataResult, $expected)
 {
     $useForShipping = (int) $data['use_for_shipping'];
     $passwordHash = 'password hash';
     $this->requestMock->expects($this->any())->method('isAjax')->will($this->returnValue(false));
     $customerValidationResultMock = $this->getMock('Magento\\Customer\\Api\\Data\\ValidationResultsInterface', [], [], '', false);
     $customerValidationResultMock->expects($this->any())->method('isValid')->will($this->returnValue(empty($validationResultMessages)));
     $customerValidationResultMock->expects($this->any())->method('getMessages')->will($this->returnValue($validationResultMessages));
     $this->accountManagementMock->expects($this->any())->method('getPasswordHash')->with($customerPassword)->will($this->returnValue($passwordHash));
     $this->accountManagementMock->expects($this->any())->method('validate')->will($this->returnValue($customerValidationResultMock));
     $this->accountManagementMock->expects($this->any())->method('isEmailAvailable')->will($this->returnValue($isEmailAvailable));
     /** @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject $quoteMock */
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['getData', 'getCustomerId', '__wakeup', 'getBillingAddress', 'setPasswordHash', 'getCheckoutMethod', 'isVirtual', 'getShippingAddress', 'getCustomerData', 'collectTotals', 'save', 'getCustomer'], [], '', false);
     $customerMock = $this->getMockForAbstractClass('Magento\\Framework\\Api\\AbstractExtensibleObject', [], '', false, true, true, ['__toArray']);
     $shippingAddressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['setSameAsBilling', 'save', 'collectTotals', 'addData', 'setShippingMethod', 'setCollectShippingRates', '__wakeup'], [], '', false);
     $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock));
     $shippingAddressMock->expects($useForShipping ? $this->any() : $this->once())->method('setSameAsBilling')->with($useForShipping)->will($this->returnSelf());
     $expects = !$useForShipping || $checkoutMethod != Onepage::METHOD_REGISTER ? $this->once() : $this->never();
     $shippingAddressMock->expects($expects)->method('save');
     $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('addData')->will($this->returnSelf());
     $shippingAddressMock->expects($this->any())->method('setSaveInAddressBook')->will($this->returnSelf());
     $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('setShippingMethod')->will($this->returnSelf());
     $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('setCollectShippingRates')->will($this->returnSelf());
     $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())->method('collectTotals');
     $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));
     $addressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['setSaveInAddressBook', 'getData', 'setEmail', '__wakeup', 'importCustomerAddressData', 'validate', 'save'], [], '', 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));
     $this->quoteRepositoryMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->once() : $this->never())->method('save')->with($quoteMock);
     $addressMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once())->method('save');
     $quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock));
     $data1 = [];
     $extensibleDataObjectConverterMock = $this->getMock('Magento\\Framework\\Api\\ExtensibleDataObjectConverter', ['toFlatArray'], [], '', false);
     $extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->with($customerMock)->will($this->returnValue($data1));
     $formMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false);
     $formMock->expects($this->atLeastOnce())->method('validateData')->will($this->returnValue($validateDataResult));
     $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($formMock));
     $formMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->requestMock));
     $formMock->expects($this->any())->method('extractData')->with($this->requestMock)->will($this->returnValue([]));
     $formMock->expects($this->any())->method('validateData')->with([])->will($this->returnValue(false));
     $customerDataMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->customerDataFactoryMock->expects($this->any())->method('create')->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($useForShipping ? true : $getStepDataResult));
     $this->checkoutSessionMock->expects($this->any())->method('setStepData')->will($this->returnSelf());
     $customerAddressMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false);
     $customerAddressMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($addressCustomerId));
     $this->addressRepositoryMock->expects($this->any())->method('getById')->will($isAddress ? $this->returnValue($customerAddressMock) : $this->throwException(new \Exception()));
     $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));
 }
 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));
 }
Esempio n. 7
0
 public function testGetCustomerWithSession()
 {
     $customerId = 1;
     $data = $customerId . ',2';
     $this->urlDecoderMock->expects($this->any())->method('decode')->willReturnArgument(0);
     $this->requestMock->expects($this->once())->method('getParam')->with('data', null)->willReturn($data);
     $this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
     $this->customerFactoryMock->expects($this->never())->method('create');
     $this->assertEquals($customer, $this->model->getCustomer());
     // Check that customer is cached
     $this->assertSame($customer, $this->model->getCustomer());
 }
Esempio n. 8
0
 /**
  * @param $customerData
  * @param $isSingleStoreMode
  * @param $canModifyCustomer
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 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->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     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->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerObject));
     $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray');
     $this->options->expects($this->any())->method('getNamePrefixOptions')->will($this->returnValue(['Pref1', 'Pref2']));
     $this->options->expects($this->any())->method('getNameSuffixOptions')->will($this->returnValue(['Suf1', 'Suf2']));
     $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($accountForm));
     $this->extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->will($this->returnValue($customerData));
     $this->customerFormFactoryMock->expects($this->any())->method('create')->with('customer', 'adminhtml_customer', $this->extensibleDataObjectConverterMock->toFlatArray($customerObject, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'))->will($this->returnValue($customerForm));
     $this->accountManagementMock->expects($this->any())->method('isReadOnly')->withAnyParameters()->will($this->returnValue(!$canModifyCustomer));
     $this->accountManagementMock->expects($this->any())->method('getConfirmationStatus')->withAnyParameters()->will($this->returnValue(AccountManagementInterface::ACCOUNT_CONFIRMED));
 }
Esempio n. 9
0
 /**
  * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithNewCustomerAndException()
 {
     $subscription = 'false';
     $postValue = ['customer' => ['coolness' => false, 'disable_auto_group_change' => 'false'], 'subscription' => $subscription];
     $filteredData = ['coolness' => false, 'disable_auto_group_change' => 'false'];
     /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock();
     $attributeMock->expects($this->once())->method('getAttributeCode')->willReturn('coolness');
     $attributeMock->expects($this->once())->method('getFrontendInput')->willReturn('int');
     $attributes = [$attributeMock];
     $this->requestMock->expects($this->exactly(2))->method('getPostValue')->willReturn($postValue);
     $this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['customer', null, $postValue['customer']], ['address', null, null]]);
     /** @var \Magento\Customer\Model\Metadata\Form|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $formMock = $this->getMockBuilder('Magento\\Customer\\Model\\Metadata\\Form')->disableOriginalConstructor()->getMock();
     $this->formFactoryMock->expects($this->once())->method('create')->with(\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'adminhtml_customer', [], false, \Magento\Customer\Model\Metadata\Form::DONT_IGNORE_INVISIBLE)->willReturn($formMock);
     $formMock->expects($this->once())->method('extractData')->with($this->requestMock, 'customer')->willReturn($filteredData);
     /** @var \Magento\Framework\DataObject|\PHPUnit_Framework_MockObject_MockObject $objectMock */
     $objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $this->objectFactoryMock->expects($this->once())->method('create')->with(['data' => $postValue])->willReturn($objectMock);
     $objectMock->expects($this->once())->method('getData')->with('customer')->willReturn($postValue['customer']);
     $formMock->expects($this->once())->method('getAttributes')->willReturn($attributes);
     /** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customerMock */
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerDataFactoryMock->expects($this->once())->method('create')->willReturn($customerMock);
     $exception = new \Exception(__('Exception'));
     $this->managementMock->expects($this->once())->method('createAccount')->with($customerMock, null, '')->willThrowException($exception);
     $customerMock->expects($this->never())->method('getId');
     $this->authorizationMock->expects($this->never())->method('isAllowed');
     $this->subscriberFactoryMock->expects($this->never())->method('create');
     $this->sessionMock->expects($this->never())->method('unsCustomerData');
     $this->registryMock->expects($this->never())->method('register');
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Something went wrong while saving the customer.'));
     $this->sessionMock->expects($this->once())->method('setCustomerData')->with($postValue);
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->redirectFactoryMock->expects($this->once())->method('create')->with([])->willReturn($redirectMock);
     $redirectMock->expects($this->once())->method('setPath')->with('customer/*/new', ['_current' => true])->willReturn(true);
     $this->assertEquals($redirectMock, $this->model->execute());
 }
Esempio n. 10
0
 /**
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function testSetCustomerAddressData()
 {
     $customerId = 1;
     $addressMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false, true, true, ['getId']);
     $addressMock->expects($this->any())->method('getId')->will($this->returnValue(null));
     $addresses = [$addressMock];
     $customerMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false);
     $customerResultMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false);
     $requestMock = $this->getMock('\\Magento\\Framework\\DataObject');
     $this->extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->will($this->returnValue(['customer_id' => $customerId]));
     $this->customerRepositoryMock->expects($this->any())->method('getById')->will($this->returnValue($customerMock));
     $this->customerDataFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerMock));
     $this->customerRepositoryMock->expects($this->once())->method('save')->will($this->returnValue($customerMock));
     $customerMock->expects($this->any())->method('getAddresses')->will($this->returnValue($addresses));
     $this->objectFactoryMock->expects($this->once())->method('create')->with($this->equalTo(['customer_id' => $customerId]))->will($this->returnValue($requestMock));
     $result = $this->quote->setCustomerAddressData([$addressMock]);
     $this->assertInstanceOf('Magento\\Quote\\Model\\Quote', $result);
     $this->assertEquals($customerResultMock, $this->quote->getCustomer());
 }