@@ -121,6 +121,11 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase
121
121
*/
122
122
protected $ quoteMock ;
123
123
124
+ /**
125
+ * @var \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
126
+ */
127
+ protected $ minimumAmountErrorMessage ;
128
+
124
129
/**
125
130
* @var \PHPUnit_Framework_MockObject_MockObject
126
131
*/
@@ -218,6 +223,8 @@ protected function setUp()
218
223
'setCustomerGroupId ' ,
219
224
'assignCustomer ' ,
220
225
'getPayment ' ,
226
+ 'getIsMultiShipping ' ,
227
+ 'validateMinimumAmount '
221
228
],
222
229
[],
223
230
'' ,
@@ -249,6 +256,14 @@ protected function setUp()
249
256
false
250
257
);
251
258
259
+ $ this ->minimumAmountErrorMessage = $ this ->getMock (
260
+ \Magento \Quote \Model \Quote \Validator \MinimumOrderAmount \ValidationMessage::class,
261
+ ['getMessage ' ],
262
+ [],
263
+ '' ,
264
+ false
265
+ );
266
+
252
267
$ this ->quoteFactoryMock = $ this ->getMock (\Magento \Quote \Model \QuoteFactory::class, ['create ' ], [], '' , false );
253
268
$ this ->model = $ objectManager ->getObject (
254
269
\Magento \Quote \Model \QuoteManagement::class,
@@ -272,7 +287,8 @@ protected function setUp()
272
287
'checkoutSession ' => $ this ->checkoutSessionMock ,
273
288
'customerSession ' => $ this ->customerSessionMock ,
274
289
'accountManagement ' => $ this ->accountManagementMock ,
275
- 'quoteFactory ' => $ this ->quoteFactoryMock
290
+ 'quoteFactory ' => $ this ->quoteFactoryMock ,
291
+ 'minimumAmountErrorMessage ' => $ this ->minimumAmountErrorMessage
276
292
]
277
293
);
278
294
@@ -705,6 +721,10 @@ public function testPlaceOrderIfCustomerIsGuest()
705
721
->willReturn (\Magento \Checkout \Model \Type \Onepage::METHOD_GUEST );
706
722
$ this ->quoteMock ->expects ($ this ->once ())->method ('setCustomerId ' )->with (null )->willReturnSelf ();
707
723
$ this ->quoteMock ->expects ($ this ->once ())->method ('setCustomerEmail ' )->with ($ email )->willReturnSelf ();
724
+ $ this ->quoteMock ->expects ($ this ->once ())->method ('getIsMultiShipping ' )->willReturn (false );
725
+ $ this ->quoteMock ->expects ($ this ->once ())->method ('validateMinimumAmount ' )->with (false )->willReturn (true );
726
+
727
+ $ this ->minimumAmountErrorMessage ->expects ($ this ->never ())->method ('getMessage ' );
708
728
709
729
$ addressMock = $ this ->getMock (\Magento \Quote \Model \Quote \Address::class, ['getEmail ' ], [], '' , false );
710
730
$ addressMock ->expects ($ this ->once ())->method ('getEmail ' )->willReturn ($ email );
@@ -739,7 +759,8 @@ public function testPlaceOrderIfCustomerIsGuest()
739
759
'checkoutSession ' => $ this ->checkoutSessionMock ,
740
760
'customerSession ' => $ this ->customerSessionMock ,
741
761
'accountManagement ' => $ this ->accountManagementMock ,
742
- 'quoteFactory ' => $ this ->quoteFactoryMock
762
+ 'quoteFactory ' => $ this ->quoteFactoryMock ,
763
+ 'minimumAmountErrorMessage ' => $ this ->minimumAmountErrorMessage
743
764
]
744
765
);
745
766
$ orderMock = $ this ->getMock (
@@ -797,7 +818,8 @@ public function testPlaceOrder()
797
818
'checkoutSession ' => $ this ->checkoutSessionMock ,
798
819
'customerSession ' => $ this ->customerSessionMock ,
799
820
'accountManagement ' => $ this ->accountManagementMock ,
800
- 'quoteFactory ' => $ this ->quoteFactoryMock
821
+ 'quoteFactory ' => $ this ->quoteFactoryMock ,
822
+ 'minimumAmountErrorMessage ' => $ this ->minimumAmountErrorMessage
801
823
]
802
824
);
803
825
$ orderMock = $ this ->getMock (
@@ -829,6 +851,11 @@ public function testPlaceOrder()
829
851
->method ('setCustomerIsGuest ' )
830
852
->with (true );
831
853
854
+ $ this ->quoteMock ->expects ($ this ->once ())->method ('getIsMultiShipping ' )->willReturn (false );
855
+ $ this ->quoteMock ->expects ($ this ->once ())->method ('validateMinimumAmount ' )->with (false )->willReturn (true );
856
+
857
+ $ this ->minimumAmountErrorMessage ->expects ($ this ->never ())->method ('getMessage ' );
858
+
832
859
$ service ->expects ($ this ->once ())->method ('submit ' )->willReturn ($ orderMock );
833
860
834
861
$ this ->quoteMock ->expects ($ this ->atLeastOnce ())->method ('getId ' )->willReturn ($ cartId );
@@ -856,6 +883,67 @@ public function testPlaceOrder()
856
883
$ this ->assertEquals ($ orderId , $ service ->placeOrder ($ cartId , $ paymentMethod ));
857
884
}
858
885
886
+ /**
887
+ * @expectedException \Magento\Framework\Exception\InputException
888
+ * @expectedExceptionMessage Incorrect amount
889
+ */
890
+ public function testPlaceOrderWithViolationOfMinimumAmount ()
891
+ {
892
+ $ cartId = 323 ;
893
+
894
+ $ this ->quoteMock ->expects ($ this ->once ())->method ('getIsMultiShipping ' )->willReturn (false );
895
+ $ this ->quoteMock ->expects ($ this ->once ())->method ('validateMinimumAmount ' )->with (false )->willReturn (false );
896
+
897
+ $ this ->minimumAmountErrorMessage ->expects ($ this ->once ())
898
+ ->method ('getMessage ' )
899
+ ->willReturn (__ ('Incorrect amount ' ));
900
+
901
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
902
+ ->method ('getActive ' )
903
+ ->with ($ cartId )
904
+ ->willReturn ($ this ->quoteMock );
905
+
906
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\QuoteManagement $service */
907
+ $ service = $ this ->getMock (
908
+ \Magento \Quote \Model \QuoteManagement::class,
909
+ ['submit ' ],
910
+ [
911
+ 'eventManager ' => $ this ->eventManager ,
912
+ 'quoteValidator ' => $ this ->quoteValidator ,
913
+ 'orderFactory ' => $ this ->orderFactory ,
914
+ 'orderManagement ' => $ this ->orderManagement ,
915
+ 'customerManagement ' => $ this ->customerManagement ,
916
+ 'quoteAddressToOrder ' => $ this ->quoteAddressToOrder ,
917
+ 'quoteAddressToOrderAddress ' => $ this ->quoteAddressToOrderAddress ,
918
+ 'quoteItemToOrderItem ' => $ this ->quoteItemToOrderItem ,
919
+ 'quotePaymentToOrderPayment ' => $ this ->quotePaymentToOrderPayment ,
920
+ 'userContext ' => $ this ->userContextMock ,
921
+ 'quoteRepository ' => $ this ->quoteRepositoryMock ,
922
+ 'customerRepository ' => $ this ->customerRepositoryMock ,
923
+ 'customerModelFactory ' => $ this ->customerFactoryMock ,
924
+ 'quoteAddressFactory ' => $ this ->quoteAddressFactory ,
925
+ 'dataObjectHelper ' => $ this ->dataObjectHelperMock ,
926
+ 'storeManager ' => $ this ->storeManagerMock ,
927
+ 'checkoutSession ' => $ this ->checkoutSessionMock ,
928
+ 'customerSession ' => $ this ->customerSessionMock ,
929
+ 'accountManagement ' => $ this ->accountManagementMock ,
930
+ 'quoteFactory ' => $ this ->quoteFactoryMock ,
931
+ 'minimumAmountErrorMessage ' => $ this ->minimumAmountErrorMessage
932
+ ]
933
+ );
934
+
935
+ $ service ->expects ($ this ->never ())->method ('submit ' );
936
+
937
+ $ paymentMethod = $ this ->getMock (
938
+ \Magento \Quote \Model \Quote \Payment::class,
939
+ [],
940
+ [],
941
+ '' ,
942
+ false
943
+ );
944
+ $ service ->placeOrder ($ cartId , $ paymentMethod );
945
+ }
946
+
859
947
/**
860
948
* @param $isGuest
861
949
* @param $isVirtual
0 commit comments