@@ -46,8 +46,8 @@ class OnepageTest extends \PHPUnit_Framework_TestCase
46
46
/** @var \PHPUnit_Framework_MockObject_MockObject */
47
47
protected $ addressFactoryMock ;
48
48
49
- /** @var \PHPUnit_Framework_MockObject_MockObject */
50
- protected $ formFactoryMock ;
49
+ /** @var \Magento\Customer\Model\FormFactory|\ PHPUnit_Framework_MockObject_MockObject */
50
+ protected $ customerFormFactoryMock ;
51
51
52
52
/** @var \PHPUnit_Framework_MockObject_MockObject */
53
53
protected $ customerFactoryMock ;
@@ -65,7 +65,7 @@ class OnepageTest extends \PHPUnit_Framework_TestCase
65
65
protected $ messageManagerMock ;
66
66
67
67
/** @var \Magento\Customer\Model\Metadata\FormFactory|\PHPUnit_Framework_MockObject_MockObject */
68
- protected $ customerFormFactoryMock ;
68
+ protected $ formFactoryMock ;
69
69
70
70
/** @var \Magento\Customer\Api\Data\CustomerDataBuilder|\PHPUnit_Framework_MockObject_MockObject */
71
71
protected $ customerBuilderMock ;
@@ -134,15 +134,15 @@ protected function setUp()
134
134
['isAjax ' , 'getModuleName ' , 'setModuleName ' , 'getActionName ' , 'setActionName ' , 'getParam ' , 'getCookie ' ]
135
135
);
136
136
$ 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 );
138
138
$ this ->customerFactoryMock = $ this ->getMock ('Magento\Customer\Model\CustomerFactory ' , [], [], '' , false );
139
139
$ this ->quoteFactoryMock = $ this ->getMock ('Magento\Sales\Model\Service\QuoteFactory ' , [], [], '' , false );
140
140
$ this ->orderFactoryMock = $ this ->getMock ('Magento\Sales\Model\OrderFactory ' , ['create ' ], [], '' , false );
141
141
$ this ->copyMock = $ this ->getMock ('Magento\Framework\Object\Copy ' , [], [], '' , false );
142
142
$ this ->messageManagerMock = $ this ->getMock ('Magento\Framework\Message\ManagerInterface ' );
143
143
144
144
$ this ->customerFormFactoryMock = $ this ->getMock (
145
- 'Magento\Customer\Model\Metadata\ FormFactory ' ,
145
+ 'Magento\Customer\Model\FormFactory ' ,
146
146
['create ' ],
147
147
[],
148
148
'' ,
@@ -212,13 +212,13 @@ protected function setUp()
212
212
'storeManager ' => $ this ->storeManagerMock ,
213
213
'request ' => $ this ->requestMock ,
214
214
'customrAddrFactory ' => $ this ->addressFactoryMock ,
215
- 'customerFormFactory ' => $ this ->formFactoryMock ,
215
+ 'customerFormFactory ' => $ this ->customerFormFactoryMock ,
216
216
'customerFactory ' => $ this ->customerFactoryMock ,
217
217
'serviceQuoteFactory ' => $ this ->quoteFactoryMock ,
218
218
'orderFactory ' => $ this ->orderFactoryMock ,
219
219
'objectCopyService ' => $ this ->copyMock ,
220
220
'messageManager ' => $ this ->messageManagerMock ,
221
- 'formFactory ' => $ this ->customerFormFactoryMock ,
221
+ 'formFactory ' => $ this ->formFactoryMock ,
222
222
'customerBuilder ' => $ this ->customerBuilderMock ,
223
223
'addressBuilder ' => $ this ->addressBuilderMock ,
224
224
'mathRandom ' => $ this ->randomMock ,
@@ -396,6 +396,8 @@ public function testSaveBilling(
396
396
$ getStepDataResult ,
397
397
$ expected
398
398
) {
399
+ $ useForShipping = (int )$ data ['use_for_shipping ' ];
400
+
399
401
$ passwordHash = 'password hash ' ;
400
402
$ this ->requestMock ->expects ($ this ->any ())->method ('isAjax ' )->will ($ this ->returnValue (false ));
401
403
$ customerValidationResultMock = $ this ->getMock (
@@ -454,17 +456,52 @@ public function testSaveBilling(
454
456
);
455
457
$ shippingAddressMock = $ this ->getMock (
456
458
'Magento\Sales\Model\Quote\Address ' ,
457
- ['setSameAsBilling ' , 'save ' , '__wakeup ' , 'unserialize ' ],
459
+ [
460
+ 'setSameAsBilling ' ,
461
+ 'save ' ,
462
+ 'collectTotals ' ,
463
+ 'addData ' ,
464
+ 'setShippingMethod ' ,
465
+ 'setCollectShippingRates '
466
+ ],
458
467
[],
459
468
'' ,
460
469
false
461
470
);
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
+
464
501
$ quoteMock ->expects ($ this ->any ())->method ('setPasswordHash ' )->with ($ passwordHash );
465
502
$ quoteMock ->expects ($ this ->any ())->method ('getCheckoutMethod ' )->will ($ this ->returnValue ($ checkoutMethod ));
466
503
$ quoteMock ->expects ($ this ->any ())->method ('isVirtual ' )->will ($ this ->returnValue ($ isVirtual ));
467
- $ quoteMock -> expects ( $ this -> any ())-> method ( ' getShippingAddress ' )-> will ( $ this -> returnValue ( $ shippingAddressMock ));
504
+
468
505
$ addressMock = $ this ->getMock (
469
506
'Magento\Sales\Model\Quote\Address ' ,
470
507
[
@@ -486,7 +523,15 @@ public function testSaveBilling(
486
523
487
524
$ quoteMock ->expects ($ this ->any ())->method ('getBillingAddress ' )->will ($ this ->returnValue ($ addressMock ));
488
525
$ 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
+
490
535
$ quoteMock ->expects ($ this ->any ())->method ('getCustomer ' )->will ($ this ->returnValue ($ customerMock ));
491
536
$ data1 = [];
492
537
$ extensibleDataObjectConverterMock = $ this ->getMock (
@@ -504,7 +549,7 @@ public function testSaveBilling(
504
549
$ formMock = $ this ->getMock ('Magento\Customer\Model\Metadata\Form ' , [], [], '' , false );
505
550
$ formMock ->expects ($ this ->atLeastOnce ())->method ('validateData ' )->will ($ this ->returnValue ($ validateDataResult ));
506
551
507
- $ this ->customerFormFactoryMock ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ formMock ));
552
+ $ this ->formFactoryMock ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ formMock ));
508
553
$ formMock ->expects ($ this ->any ())->method ('prepareRequest ' )->will ($ this ->returnValue ($ this ->requestMock ));
509
554
$ formMock ->expects ($ this ->any ())
510
555
->method ('extractData ' )
@@ -525,7 +570,7 @@ public function testSaveBilling(
525
570
$ this ->checkoutSessionMock ->expects ($ this ->any ())->method ('getQuote ' )->will ($ this ->returnValue ($ quoteMock ));
526
571
$ this ->checkoutSessionMock ->expects ($ this ->any ())
527
572
->method ('getStepData ' )
528
- ->will ($ this ->returnValue (( int ) $ data [ ' use_for_shipping ' ] === 1 ? true : $ getStepDataResult ));
573
+ ->will ($ this ->returnValue ($ useForShipping ? true : $ getStepDataResult ));
529
574
$ this ->checkoutSessionMock ->expects ($ this ->any ())->method ('setStepData ' )->will ($ this ->returnSelf ());
530
575
$ customerAddressMock = $ this ->getMockForAbstractClass (
531
576
'Magento\Customer\Api\Data\AddressInterface ' ,
@@ -540,13 +585,6 @@ public function testSaveBilling(
540
585
->method ('getById ' )
541
586
->will ($ isAddress ? $ this ->returnValue ($ customerAddressMock ) : $ this ->throwException (new \Exception ()));
542
587
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
-
550
588
$ websiteMock = $ this ->getMock ('Magento\Store\Model\Website ' , [], [], '' , false );
551
589
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('getWebsite ' )->will ($ this ->returnValue ($ websiteMock ));
552
590
$ this ->assertEquals ($ expected , $ this ->onepage ->saveBilling ($ data , $ customerAddressId ));
@@ -571,6 +609,23 @@ public function saveBillingDataProvider()
571
609
false , // $isVirtual
572
610
false , // $getStepDataResult
573
611
[], // $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
574
629
]
575
630
];
576
631
}
0 commit comments