Skip to content

Commit c7c47e7

Browse files
author
Kostiantyn Poida
committed
Merge remote-tracking branch 'remotes/origin/MAGETWO-31168' into develop
2 parents b2528d6 + 85b4474 commit c7c47e7

File tree

3 files changed

+77
-24
lines changed

3 files changed

+77
-24
lines changed

app/code/Magento/Checkout/Model/Type/Onepage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public function saveBilling($data, $customerAddressId)
430430
$address = $this->getQuote()->getBillingAddress();
431431
}
432432

433-
if (!$this->getQuote()->getCustomerId() && self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod()) {
433+
if (!$this->getQuote()->getCustomerId() && $this->isCheckoutMethodRegister()) {
434434
if ($this->_customerEmailExists($address->getEmail(), $this->_storeManager->getWebsite()->getId())) {
435435
return [
436436
'error' => 1,

app/code/Magento/Sales/Model/Service/Quote.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ protected function prepareCustomerData(\Magento\Sales\Model\Quote $quote)
184184
$this->customerBuilder->populate($customer)->create(),
185185
$quote->getPasswordHash()
186186
);
187-
} else {
188-
$this->customerRepository->save($customer);
189187
}
190188

191189
if (!$quote->getBillingAddress()->getId() && $customer->getDefaultBilling()) {

dev/tests/unit/testsuite/Magento/Checkout/Model/Type/OnepageTest.php

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class OnepageTest extends \PHPUnit_Framework_TestCase
4646
/** @var \PHPUnit_Framework_MockObject_MockObject */
4747
protected $addressFactoryMock;
4848

49-
/** @var \PHPUnit_Framework_MockObject_MockObject */
50-
protected $formFactoryMock;
49+
/** @var \Magento\Customer\Model\FormFactory|\PHPUnit_Framework_MockObject_MockObject */
50+
protected $customerFormFactoryMock;
5151

5252
/** @var \PHPUnit_Framework_MockObject_MockObject */
5353
protected $customerFactoryMock;
@@ -65,7 +65,7 @@ class OnepageTest extends \PHPUnit_Framework_TestCase
6565
protected $messageManagerMock;
6666

6767
/** @var \Magento\Customer\Model\Metadata\FormFactory|\PHPUnit_Framework_MockObject_MockObject */
68-
protected $customerFormFactoryMock;
68+
protected $formFactoryMock;
6969

7070
/** @var \Magento\Customer\Api\Data\CustomerDataBuilder|\PHPUnit_Framework_MockObject_MockObject */
7171
protected $customerBuilderMock;
@@ -134,15 +134,15 @@ protected function setUp()
134134
['isAjax', 'getModuleName', 'setModuleName', 'getActionName', 'setActionName', 'getParam', 'getCookie']
135135
);
136136
$this->addressFactoryMock = $this->getMock('Magento\Customer\Model\AddressFactory', [], [], '', false);
137-
$this->formFactoryMock = $this->getMock('Magento\Customer\Model\FormFactory', [], [], '', false);
137+
$this->formFactoryMock = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', [], [], '', false);
138138
$this->customerFactoryMock = $this->getMock('Magento\Customer\Model\CustomerFactory', [], [], '', false);
139139
$this->quoteFactoryMock = $this->getMock('Magento\Sales\Model\Service\QuoteFactory', [], [], '', false);
140140
$this->orderFactoryMock = $this->getMock('Magento\Sales\Model\OrderFactory', ['create'], [], '', false);
141141
$this->copyMock = $this->getMock('Magento\Framework\Object\Copy', [], [], '', false);
142142
$this->messageManagerMock = $this->getMock('Magento\Framework\Message\ManagerInterface');
143143

144144
$this->customerFormFactoryMock = $this->getMock(
145-
'Magento\Customer\Model\Metadata\FormFactory',
145+
'Magento\Customer\Model\FormFactory',
146146
['create'],
147147
[],
148148
'',
@@ -212,13 +212,13 @@ protected function setUp()
212212
'storeManager' => $this->storeManagerMock,
213213
'request' => $this->requestMock,
214214
'customrAddrFactory' => $this->addressFactoryMock,
215-
'customerFormFactory' => $this->formFactoryMock,
215+
'customerFormFactory' => $this->customerFormFactoryMock,
216216
'customerFactory' => $this->customerFactoryMock,
217217
'serviceQuoteFactory' => $this->quoteFactoryMock,
218218
'orderFactory' => $this->orderFactoryMock,
219219
'objectCopyService' => $this->copyMock,
220220
'messageManager' => $this->messageManagerMock,
221-
'formFactory' => $this->customerFormFactoryMock,
221+
'formFactory' => $this->formFactoryMock,
222222
'customerBuilder' => $this->customerBuilderMock,
223223
'addressBuilder' => $this->addressBuilderMock,
224224
'mathRandom' => $this->randomMock,
@@ -396,6 +396,8 @@ public function testSaveBilling(
396396
$getStepDataResult,
397397
$expected
398398
) {
399+
$useForShipping = (int)$data['use_for_shipping'];
400+
399401
$passwordHash = 'password hash';
400402
$this->requestMock->expects($this->any())->method('isAjax')->will($this->returnValue(false));
401403
$customerValidationResultMock = $this->getMock(
@@ -454,17 +456,52 @@ public function testSaveBilling(
454456
);
455457
$shippingAddressMock = $this->getMock(
456458
'Magento\Sales\Model\Quote\Address',
457-
['setSameAsBilling', 'save', '__wakeup', 'unserialize'],
459+
[
460+
'setSameAsBilling',
461+
'save',
462+
'collectTotals',
463+
'addData',
464+
'setShippingMethod',
465+
'setCollectShippingRates'
466+
],
458467
[],
459468
'',
460469
false
461470
);
462-
$shippingAddressMock->expects($this->any())->method('setSameAsBilling')->with((int)$data['use_for_shipping']);
463-
$shippingAddressMock->expects($this->once())->method('save');
471+
$quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock));
472+
473+
$shippingAddressMock->expects($useForShipping ? $this->any() : $this->once())
474+
->method('setSameAsBilling')
475+
->with($useForShipping)
476+
->will($this->returnSelf());
477+
478+
$expects = (!$useForShipping || ($checkoutMethod != Onepage::METHOD_REGISTER)) ? $this->once() : $this->never();
479+
$shippingAddressMock->expects($expects)
480+
->method('save');
481+
482+
$shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())
483+
->method('addData')
484+
->will($this->returnSelf());
485+
486+
$shippingAddressMock->expects($this->any())
487+
->method('setSaveInAddressBook')
488+
->will($this->returnSelf());
489+
490+
$shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())
491+
->method('setShippingMethod')
492+
->will($this->returnSelf());
493+
494+
$shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())
495+
->method('setCollectShippingRates')
496+
->will($this->returnSelf());
497+
498+
$shippingAddressMock->expects($useForShipping ? $this->once() : $this->never())
499+
->method('collectTotals');
500+
464501
$quoteMock->expects($this->any())->method('setPasswordHash')->with($passwordHash);
465502
$quoteMock->expects($this->any())->method('getCheckoutMethod')->will($this->returnValue($checkoutMethod));
466503
$quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue($isVirtual));
467-
$quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock));
504+
468505
$addressMock = $this->getMock(
469506
'Magento\Sales\Model\Quote\Address',
470507
[
@@ -486,7 +523,15 @@ public function testSaveBilling(
486523

487524
$quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock));
488525
$quoteMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($quoteCustomerId));
489-
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock);
526+
527+
$this->quoteRepositoryMock
528+
->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->once() : $this->never())
529+
->method('save')
530+
->with($quoteMock);
531+
532+
$addressMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once())
533+
->method('save');
534+
490535
$quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock));
491536
$data1 = [];
492537
$extensibleDataObjectConverterMock = $this->getMock(
@@ -504,7 +549,7 @@ public function testSaveBilling(
504549
$formMock = $this->getMock('Magento\Customer\Model\Metadata\Form', [], [], '', false);
505550
$formMock->expects($this->atLeastOnce())->method('validateData')->will($this->returnValue($validateDataResult));
506551

507-
$this->customerFormFactoryMock->expects($this->any())->method('create')->will($this->returnValue($formMock));
552+
$this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($formMock));
508553
$formMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->requestMock));
509554
$formMock->expects($this->any())
510555
->method('extractData')
@@ -525,7 +570,7 @@ public function testSaveBilling(
525570
$this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
526571
$this->checkoutSessionMock->expects($this->any())
527572
->method('getStepData')
528-
->will($this->returnValue((int)$data['use_for_shipping'] === 1 ? true : $getStepDataResult));
573+
->will($this->returnValue($useForShipping ? true : $getStepDataResult));
529574
$this->checkoutSessionMock->expects($this->any())->method('setStepData')->will($this->returnSelf());
530575
$customerAddressMock = $this->getMockForAbstractClass(
531576
'Magento\Customer\Api\Data\AddressInterface',
@@ -540,13 +585,6 @@ public function testSaveBilling(
540585
->method('getById')
541586
->will($isAddress ? $this->returnValue($customerAddressMock) : $this->throwException(new \Exception()));
542587

543-
$this->customerBuilderMock
544-
->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once())
545-
->method('populate');
546-
$this->customerBuilderMock
547-
->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once())
548-
->method('setGroupId');
549-
550588
$websiteMock = $this->getMock('Magento\Store\Model\Website', [], [], '', false);
551589
$this->storeManagerMock->expects($this->any())->method('getWebsite')->will($this->returnValue($websiteMock));
552590
$this->assertEquals($expected, $this->onepage->saveBilling($data, $customerAddressId));
@@ -571,6 +609,23 @@ public function saveBillingDataProvider()
571609
false, // $isVirtual
572610
false, // $getStepDataResult
573611
[], // $expected
612+
],
613+
[
614+
['use_for_shipping' => 1], // $data
615+
1, // $customerAddressId
616+
1, // $quoteCustomerId
617+
1, // $addressCustomerId
618+
true, //$isAddress
619+
true, // $validateDataResult
620+
true, // $validateResult
621+
Onepage::METHOD_CUSTOMER, // $checkoutMethod
622+
'password', // $customerPassword
623+
'password', // $confirmPassword
624+
[], // $validationResultMessages
625+
true, // $isEmailAvailable
626+
false, // $isVirtual
627+
false, // $getStepDataResult
628+
[], // $expected
574629
]
575630
];
576631
}

0 commit comments

Comments
 (0)