@@ -200,7 +200,8 @@ protected function setUp()
200
200
'getBillingAddress ' ,
201
201
'setCustomerIsGuest ' ,
202
202
'setCustomerGroupId ' ,
203
- 'assignCustomer '
203
+ 'assignCustomer ' ,
204
+ 'getPayment ' ,
204
205
],
205
206
[],
206
207
'' ,
@@ -724,6 +725,42 @@ public function testPlaceOrderIfCustomerIsGuest()
724
725
$ this ->assertEquals ($ orderId , $ service ->placeOrder ($ cartId ));
725
726
}
726
727
728
+ /**
729
+ * @expectedException \Magento\Framework\Exception\CouldNotSaveException
730
+ */
731
+ public function testPlaceOrderIfAgreementsIsNotValid ()
732
+ {
733
+ $ this ->agreementsValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->willReturn (false );
734
+
735
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\QuoteManagement $service */
736
+ $ service = $ this ->getMock (
737
+ '\Magento\Quote\Model\QuoteManagement ' ,
738
+ ['submit ' ],
739
+ [
740
+ 'eventManager ' => $ this ->eventManager ,
741
+ 'quoteValidator ' => $ this ->quoteValidator ,
742
+ 'orderFactory ' => $ this ->orderFactory ,
743
+ 'orderManagement ' => $ this ->orderManagement ,
744
+ 'customerManagement ' => $ this ->customerManagement ,
745
+ 'quoteAddressToOrder ' => $ this ->quoteAddressToOrder ,
746
+ 'quoteAddressToOrderAddress ' => $ this ->quoteAddressToOrderAddress ,
747
+ 'quoteItemToOrderItem ' => $ this ->quoteItemToOrderItem ,
748
+ 'quotePaymentToOrderPayment ' => $ this ->quotePaymentToOrderPayment ,
749
+ 'userContext ' => $ this ->userContextMock ,
750
+ 'quoteRepository ' => $ this ->quoteRepositoryMock ,
751
+ 'customerRepository ' => $ this ->customerRepositoryMock ,
752
+ 'customerModelFactory ' => $ this ->customerFactoryMock ,
753
+ 'dataObjectHelper ' => $ this ->dataObjectHelperMock ,
754
+ 'storeManager ' => $ this ->storeManagerMock ,
755
+ 'checkoutSession ' => $ this ->checkoutSessionMock ,
756
+ 'customerSession ' => $ this ->customerSessionMock ,
757
+ 'accountManagement ' => $ this ->accountManagementMock ,
758
+ 'agreementsValidator ' => $ this ->agreementsValidatorMock ,
759
+ ]
760
+ );
761
+ $ service ->placeOrder (45 );
762
+ }
763
+
727
764
public function testPlaceOrder ()
728
765
{
729
766
$ cartId = 323 ;
@@ -769,6 +806,15 @@ public function testPlaceOrder()
769
806
->with ($ cartId )
770
807
->willReturn ($ this ->quoteMock );
771
808
809
+ $ quotePayment = $ this ->getMock ('Magento\Quote\Model\Quote\Payment ' , [], [], '' , false );
810
+ $ quotePayment ->expects ($ this ->once ())
811
+ ->method ('setQuote ' );
812
+ $ quotePayment ->expects ($ this ->once ())
813
+ ->method ('importData ' );
814
+ $ this ->quoteMock ->expects ($ this ->atLeastOnce ())
815
+ ->method ('getPayment ' )
816
+ ->willReturn ($ quotePayment );
817
+
772
818
$ this ->quoteMock ->expects ($ this ->once ())
773
819
->method ('getCheckoutMethod ' )
774
820
->willReturn (\Magento \Checkout \Model \Type \Onepage::METHOD_CUSTOMER );
@@ -787,7 +833,12 @@ public function testPlaceOrder()
787
833
$ this ->checkoutSessionMock ->expects ($ this ->once ())->method ('setLastOrderId ' )->with ($ orderId );
788
834
$ this ->checkoutSessionMock ->expects ($ this ->once ())->method ('setLastRealOrderId ' )->with ($ orderIncrementId );
789
835
$ this ->agreementsValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->willReturn (true );
790
- $ this ->assertEquals ($ orderId , $ service ->placeOrder ($ cartId ));
836
+
837
+ $ paymentMethod = $ this ->getMock ('Magento\Quote\Model\Quote\Payment ' , ['setChecks ' , 'getData ' ], [], '' , false );
838
+ $ paymentMethod ->expects ($ this ->once ())->method ('setChecks ' );
839
+ $ paymentMethod ->expects ($ this ->once ())->method ('getData ' )->willReturn (['additional_data ' => []]);
840
+
841
+ $ this ->assertEquals ($ orderId , $ service ->placeOrder ($ cartId , null , $ paymentMethod ));
791
842
}
792
843
793
844
/**
0 commit comments