Skip to content

Commit 929aabe

Browse files
committed
MAGETWO-55117: ShippingMethodManagement::estimateByAddressId set not full address details
- fixing and adding unit tests
1 parent b5ddd2a commit 929aabe

File tree

1 file changed

+135
-9
lines changed

1 file changed

+135
-9
lines changed

app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php

Lines changed: 135 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase
6363
*/
6464
private $shippingAddress;
6565

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+
6681
/**
6782
* @var TotalsCollector|MockObject
6883
*/
@@ -72,6 +87,8 @@ protected function setUp()
7287
{
7388
$this->objectManager = new ObjectManager($this);
7489
$this->quoteRepository = $this->getMock('\Magento\Quote\Api\CartRepositoryInterface');
90+
$this->addressRepository = $this->getMock('\Magento\Customer\Api\AddressRepositoryInterface');
91+
7592
$this->methodDataFactoryMock = $this->getMock(
7693
'\Magento\Quote\Api\Data\ShippingMethodInterfaceFactory',
7794
[
@@ -82,6 +99,16 @@ protected function setUp()
8299
false
83100
);
84101

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+
85112
$this->storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
86113
$this->quote = $this->getMockBuilder(Quote::class)
87114
->disableOriginalConstructor()
@@ -132,9 +159,22 @@ protected function setUp()
132159
'quoteRepository' => $this->quoteRepository,
133160
'methodDataFactory' => $this->methodDataFactoryMock,
134161
'converter' => $this->converter,
135-
'totalsCollector' => $this->totalsCollector
162+
'totalsCollector' => $this->totalsCollector,
163+
'addressRepository' => $this->addressRepository
136164
]
137165
);
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+
);
138178
}
139179

140180
/**
@@ -457,11 +497,17 @@ public function testEstimateByExtendedAddress()
457497
];
458498
$currencyCode = 'UAH';
459499

500+
/**
501+
* @var \Magento\Quote\Api\Data\AddressInterface|MockObject $address
502+
*/
460503
$address = $this->getMockBuilder(Address::class)
461504
->disableOriginalConstructor()
462-
->setMethods(['getData'])
463505
->getMock();
464506

507+
$this->addressFactory->expects($this->any())
508+
->method('create')
509+
->will($this->returnValue($address));
510+
465511
$this->quoteRepository->expects(static::once())
466512
->method('getActive')
467513
->with($cartId)
@@ -474,18 +520,98 @@ public function testEstimateByExtendedAddress()
474520
->method('getItemsCount')
475521
->willReturn(1);
476522

477-
$address->expects(static::once())
478-
->method('getData')
479-
->willReturn($addressData);
480-
481523
$this->quote->expects(static::once())
482524
->method('getShippingAddress')
483525
->willReturn($this->shippingAddress);
484526

527+
$this->dataProcessor->expects(static::any())
528+
->method('buildOutputDataArray')
529+
->willReturn($addressData);
530+
485531
$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)
488539
->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+
489615
$this->shippingAddress->expects(static::once())
490616
->method('setCollectShippingRates')
491617
->with(true)
@@ -516,7 +642,7 @@ public function testEstimateByExtendedAddress()
516642
->with($rate, $currencyCode)
517643
->willReturn($methodObject);
518644

519-
$carriersRates = $this->model->estimateByExtendedAddress($cartId, $address);
645+
$carriersRates = $this->model->estimateByAddressId($cartId, $address);
520646
static::assertEquals($expectedRates, $carriersRates);
521647
}
522648
}

0 commit comments

Comments
 (0)