@@ -180,6 +180,7 @@ public function testSavePaymentInformationWithoutBillingAddress()
180180 $ paymentMock = $ this ->getMockForAbstractClass (PaymentInterface::class);
181181 $ billingAddressMock = $ this ->getMockForAbstractClass (AddressInterface::class);
182182 $ quoteMock = $ this ->createMock (Quote::class);
183+ $ quoteMock ->expects ($ this ->any ())->method ('getItemsQty ' )->willReturn (1 );
183184
184185 $ billingAddressMock ->expects ($ this ->once ())->method ('setEmail ' )->with ($ email )->willReturnSelf ();
185186
@@ -210,6 +211,7 @@ public function testSavePaymentInformationAndPlaceOrderWithLocalizedException()
210211
211212 $ quoteMock = $ this ->createMock (Quote::class);
212213 $ quoteMock ->method ('getBillingAddress ' )->willReturn ($ billingAddressMock );
214+ $ quoteMock ->expects ($ this ->any ())->method ('getItemsQty ' )->willReturn (1 );
213215 $ this ->cartRepositoryMock ->method ('getActive ' )->with ($ cartId )->willReturn ($ quoteMock );
214216
215217 $ quoteIdMask = $ this ->getMockBuilder (QuoteIdMask::class)
@@ -231,6 +233,35 @@ public function testSavePaymentInformationAndPlaceOrderWithLocalizedException()
231233 $ this ->model ->savePaymentInformationAndPlaceOrder ($ cartId , $ email , $ paymentMock , $ billingAddressMock );
232234 }
233235
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+ $ email = 'email@magento.com ' ;
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+
234265 /**
235266 * @param int $cartId
236267 * @param MockObject $billingAddressMock
@@ -266,6 +297,9 @@ private function getMockForAssignBillingAddress(
266297 $ this ->cartRepositoryMock ->method ('getActive ' )
267298 ->with ($ cartId )
268299 ->willReturn ($ quote );
300+ $ quote ->expects ($ this ->any ())
301+ ->method ('getItemsQty ' )
302+ ->willReturn (1 );
269303 $ quote ->expects ($ this ->any ())
270304 ->method ('getBillingAddress ' )
271305 ->willReturn ($ quoteBillingAddress );
0 commit comments