7
7
8
8
namespace Magento \Quote \Test \Unit \Model ;
9
9
10
+ use Magento \Customer \Api \Data \CustomerInterface ;
11
+ use Magento \Customer \Model \Customer ;
10
12
use Magento \Framework \App \RequestInterface ;
11
13
use Magento \Framework \Exception \NoSuchEntityException ;
12
14
13
15
use Magento \Framework \HTTP \PhpEnvironment \RemoteAddress ;
14
16
use Magento \Quote \Model \CustomerManagement ;
17
+ use Magento \Quote \Model \Quote ;
15
18
use Magento \Quote \Model \QuoteIdMaskFactory ;
16
19
use Magento \Sales \Api \Data \OrderAddressInterface ;
17
20
@@ -199,7 +202,7 @@ protected function setUp()
199
202
);
200
203
201
204
$ this ->quoteMock = $ this ->createPartialMock (
202
- \ Magento \ Quote \ Model \ Quote::class,
205
+ Quote::class,
203
206
[
204
207
'assignCustomer ' ,
205
208
'collectTotals ' ,
@@ -275,7 +278,7 @@ public function testCreateEmptyCartAnonymous()
275
278
$ storeId = 345 ;
276
279
$ quoteId = 2311 ;
277
280
278
- $ quoteMock = $ this ->createMock (\ Magento \ Quote \ Model \ Quote::class);
281
+ $ quoteMock = $ this ->createMock (Quote::class);
279
282
$ quoteAddress = $ this ->createPartialMock (
280
283
\Magento \Quote \Model \Quote \Address::class,
281
284
['setCollectShippingRates ' ]
@@ -306,14 +309,14 @@ public function testCreateEmptyCartForCustomer()
306
309
$ quoteId = 2311 ;
307
310
$ userId = 567 ;
308
311
309
- $ quoteMock = $ this ->createMock (\ Magento \ Quote \ Model \ Quote::class);
312
+ $ quoteMock = $ this ->createMock (Quote::class);
310
313
311
314
$ this ->quoteRepositoryMock
312
315
->expects ($ this ->once ())
313
316
->method ('getActiveForCustomer ' )
314
317
->with ($ userId )
315
318
->willThrowException (new NoSuchEntityException ());
316
- $ customer = $ this ->getMockBuilder (\ Magento \ Customer \ Api \ Data \ CustomerInterface::class)
319
+ $ customer = $ this ->getMockBuilder (CustomerInterface::class)
317
320
->setMethods (['getDefaultBilling ' ])->disableOriginalConstructor ()->getMockForAbstractClass ();
318
321
$ quoteAddress = $ this ->createPartialMock (
319
322
\Magento \Quote \Model \Quote \Address::class,
@@ -342,14 +345,14 @@ public function testCreateEmptyCartForCustomerReturnExistsQuote()
342
345
$ storeId = 345 ;
343
346
$ userId = 567 ;
344
347
345
- $ quoteMock = $ this ->createMock (\ Magento \ Quote \ Model \ Quote::class);
348
+ $ quoteMock = $ this ->createMock (Quote::class);
346
349
347
350
$ this ->quoteRepositoryMock
348
351
->expects ($ this ->once ())
349
352
->method ('getActiveForCustomer ' )
350
353
->with ($ userId )->willReturn ($ quoteMock );
351
354
352
- $ customer = $ this ->getMockBuilder (\ Magento \ Customer \ Api \ Data \ CustomerInterface::class)
355
+ $ customer = $ this ->getMockBuilder (CustomerInterface::class)
353
356
->setMethods (['getDefaultBilling ' ])->disableOriginalConstructor ()->getMockForAbstractClass ();
354
357
$ quoteAddress = $ this ->createPartialMock (
355
358
\Magento \Quote \Model \Quote \Address::class,
@@ -379,8 +382,8 @@ public function testAssignCustomerFromAnotherStore()
379
382
$ customerId = 455 ;
380
383
$ storeId = 5 ;
381
384
382
- $ quoteMock = $ this ->createMock (\ Magento \ Quote \ Model \ Quote::class);
383
- $ customerMock = $ this ->createMock (\ Magento \ Customer \ Api \ Data \ CustomerInterface::class);
385
+ $ quoteMock = $ this ->createMock (Quote::class);
386
+ $ customerMock = $ this ->createMock (CustomerInterface::class);
384
387
385
388
$ this ->quoteRepositoryMock
386
389
->expects ($ this ->once ())
@@ -395,7 +398,7 @@ public function testAssignCustomerFromAnotherStore()
395
398
->willReturn ($ customerMock );
396
399
397
400
$ customerModelMock = $ this ->createPartialMock (
398
- \ Magento \ Customer \ Model \ Customer::class,
401
+ Customer::class,
399
402
['load ' , 'getSharedStoreIds ' ]
400
403
);
401
404
$ this ->customerFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ customerModelMock );
@@ -424,10 +427,10 @@ public function testAssignCustomerToNonanonymousCart()
424
427
$ storeId = 5 ;
425
428
426
429
$ quoteMock = $ this ->createPartialMock (
427
- \ Magento \ Quote \ Model \ Quote::class,
430
+ Quote::class,
428
431
['getCustomerId ' , 'setCustomer ' , 'setCustomerIsGuest ' ]
429
432
);
430
- $ customerMock = $ this ->createMock (\ Magento \ Customer \ Api \ Data \ CustomerInterface::class);
433
+ $ customerMock = $ this ->createMock (CustomerInterface::class);
431
434
432
435
$ this ->quoteRepositoryMock
433
436
->expects ($ this ->once ())
@@ -442,7 +445,7 @@ public function testAssignCustomerToNonanonymousCart()
442
445
->willReturn ($ customerMock );
443
446
444
447
$ customerModelMock = $ this ->createPartialMock (
445
- \ Magento \ Customer \ Model \ Customer::class,
448
+ Customer::class,
446
449
['load ' , 'getSharedStoreIds ' ]
447
450
);
448
451
$ this ->customerFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ customerModelMock );
@@ -463,7 +466,7 @@ public function testAssignCustomerToNonanonymousCart()
463
466
}
464
467
465
468
/**
466
- * @expectedException \Magento\Framework\Exception\StateException
469
+ * @expectedException NoSuchEntityException
467
470
*/
468
471
public function testAssignCustomerNoSuchCustomer ()
469
472
{
@@ -472,10 +475,9 @@ public function testAssignCustomerNoSuchCustomer()
472
475
$ storeId = 5 ;
473
476
474
477
$ quoteMock = $ this ->createPartialMock (
475
- \ Magento \ Quote \ Model \ Quote::class,
478
+ Quote::class,
476
479
['getCustomerId ' , 'setCustomer ' , 'setCustomerIsGuest ' ]
477
480
);
478
- $ customerMock = $ this ->createMock (\Magento \Customer \Api \Data \CustomerInterface::class);
479
481
480
482
$ this ->quoteRepositoryMock
481
483
->expects ($ this ->once ())
@@ -487,36 +489,14 @@ public function testAssignCustomerNoSuchCustomer()
487
489
->expects ($ this ->once ())
488
490
->method ('getById ' )
489
491
->with ($ customerId )
490
- ->willReturn ( $ customerMock );
492
+ ->willThrowException ( new NoSuchEntityException () );
491
493
492
- $ customerModelMock = $ this ->createPartialMock (
493
- \Magento \Customer \Model \Customer::class,
494
- ['load ' , 'getSharedStoreIds ' ]
494
+ $ this ->expectExceptionMessage (
495
+ "No such entity. "
495
496
);
496
- $ this ->customerFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ customerModelMock );
497
- $ customerModelMock
498
- ->expects ($ this ->once ())
499
- ->method ('load ' )
500
- ->with ($ customerId )
501
- ->willReturnSelf ();
502
-
503
- $ customerModelMock
504
- ->expects ($ this ->once ())
505
- ->method ('getSharedStoreIds ' )
506
- ->willReturn ([$ storeId , 'some store value ' ]);
507
-
508
- $ quoteMock ->expects ($ this ->once ())->method ('getCustomerId ' )->willReturn (null );
509
-
510
- $ this ->quoteRepositoryMock
511
- ->expects ($ this ->once ())
512
- ->method ('getForCustomer ' )
513
- ->with ($ customerId );
514
497
515
498
$ this ->model ->assignCustomer ($ cartId , $ customerId , $ storeId );
516
499
517
- $ this ->expectExceptionMessage (
518
- "The customer can't be assigned to the cart because the customer already has an active cart. "
519
- );
520
500
}
521
501
522
502
public function testAssignCustomer ()
@@ -525,18 +505,11 @@ public function testAssignCustomer()
525
505
$ customerId = 455 ;
526
506
$ storeId = 5 ;
527
507
528
- $ this ->getPropertyValue ($ this ->model , 'quoteIdMaskFactory ' )
529
- ->expects ($ this ->once ())
530
- ->method ('create ' )
531
- ->willReturn ($ this ->quoteIdMock );
532
- $ this ->quoteIdMock ->expects ($ this ->once ())->method ('load ' )->with ($ cartId , 'quote_id ' )->willReturnSelf ();
533
- $ this ->quoteIdMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (10 );
534
- $ this ->quoteIdMock ->expects ($ this ->once ())->method ('delete ' );
535
508
$ quoteMock = $ this ->createPartialMock (
536
- \ Magento \ Quote \ Model \ Quote::class,
537
- ['getCustomerId ' , 'setCustomer ' , 'setCustomerIsGuest ' ]
509
+ Quote::class,
510
+ ['getCustomerId ' , 'setCustomer ' , 'setCustomerIsGuest ' , ' merge ' ]
538
511
);
539
- $ customerMock = $ this ->createMock (\ Magento \ Customer \ Api \ Data \ CustomerInterface::class);
512
+ $ customerMock = $ this ->createMock (CustomerInterface::class);
540
513
541
514
$ this ->quoteRepositoryMock
542
515
->expects ($ this ->once ())
@@ -551,7 +524,7 @@ public function testAssignCustomer()
551
524
->willReturn ($ customerMock );
552
525
553
526
$ customerModelMock = $ this ->createPartialMock (
554
- \ Magento \ Customer \ Model \ Customer::class,
527
+ Customer::class,
555
528
['load ' , 'getSharedStoreIds ' ]
556
529
);
557
530
$ this ->customerFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ customerModelMock );
@@ -574,10 +547,22 @@ public function testAssignCustomer()
574
547
->with ($ customerId )
575
548
->willThrowException (new NoSuchEntityException ());
576
549
577
- $ quoteMock ->expects ($ this ->once ())->method ('setCustomer ' )->with ($ customerMock );
578
- $ quoteMock ->expects ($ this ->once ())->method ('setCustomerIsGuest ' )->with (0 );
550
+ $ activeQuoteMock = $ this ->createPartialMock (
551
+ Quote::class,
552
+ ['getCustomerId ' , 'setCustomer ' , 'setCustomerIsGuest ' , 'setStoreId ' , 'setIsActive ' , 'getIsActive ' , 'merge ' ]
553
+ );
579
554
580
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ quoteMock );
555
+ $ this ->quoteFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ activeQuoteMock );
556
+ $ activeQuoteMock ->expects ($ this ->once ())->method ('setCustomer ' )->with ($ customerMock );
557
+ $ activeQuoteMock ->expects ($ this ->once ())->method ('setCustomerIsGuest ' )->with (0 );
558
+ $ activeQuoteMock ->expects ($ this ->once ())->method ('setStoreId ' )->with ($ storeId );
559
+ $ activeQuoteMock ->expects ($ this ->once ())->method ('setIsActive ' )->with (1 );
560
+
561
+ $ activeQuoteMock ->expects ($ this ->once ())->method ('getIsActive ' )->willReturn (1 );
562
+ $ activeQuoteMock ->expects ($ this ->once ())->method ('merge ' )->with ($ quoteMock )->willReturnSelf ();
563
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('delete ' )->with ($ quoteMock );
564
+
565
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ activeQuoteMock );
581
566
582
567
$ this ->model ->assignCustomer ($ cartId , $ customerId , $ storeId );
583
568
}
@@ -881,7 +866,7 @@ protected function getQuote(
881
866
\Magento \Quote \Model \Quote \Address $ shippingAddress = null
882
867
) {
883
868
$ quote = $ this ->createPartialMock (
884
- \ Magento \ Quote \ Model \ Quote::class,
869
+ Quote::class,
885
870
[
886
871
'setIsActive ' ,
887
872
'getCustomerEmail ' ,
@@ -928,7 +913,7 @@ protected function getQuote(
928
913
->willReturn ($ payment );
929
914
930
915
$ customer = $ this ->createPartialMock (
931
- \ Magento \ Customer \ Model \ Customer::class,
916
+ Customer::class,
932
917
['getDefaultBilling ' , 'getId ' ]
933
918
);
934
919
$ quote ->expects ($ this ->any ())->method ('getCustomerId ' )->willReturn ($ customerId );
@@ -1021,7 +1006,7 @@ protected function prepareOrderFactory(
1021
1006
public function testGetCartForCustomer ()
1022
1007
{
1023
1008
$ customerId = 100 ;
1024
- $ cartMock = $ this ->createMock (\ Magento \ Quote \ Model \ Quote::class);
1009
+ $ cartMock = $ this ->createMock (Quote::class);
1025
1010
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
1026
1011
->method ('getActiveForCustomer ' )
1027
1012
->with ($ customerId )
0 commit comments