@@ -576,6 +576,62 @@ public function testSubmit()
576
576
$ this ->assertEquals ($ order , $ this ->model ->submit ($ quote , $ orderData ));
577
577
}
578
578
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
+ */
579
635
protected function getQuote (
580
636
$ isGuest ,
581
637
$ isVirtual ,
@@ -649,14 +705,25 @@ protected function getQuote(
649
705
return $ quote ;
650
706
}
651
707
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
+ */
652
718
protected function prepareOrderFactory (
653
719
\Magento \Sales \Api \Data \OrderInterface $ baseOrder ,
654
720
\Magento \Sales \Api \Data \OrderAddressInterface $ billingAddress ,
655
721
array $ addresses ,
656
722
array $ payments ,
657
723
array $ items ,
658
724
$ quoteId ,
659
- \Magento \Sales \Api \Data \OrderAddressInterface $ shippingAddress = null
725
+ \Magento \Sales \Api \Data \OrderAddressInterface $ shippingAddress = null ,
726
+ $ customerId = null
660
727
) {
661
728
$ order = $ this ->getMock (
662
729
'Magento\Sales\Model\Order ' ,
@@ -677,6 +744,11 @@ protected function prepareOrderFactory(
677
744
if ($ shippingAddress ) {
678
745
$ order ->expects ($ this ->once ())->method ('setShippingAddress ' )->with ($ shippingAddress );
679
746
}
747
+ if ($ customerId ) {
748
+ $ this ->orderFactory ->expects ($ this ->once ())
749
+ ->method ('setCustomerId ' )
750
+ ->with ($ customerId );
751
+ }
680
752
$ order ->expects ($ this ->any ())->method ('getAddressesCollection ' );
681
753
$ order ->expects ($ this ->any ())->method ('getAddresses ' );
682
754
$ order ->expects ($ this ->any ())->method ('getBillingAddress ' )->willReturn (false );
0 commit comments