@@ -180,6 +180,7 @@ public function testSavePaymentInformationWithoutBillingAddress()
180
180
$ paymentMock = $ this ->getMockForAbstractClass (PaymentInterface::class);
181
181
$ billingAddressMock = $ this ->getMockForAbstractClass (AddressInterface::class);
182
182
$ quoteMock = $ this ->createMock (Quote::class);
183
+ $ quoteMock ->expects ($ this ->any ())->method ('getItemsQty ' )->willReturn (1 );
183
184
184
185
$ billingAddressMock ->expects ($ this ->once ())->method ('setEmail ' )->with ($ email )->willReturnSelf ();
185
186
@@ -210,6 +211,7 @@ public function testSavePaymentInformationAndPlaceOrderWithLocalizedException()
210
211
211
212
$ quoteMock = $ this ->createMock (Quote::class);
212
213
$ quoteMock ->method ('getBillingAddress ' )->willReturn ($ billingAddressMock );
214
+ $ quoteMock ->expects ($ this ->any ())->method ('getItemsQty ' )->willReturn (1 );
213
215
$ this ->cartRepositoryMock ->method ('getActive ' )->with ($ cartId )->willReturn ($ quoteMock );
214
216
215
217
$ quoteIdMask = $ this ->getMockBuilder (QuoteIdMask::class)
@@ -231,6 +233,35 @@ public function testSavePaymentInformationAndPlaceOrderWithLocalizedException()
231
233
$ this ->model ->savePaymentInformationAndPlaceOrder ($ cartId , $ email , $ paymentMock , $ billingAddressMock );
232
234
}
233
235
236
+ public function testSavePaymentInformationAndPlaceOrderWithDisabledProduct ()
237
+ {
238
+ $ this ->expectException ('Magento\Framework\Exception\CouldNotSaveException ' );
239
+ $ this ->expectExceptionMessage ('Some of the products are disabled. ' );
240
+ $ cartId = 100 ;
241
+
242
+ $ paymentMock = $ this ->getMockForAbstractClass (PaymentInterface::class);
243
+ $ billingAddressMock = $ this ->getMockForAbstractClass (AddressInterface::class);
244
+
245
+ $ quoteMock = $ this ->createMock (Quote::class);
246
+ $ quoteMock ->method ('getBillingAddress ' )->willReturn ($ billingAddressMock );
247
+ $ quoteMock ->expects ($ this ->any ())->method ('getItemsQty ' )->willReturn (0 );
248
+ $ this ->cartRepositoryMock ->method ('getActive ' )->with ($ cartId )->willReturn ($ quoteMock );
249
+
250
+ $ quoteIdMask = $ this ->getMockBuilder (QuoteIdMask::class)
251
+ ->addMethods (['getQuoteId ' ])
252
+ ->onlyMethods (['load ' ])
253
+ ->disableOriginalConstructor ()
254
+ ->getMock ();
255
+ $ this ->quoteIdMaskFactoryMock ->method ('create ' )->willReturn ($ quoteIdMask );
256
+ $ quoteIdMask ->method ('load ' )->with ($ cartId , 'masked_id ' )->willReturnSelf ();
257
+ $ quoteIdMask ->method ('getQuoteId ' )->willReturn ($ cartId );
258
+
259
+ $ billingAddressMock ->expects ($ this ->once ())->method ('setEmail ' )->with ($ email )->willReturnSelf ();
260
+
261
+ $ this ->paymentMethodManagementMock ->expects ($ this ->never ())->method ('set ' )->with ($ cartId , $ paymentMock );
262
+ $ this ->model ->savePaymentInformationAndPlaceOrder ($ cartId , $ email , $ paymentMock , $ billingAddressMock );
263
+ }
264
+
234
265
/**
235
266
* @param int $cartId
236
267
* @param MockObject $billingAddressMock
@@ -266,6 +297,9 @@ private function getMockForAssignBillingAddress(
266
297
$ this ->cartRepositoryMock ->method ('getActive ' )
267
298
->with ($ cartId )
268
299
->willReturn ($ quote );
300
+ $ quote ->expects ($ this ->any ())
301
+ ->method ('getItemsQty ' )
302
+ ->willReturn (1 );
269
303
$ quote ->expects ($ this ->any ())
270
304
->method ('getBillingAddress ' )
271
305
->willReturn ($ quoteBillingAddress );
0 commit comments