Skip to content

Commit fa93a40

Browse files
author
Mike Weis
committed
MAGETWO-31933: Can't change shipping address when creating order in backend
- expanded unit test
1 parent e776b21 commit fa93a40

File tree

1 file changed

+69
-4
lines changed

1 file changed

+69
-4
lines changed

app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ class QuoteTest extends \PHPUnit_Framework_TestCase
8686
*/
8787
protected $groupManagementMock;
8888

89+
/**
90+
* @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject
91+
*/
92+
protected $billingAddressMock;
93+
94+
/**
95+
* @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject
96+
*/
97+
protected $shippingAddressMock;
98+
8999
/**
90100
* Set up
91101
*
@@ -215,9 +225,13 @@ protected function setUp()
215225
/**
216226
* Run test getQuote method
217227
*
228+
* @param \Magento\Quote\Model\Quote\Address[] $allAddresses
229+
* @param \Magento\Quote\Model\Quote\Address|null $expectedBillingAddress
230+
* @param \Magento\Quote\Model\Quote\Address|null $expectedShippingAddress
218231
* @return void
232+
* @dataProvider allAddressesDataProvider
219233
*/
220-
public function testGetQuote()
234+
public function testGetQuoteWithoutQuoteId($allAddresses, $expectedBillingAddress, $expectedShippingAddress)
221235
{
222236
$storeId = 10;
223237
$quoteId = 22;
@@ -292,7 +306,7 @@ public function testGetQuote()
292306
->willReturn($dataCustomerMock);
293307
$quoteMock->expects($this->once())
294308
->method('assignCustomerWithAddressChange')
295-
->with($dataCustomerMock);
309+
->with($dataCustomerMock, $expectedBillingAddress, $expectedShippingAddress);
296310
$quoteMock->expects($this->once())
297311
->method('setIgnoreOldQty')
298312
->with(true);
@@ -301,17 +315,68 @@ public function testGetQuote()
301315
->with(true);
302316
$quoteMock->expects($this->any())
303317
->method('getAllAddresses')
304-
->will($this->returnValue([]));
318+
->will($this->returnValue($allAddresses));
305319

306320
$this->assertEquals($quoteMock, $this->quote->getQuote());
307321
}
308322

323+
/**
324+
* @return array
325+
*/
326+
public function allAddressesDataProvider()
327+
{
328+
// since setup() is called after the dataProvider, ensure we have valid addresses
329+
$this->buildAddressMocks();
330+
331+
return [
332+
'empty addresses' => [
333+
[],
334+
null,
335+
null
336+
],
337+
'use typical addresses' => [
338+
[$this->billingAddressMock, $this->shippingAddressMock],
339+
$this->billingAddressMock,
340+
$this->shippingAddressMock
341+
],
342+
];
343+
}
344+
345+
protected function buildAddressMocks()
346+
{
347+
if ($this->billingAddressMock == null) {
348+
$this->billingAddressMock = $this->getMock(
349+
'Magento\Quote\Model\Quote\Address',
350+
['getAddressType'],
351+
[],
352+
'',
353+
false
354+
);
355+
$this->billingAddressMock->expects($this->any())
356+
->method('getAddressType')
357+
->will($this->returnValue(\Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_BILLING));
358+
}
359+
360+
if ($this->shippingAddressMock == null) {
361+
$this->shippingAddressMock = $this->getMock(
362+
'Magento\Quote\Model\Quote\Address',
363+
['getAddressType'],
364+
[],
365+
'',
366+
false
367+
);
368+
$this->shippingAddressMock->expects($this->any())
369+
->method('getAddressType')
370+
->will($this->returnValue(\Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING));
371+
}
372+
}
373+
309374
/**
310375
* Run test getQuote method
311376
*
312377
* @return void
313378
*/
314-
public function testGetQuoteGet()
379+
public function testGetQuoteWithQuoteId()
315380
{
316381
$storeId = 10;
317382
$quoteId = 22;

0 commit comments

Comments
 (0)