@@ -497,16 +497,27 @@ public function testAssignCustomerNoSuchCustomer()
497
497
$ this ->model ->assignCustomer ($ cartId , $ customerId , $ storeId );
498
498
}
499
499
500
- public function testAssignCustomer ()
500
+ public function testAssignCustomerWithActiveCart ()
501
501
{
502
502
$ cartId = 220 ;
503
503
$ customerId = 455 ;
504
504
$ storeId = 5 ;
505
505
506
+ $ this ->getPropertyValue ($ this ->model , 'quoteIdMaskFactory ' )
507
+ ->expects ($ this ->once ())
508
+ ->method ('create ' )
509
+ ->willReturn ($ this ->quoteIdMock );
510
+
506
511
$ quoteMock = $ this ->createPartialMock (
507
512
Quote::class,
508
- ['getCustomerId ' , 'setCustomer ' , 'setCustomerIsGuest ' , 'merge ' ]
513
+ ['getCustomerId ' , 'setCustomer ' , 'setCustomerIsGuest ' , 'setStoreId ' , 'setIsActive ' , 'getIsActive ' , 'merge ' ]
514
+ );
515
+
516
+ $ activeQuoteMock = $ this ->createPartialMock (
517
+ Quote::class,
518
+ ['getCustomerId ' , 'setCustomer ' , 'setCustomerIsGuest ' , 'setStoreId ' , 'setIsActive ' , 'getIsActive ' , 'merge ' ]
509
519
);
520
+
510
521
$ customerMock = $ this ->createMock (CustomerInterface::class);
511
522
512
523
$ this ->quoteRepositoryMock
@@ -538,29 +549,97 @@ public function testAssignCustomer()
538
549
->willReturn ([$ storeId , 'some store value ' ]);
539
550
540
551
$ quoteMock ->expects ($ this ->once ())->method ('getCustomerId ' )->willReturn (null );
541
-
542
552
$ this ->quoteRepositoryMock
543
553
->expects ($ this ->once ())
544
554
->method ('getForCustomer ' )
545
555
->with ($ customerId )
546
- ->willThrowException ( new \ Magento \ Framework \ Exception \ NoSuchEntityException () );
556
+ ->willReturn ( $ activeQuoteMock );
547
557
548
- $ activeQuoteMock = $ this ->createPartialMock (
558
+ $ quoteMock ->expects ($ this ->once ())->method ('merge ' )->with ($ activeQuoteMock )->willReturnSelf ();
559
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('delete ' )->with ($ activeQuoteMock );
560
+
561
+ $ quoteMock ->expects ($ this ->once ())->method ('setCustomer ' )->with ($ customerMock );
562
+ $ quoteMock ->expects ($ this ->once ())->method ('setCustomerIsGuest ' )->with (0 );
563
+ $ quoteMock ->expects ($ this ->once ())->method ('setStoreId ' )->with ($ storeId );
564
+ $ quoteMock ->expects ($ this ->once ())->method ('setIsActive ' )->with (1 );
565
+
566
+ $ this ->quoteIdMock ->expects ($ this ->once ())->method ('load ' )->with ($ cartId , 'quote_id ' )->willReturnSelf ();
567
+ $ this ->quoteIdMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (10 );
568
+ $ this ->quoteIdMock ->expects ($ this ->once ())->method ('delete ' );
569
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ quoteMock );
570
+
571
+ $ this ->model ->assignCustomer ($ cartId , $ customerId , $ storeId );
572
+ }
573
+
574
+ public function testAssignCustomer ()
575
+ {
576
+ $ cartId = 220 ;
577
+ $ customerId = 455 ;
578
+ $ storeId = 5 ;
579
+ $ activeQuoteMock = null ;
580
+
581
+ $ this ->getPropertyValue ($ this ->model , 'quoteIdMaskFactory ' )
582
+ ->expects ($ this ->once ())
583
+ ->method ('create ' )
584
+ ->willReturn ($ this ->quoteIdMock );
585
+
586
+ $ quoteMock = $ this ->createPartialMock (
549
587
Quote::class,
550
588
['getCustomerId ' , 'setCustomer ' , 'setCustomerIsGuest ' , 'setStoreId ' , 'setIsActive ' , 'getIsActive ' , 'merge ' ]
551
589
);
552
590
553
- $ this ->quoteFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ activeQuoteMock );
554
- $ activeQuoteMock ->expects ($ this ->once ())->method ('setCustomer ' )->with ($ customerMock );
555
- $ activeQuoteMock ->expects ($ this ->once ())->method ('setCustomerIsGuest ' )->with (0 );
556
- $ activeQuoteMock ->expects ($ this ->once ())->method ('setStoreId ' )->with ($ storeId );
557
- $ activeQuoteMock ->expects ($ this ->once ())->method ('setIsActive ' )->with (1 );
591
+ $ customerMock = $ this ->createMock (CustomerInterface::class);
592
+ $ this ->quoteRepositoryMock
593
+ ->expects ($ this ->once ())
594
+ ->method ('getActive ' )
595
+ ->with ($ cartId )
596
+ ->willReturn ($ quoteMock );
597
+
598
+ $ this ->customerRepositoryMock
599
+ ->expects ($ this ->once ())
600
+ ->method ('getById ' )
601
+ ->with ($ customerId )
602
+ ->willReturn ($ customerMock );
603
+
604
+ $ customerModelMock = $ this ->createPartialMock (
605
+ Customer::class,
606
+ ['load ' , 'getSharedStoreIds ' ]
607
+ );
558
608
559
- $ activeQuoteMock ->expects ($ this ->once ())->method ('getIsActive ' )->willReturn (1 );
560
- $ activeQuoteMock ->expects ($ this ->once ())->method ('merge ' )->with ($ quoteMock )->willReturnSelf ();
561
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('delete ' )->with ($ quoteMock );
609
+ $ this ->customerFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ customerModelMock );
562
610
563
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ activeQuoteMock );
611
+ $ customerModelMock
612
+ ->expects ($ this ->once ())
613
+ ->method ('load ' )
614
+ ->with ($ customerId )
615
+ ->willReturnSelf ();
616
+
617
+ $ customerModelMock
618
+ ->expects ($ this ->once ())
619
+ ->method ('getSharedStoreIds ' )
620
+ ->willReturn ([$ storeId , 'some store value ' ]);
621
+
622
+ $ quoteMock ->expects ($ this ->once ())->method ('getCustomerId ' )->willReturn (null );
623
+
624
+ $ this ->quoteRepositoryMock
625
+ ->expects ($ this ->once ())
626
+ ->method ('getForCustomer ' )
627
+ ->with ($ customerId )
628
+ ->willThrowException (new \Magento \Framework \Exception \NoSuchEntityException ());
629
+
630
+ $ this ->assertEquals (false , $ activeQuoteMock );
631
+ $ quoteMock ->expects ($ this ->never ())->method ('merge ' );
632
+ $ this ->quoteRepositoryMock ->expects ($ this ->never ())->method ('delete ' );
633
+
634
+ $ quoteMock ->expects ($ this ->once ())->method ('setCustomer ' )->with ($ customerMock );
635
+ $ quoteMock ->expects ($ this ->once ())->method ('setCustomerIsGuest ' )->with (0 );
636
+ $ quoteMock ->expects ($ this ->once ())->method ('setStoreId ' )->with ($ storeId );
637
+ $ quoteMock ->expects ($ this ->once ())->method ('setIsActive ' )->with (1 );
638
+
639
+ $ this ->quoteIdMock ->expects ($ this ->once ())->method ('load ' )->with ($ cartId , 'quote_id ' )->willReturnSelf ();
640
+ $ this ->quoteIdMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (10 );
641
+ $ this ->quoteIdMock ->expects ($ this ->once ())->method ('delete ' );
642
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ quoteMock );
564
643
565
644
$ this ->model ->assignCustomer ($ cartId , $ customerId , $ storeId );
566
645
}
0 commit comments