@@ -63,6 +63,21 @@ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase
63
63
*/
64
64
private $ shippingAddress ;
65
65
66
+ /**
67
+ * @var \Magento\Framework\Reflection\DataObjectProcessor|MockObject
68
+ */
69
+ private $ dataProcessor ;
70
+
71
+ /**
72
+ * @var \Magento\Customer\Api\Data\AddressInterfaceFactory|MockObject
73
+ */
74
+ private $ addressFactory ;
75
+
76
+ /**
77
+ * @var \Magento\Customer\Api\AddressRepositoryInterface|MockObject
78
+ */
79
+ private $ addressRepository ;
80
+
66
81
/**
67
82
* @var TotalsCollector|MockObject
68
83
*/
@@ -72,16 +87,17 @@ protected function setUp()
72
87
{
73
88
$ this ->objectManager = new ObjectManager ($ this );
74
89
$ this ->quoteRepository = $ this ->getMock (\Magento \Quote \Api \CartRepositoryInterface::class);
75
- $ this ->methodDataFactoryMock = $ this ->getMock (
76
- \Magento \Quote \Api \Data \ShippingMethodInterfaceFactory::class,
77
- [
78
- 'create '
79
- ],
80
- [],
81
- '' ,
82
- false
83
- );
90
+ $ this ->addressRepository = $ this ->getMock (\Magento \Customer \Api \AddressRepositoryInterface::class);
91
+
92
+ $ className = \Magento \Quote \Api \Data \ShippingMethodInterfaceFactory::class;
93
+ $ this ->methodDataFactoryMock = $ this ->getMock ($ className , ['create ' ], [], '' , false );
84
94
95
+ $ className = \Magento \Customer \Api \Data \AddressInterfaceFactory::class;
96
+ $ this ->addressFactory = $ this ->getMock ($ className , ['create ' ], [], '' , false );
97
+
98
+ $ className = \Magento \Framework \Reflection \DataObjectProcessor::class;
99
+ $ this ->dataProcessor = $ this ->getMock ($ className , [], [], '' , false );
100
+
85
101
$ this ->storeMock = $ this ->getMock (\Magento \Store \Model \Store::class, [], [], '' , false );
86
102
$ this ->quote = $ this ->getMockBuilder (Quote::class)
87
103
->disableOriginalConstructor ()
@@ -132,9 +148,22 @@ protected function setUp()
132
148
'quoteRepository ' => $ this ->quoteRepository ,
133
149
'methodDataFactory ' => $ this ->methodDataFactoryMock ,
134
150
'converter ' => $ this ->converter ,
135
- 'totalsCollector ' => $ this ->totalsCollector
151
+ 'totalsCollector ' => $ this ->totalsCollector ,
152
+ 'addressRepository ' => $ this ->addressRepository
136
153
]
137
154
);
155
+
156
+ $ this ->objectManager ->setBackwardCompatibleProperty (
157
+ $ this ->model ,
158
+ 'addressFactory ' ,
159
+ $ this ->addressFactory
160
+ );
161
+
162
+ $ this ->objectManager ->setBackwardCompatibleProperty (
163
+ $ this ->model ,
164
+ 'dataProcessor ' ,
165
+ $ this ->dataProcessor
166
+ );
138
167
}
139
168
140
169
/**
@@ -457,11 +486,17 @@ public function testEstimateByExtendedAddress()
457
486
];
458
487
$ currencyCode = 'UAH ' ;
459
488
489
+ /**
490
+ * @var \Magento\Quote\Api\Data\AddressInterface|MockObject $address
491
+ */
460
492
$ address = $ this ->getMockBuilder (Address::class)
461
493
->disableOriginalConstructor ()
462
- ->setMethods (['getData ' ])
463
494
->getMock ();
464
495
496
+ $ this ->addressFactory ->expects ($ this ->any ())
497
+ ->method ('create ' )
498
+ ->will ($ this ->returnValue ($ address ));
499
+
465
500
$ this ->quoteRepository ->expects (static ::once ())
466
501
->method ('getActive ' )
467
502
->with ($ cartId )
@@ -474,18 +509,98 @@ public function testEstimateByExtendedAddress()
474
509
->method ('getItemsCount ' )
475
510
->willReturn (1 );
476
511
477
- $ address ->expects (static ::once ())
478
- ->method ('getData ' )
479
- ->willReturn ($ addressData );
480
-
481
512
$ this ->quote ->expects (static ::once ())
482
513
->method ('getShippingAddress ' )
483
514
->willReturn ($ this ->shippingAddress );
484
515
516
+ $ this ->dataProcessor ->expects (static ::any ())
517
+ ->method ('buildOutputDataArray ' )
518
+ ->willReturn ($ addressData );
519
+
485
520
$ this ->shippingAddress ->expects (static ::once ())
486
- ->method ('addData ' )
487
- ->with ($ addressData )
521
+ ->method ('setCollectShippingRates ' )
522
+ ->with (true )
523
+ ->willReturnSelf ();
524
+
525
+ $ this ->totalsCollector ->expects (static ::once ())
526
+ ->method ('collectAddressTotals ' )
527
+ ->with ($ this ->quote , $ this ->shippingAddress )
488
528
->willReturnSelf ();
529
+
530
+ $ rate = $ this ->getMockBuilder (Rate::class)
531
+ ->disableOriginalConstructor ()
532
+ ->setMethods ([])
533
+ ->getMock ();
534
+ $ methodObject = $ this ->getMockForAbstractClass (ShippingMethodInterface::class);
535
+ $ expectedRates = [$ methodObject ];
536
+
537
+ $ this ->shippingAddress ->expects (static ::once ())
538
+ ->method ('getGroupedAllShippingRates ' )
539
+ ->willReturn ([[$ rate ]]);
540
+
541
+ $ this ->quote ->expects (static ::once ())
542
+ ->method ('getQuoteCurrencyCode ' )
543
+ ->willReturn ($ currencyCode );
544
+
545
+ $ this ->converter ->expects (static ::once ())
546
+ ->method ('modelToDataObject ' )
547
+ ->with ($ rate , $ currencyCode )
548
+ ->willReturn ($ methodObject );
549
+
550
+ $ carriersRates = $ this ->model ->estimateByExtendedAddress ($ cartId , $ address );
551
+ static ::assertEquals ($ expectedRates , $ carriersRates );
552
+ }
553
+
554
+ /**
555
+ * @covers \Magento\Quote\Model\ShippingMethodManagement::estimateByAddressId
556
+ */
557
+ public function testEstimateByAddressId ()
558
+ {
559
+ $ cartId = 1 ;
560
+
561
+ $ addressData = [
562
+ 'region ' => 'California ' ,
563
+ 'region_id ' => 23 ,
564
+ 'country_id ' => 1 ,
565
+ 'postcode ' => 90200
566
+ ];
567
+ $ currencyCode = 'UAH ' ;
568
+
569
+ /**
570
+ * @var \Magento\Customer\Api\Data\AddressInterface|MockObject $address
571
+ */
572
+ $ address = $ this ->getMockBuilder (\Magento \Customer \Api \Data \AddressInterface::class)
573
+ ->disableOriginalConstructor ()
574
+ ->getMock ();
575
+
576
+ $ this ->addressRepository ->expects ($ this ->any ())
577
+ ->method ('getById ' )
578
+ ->will ($ this ->returnValue ($ address ));
579
+
580
+ $ this ->addressFactory ->expects ($ this ->any ())
581
+ ->method ('create ' )
582
+ ->will ($ this ->returnValue ($ address ));
583
+
584
+ $ this ->quoteRepository ->expects (static ::once ())
585
+ ->method ('getActive ' )
586
+ ->with ($ cartId )
587
+ ->willReturn ($ this ->quote );
588
+
589
+ $ this ->quote ->expects (static ::once ())
590
+ ->method ('isVirtual ' )
591
+ ->willReturn (false );
592
+ $ this ->quote ->expects (static ::once ())
593
+ ->method ('getItemsCount ' )
594
+ ->willReturn (1 );
595
+
596
+ $ this ->quote ->expects (static ::once ())
597
+ ->method ('getShippingAddress ' )
598
+ ->willReturn ($ this ->shippingAddress );
599
+
600
+ $ this ->dataProcessor ->expects (static ::any ())
601
+ ->method ('buildOutputDataArray ' )
602
+ ->willReturn ($ addressData );
603
+
489
604
$ this ->shippingAddress ->expects (static ::once ())
490
605
->method ('setCollectShippingRates ' )
491
606
->with (true )
@@ -516,7 +631,7 @@ public function testEstimateByExtendedAddress()
516
631
->with ($ rate , $ currencyCode )
517
632
->willReturn ($ methodObject );
518
633
519
- $ carriersRates = $ this ->model ->estimateByExtendedAddress ($ cartId , $ address );
634
+ $ carriersRates = $ this ->model ->estimateByAddressId ($ cartId , $ address );
520
635
static ::assertEquals ($ expectedRates , $ carriersRates );
521
636
}
522
637
}
0 commit comments