Skip to content

Commit f2b763e

Browse files
Stanislav IdolovSerhiy Shkolyarenko
authored andcommitted
MAGETWO-33580: There is no ability to place order for guest customer using API service
- unit test added
1 parent 3929bf2 commit f2b763e

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

dev/tests/unit/testsuite/Magento/Quote/Model/QuoteManagementTest.php

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,62 @@ public function testSubmit()
576576
$this->assertEquals($order, $this->model->submit($quote, $orderData));
577577
}
578578

579+
/**
580+
* //Last method throws exception because class method 'submit()' already covered.
581+
*
582+
* @expectedException \Exception
583+
* @expectedExceptionMessage Quote prepared for guest customer.
584+
*/
585+
public function testPlaceOrderIfCustomerIsQuest()
586+
{
587+
$cartId = 100;
588+
$email = 'email@mail.com';
589+
$quoteMock = $this->getMock(
590+
'Magento\Quote\Model\Quote',
591+
[
592+
'getCheckoutMethod',
593+
'setCustomerId',
594+
'setCustomerEmail',
595+
'getBillingAddress',
596+
'setCustomerIsGuest',
597+
'setCustomerGroupId'
598+
],
599+
[],
600+
'',
601+
false
602+
);
603+
$this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->willReturn($quoteMock);
604+
605+
$quoteMock->expects($this->once())
606+
->method('getCheckoutMethod')
607+
->willReturn(\Magento\Checkout\Model\Type\Onepage::METHOD_GUEST);
608+
$quoteMock->expects($this->once())->method('setCustomerId')->with(null)->willReturnSelf();
609+
$quoteMock->expects($this->once())->method('setCustomerEmail')->with($email)->willReturnSelf();
610+
611+
$addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', ['getEmail'], [], '', false);
612+
$addressMock->expects($this->once())->method('getEmail')->willReturn($email);
613+
$quoteMock->expects($this->once())->method('getBillingAddress')->with()->willReturn($addressMock);
614+
615+
$quoteMock->expects($this->once())->method('setCustomerIsGuest')->with(true)->willReturnSelf();
616+
$quoteMock->expects($this->once())
617+
->method('setCustomerGroupId')
618+
->with(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID)
619+
->willThrowException(new \Exception('Quote prepared for guest customer.'));
620+
621+
$this->model->placeOrder($cartId);
622+
}
623+
624+
/**
625+
* @param $isGuest
626+
* @param $isVirtual
627+
* @param Quote\Address $billingAddress
628+
* @param Quote\Payment $payment
629+
* @param $customerId
630+
* @param $id
631+
* @param array $quoteItems
632+
* @param Quote\Address $shippingAddress
633+
* @return \PHPUnit_Framework_MockObject_MockObject
634+
*/
579635
protected function getQuote(
580636
$isGuest,
581637
$isVirtual,
@@ -649,14 +705,25 @@ protected function getQuote(
649705
return $quote;
650706
}
651707

708+
/**
709+
* @param \Magento\Sales\Api\Data\OrderInterface $baseOrder
710+
* @param \Magento\Sales\Api\Data\OrderAddressInterface $billingAddress
711+
* @param array $addresses
712+
* @param array $payments
713+
* @param array $items
714+
* @param $quoteId
715+
* @param \Magento\Sales\Api\Data\OrderAddressInterface $shippingAddress
716+
* @return \PHPUnit_Framework_MockObject_MockObject
717+
*/
652718
protected function prepareOrderFactory(
653719
\Magento\Sales\Api\Data\OrderInterface $baseOrder,
654720
\Magento\Sales\Api\Data\OrderAddressInterface $billingAddress,
655721
array $addresses,
656722
array $payments,
657723
array $items,
658724
$quoteId,
659-
\Magento\Sales\Api\Data\OrderAddressInterface $shippingAddress = null
725+
\Magento\Sales\Api\Data\OrderAddressInterface $shippingAddress = null,
726+
$customerId = null
660727
) {
661728
$order = $this->getMock(
662729
'Magento\Sales\Model\Order',
@@ -677,6 +744,11 @@ protected function prepareOrderFactory(
677744
if ($shippingAddress) {
678745
$order->expects($this->once())->method('setShippingAddress')->with($shippingAddress);
679746
}
747+
if ($customerId) {
748+
$this->orderFactory->expects($this->once())
749+
->method('setCustomerId')
750+
->with($customerId);
751+
}
680752
$order->expects($this->any())->method('getAddressesCollection');
681753
$order->expects($this->any())->method('getAddresses');
682754
$order->expects($this->any())->method('getBillingAddress')->willReturn(false);

0 commit comments

Comments
 (0)