@@ -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,6 +87,8 @@ protected function setUp()
72
87
{
73
88
$ this ->objectManager = new ObjectManager ($ this );
74
89
$ this ->quoteRepository = $ this ->getMock ('\Magento\Quote\Api\CartRepositoryInterface ' );
90
+ $ this ->addressRepository = $ this ->getMock ('\Magento\Customer\Api\AddressRepositoryInterface ' );
91
+
75
92
$ this ->methodDataFactoryMock = $ this ->getMock (
76
93
'\Magento\Quote\Api\Data\ShippingMethodInterfaceFactory ' ,
77
94
[
@@ -82,6 +99,16 @@ protected function setUp()
82
99
false
83
100
);
84
101
102
+ $ this ->addressFactory = $ this ->getMock (
103
+ 'Magento\Customer\Api\Data\AddressInterfaceFactory ' ,
104
+ ['create ' ],
105
+ [],
106
+ '' ,
107
+ false
108
+ );
109
+
110
+ $ this ->dataProcessor = $ this ->getMock ('Magento\Framework\Reflection\DataObjectProcessor ' , [], [], '' , false );
111
+
85
112
$ this ->storeMock = $ this ->getMock ('\Magento\Store\Model\Store ' , [], [], '' , false );
86
113
$ this ->quote = $ this ->getMockBuilder (Quote::class)
87
114
->disableOriginalConstructor ()
@@ -132,9 +159,22 @@ protected function setUp()
132
159
'quoteRepository ' => $ this ->quoteRepository ,
133
160
'methodDataFactory ' => $ this ->methodDataFactoryMock ,
134
161
'converter ' => $ this ->converter ,
135
- 'totalsCollector ' => $ this ->totalsCollector
162
+ 'totalsCollector ' => $ this ->totalsCollector ,
163
+ 'addressRepository ' => $ this ->addressRepository
136
164
]
137
165
);
166
+
167
+ $ this ->objectManager ->setBackwardCompatibleProperty (
168
+ $ this ->model ,
169
+ 'addressFactory ' ,
170
+ $ this ->addressFactory
171
+ );
172
+
173
+ $ this ->objectManager ->setBackwardCompatibleProperty (
174
+ $ this ->model ,
175
+ 'dataProcessor ' ,
176
+ $ this ->dataProcessor
177
+ );
138
178
}
139
179
140
180
/**
@@ -457,11 +497,17 @@ public function testEstimateByExtendedAddress()
457
497
];
458
498
$ currencyCode = 'UAH ' ;
459
499
500
+ /**
501
+ * @var \Magento\Quote\Api\Data\AddressInterface|MockObject $address
502
+ */
460
503
$ address = $ this ->getMockBuilder (Address::class)
461
504
->disableOriginalConstructor ()
462
- ->setMethods (['getData ' ])
463
505
->getMock ();
464
506
507
+ $ this ->addressFactory ->expects ($ this ->any ())
508
+ ->method ('create ' )
509
+ ->will ($ this ->returnValue ($ address ));
510
+
465
511
$ this ->quoteRepository ->expects (static ::once ())
466
512
->method ('getActive ' )
467
513
->with ($ cartId )
@@ -474,18 +520,98 @@ public function testEstimateByExtendedAddress()
474
520
->method ('getItemsCount ' )
475
521
->willReturn (1 );
476
522
477
- $ address ->expects (static ::once ())
478
- ->method ('getData ' )
479
- ->willReturn ($ addressData );
480
-
481
523
$ this ->quote ->expects (static ::once ())
482
524
->method ('getShippingAddress ' )
483
525
->willReturn ($ this ->shippingAddress );
484
526
527
+ $ this ->dataProcessor ->expects (static ::any ())
528
+ ->method ('buildOutputDataArray ' )
529
+ ->willReturn ($ addressData );
530
+
485
531
$ this ->shippingAddress ->expects (static ::once ())
486
- ->method ('addData ' )
487
- ->with ($ addressData )
532
+ ->method ('setCollectShippingRates ' )
533
+ ->with (true )
534
+ ->willReturnSelf ();
535
+
536
+ $ this ->totalsCollector ->expects (static ::once ())
537
+ ->method ('collectAddressTotals ' )
538
+ ->with ($ this ->quote , $ this ->shippingAddress )
488
539
->willReturnSelf ();
540
+
541
+ $ rate = $ this ->getMockBuilder (Rate::class)
542
+ ->disableOriginalConstructor ()
543
+ ->setMethods ([])
544
+ ->getMock ();
545
+ $ methodObject = $ this ->getMockForAbstractClass (ShippingMethodInterface::class);
546
+ $ expectedRates = [$ methodObject ];
547
+
548
+ $ this ->shippingAddress ->expects (static ::once ())
549
+ ->method ('getGroupedAllShippingRates ' )
550
+ ->willReturn ([[$ rate ]]);
551
+
552
+ $ this ->quote ->expects (static ::once ())
553
+ ->method ('getQuoteCurrencyCode ' )
554
+ ->willReturn ($ currencyCode );
555
+
556
+ $ this ->converter ->expects (static ::once ())
557
+ ->method ('modelToDataObject ' )
558
+ ->with ($ rate , $ currencyCode )
559
+ ->willReturn ($ methodObject );
560
+
561
+ $ carriersRates = $ this ->model ->estimateByExtendedAddress ($ cartId , $ address );
562
+ static ::assertEquals ($ expectedRates , $ carriersRates );
563
+ }
564
+
565
+ /**
566
+ * @covers \Magento\Quote\Model\ShippingMethodManagement::estimateByAddressId
567
+ */
568
+ public function testEstimateByAddressId ()
569
+ {
570
+ $ cartId = 1 ;
571
+
572
+ $ addressData = [
573
+ 'region ' => 'California ' ,
574
+ 'region_id ' => 23 ,
575
+ 'country_id ' => 1 ,
576
+ 'postcode ' => 90200
577
+ ];
578
+ $ currencyCode = 'UAH ' ;
579
+
580
+ /**
581
+ * @var \Magento\Customer\Api\Data\AddressInterface|MockObject $address
582
+ */
583
+ $ address = $ this ->getMockBuilder (\Magento \Customer \Api \Data \AddressInterface::class)
584
+ ->disableOriginalConstructor ()
585
+ ->getMock ();
586
+
587
+ $ this ->addressRepository ->expects ($ this ->any ())
588
+ ->method ('getById ' )
589
+ ->will ($ this ->returnValue ($ address ));
590
+
591
+ $ this ->addressFactory ->expects ($ this ->any ())
592
+ ->method ('create ' )
593
+ ->will ($ this ->returnValue ($ address ));
594
+
595
+ $ this ->quoteRepository ->expects (static ::once ())
596
+ ->method ('getActive ' )
597
+ ->with ($ cartId )
598
+ ->willReturn ($ this ->quote );
599
+
600
+ $ this ->quote ->expects (static ::once ())
601
+ ->method ('isVirtual ' )
602
+ ->willReturn (false );
603
+ $ this ->quote ->expects (static ::once ())
604
+ ->method ('getItemsCount ' )
605
+ ->willReturn (1 );
606
+
607
+ $ this ->quote ->expects (static ::once ())
608
+ ->method ('getShippingAddress ' )
609
+ ->willReturn ($ this ->shippingAddress );
610
+
611
+ $ this ->dataProcessor ->expects (static ::any ())
612
+ ->method ('buildOutputDataArray ' )
613
+ ->willReturn ($ addressData );
614
+
489
615
$ this ->shippingAddress ->expects (static ::once ())
490
616
->method ('setCollectShippingRates ' )
491
617
->with (true )
@@ -516,7 +642,7 @@ public function testEstimateByExtendedAddress()
516
642
->with ($ rate , $ currencyCode )
517
643
->willReturn ($ methodObject );
518
644
519
- $ carriersRates = $ this ->model ->estimateByExtendedAddress ($ cartId , $ address );
645
+ $ carriersRates = $ this ->model ->estimateByAddressId ($ cartId , $ address );
520
646
static ::assertEquals ($ expectedRates , $ carriersRates );
521
647
}
522
648
}
0 commit comments