Skip to content

Commit 0cc286b

Browse files
author
Yu Tang
committed
Merge branch 'FearlessKiwis-MAGETWO-31933-backend-order-shipping-address' into develop
2 parents 4524f5a + 4e2d0aa commit 0cc286b

File tree

2 files changed

+89
-70
lines changed

2 files changed

+89
-70
lines changed

app/code/Magento/Backend/Model/Session/Quote.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function getQuote()
147147
$this->_quote->setStoreId($this->getStoreId());
148148
}
149149

150-
if ($this->getCustomerId()) {
150+
if ($this->getCustomerId() && $this->getCustomerId() != $this->_quote->getCustomerId()) {
151151
$customer = $this->customerRepository->getById($this->getCustomerId());
152152
$this->_quote->assignCustomer($customer);
153153
}

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

Lines changed: 88 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,42 @@ protected function setUp()
217217
*
218218
* @return void
219219
*/
220-
public function testGetQuote()
220+
public function testGetQuoteWithoutQuoteId()
221221
{
222-
$storeId = 10;
223222
$quoteId = 22;
224-
$customerGroupId = 77;
223+
$storeId = 10;
225224
$customerId = 66;
225+
$customerGroupId = 77;
226+
227+
$this->quote->expects($this->any())
228+
->method('getQuoteId')
229+
->will($this->returnValue(null));
230+
$this->quote->expects($this->any())
231+
->method('setQuoteId')
232+
->with($quoteId);
233+
$this->quote->expects($this->any())
234+
->method('getStoreId')
235+
->will($this->returnValue($storeId));
236+
$this->quote->expects($this->any())
237+
->method('getCustomerId')
238+
->will($this->returnValue($customerId));
239+
240+
$defaultGroup = $this->getMockBuilder('Magento\Customer\Api\Data\GroupInterface')
241+
->getMock();
242+
$defaultGroup->expects($this->any())
243+
->method('getId')
244+
->will($this->returnValue($customerGroupId));
245+
$this->groupManagementMock->expects($this->any())
246+
->method('getDefaultGroup')
247+
->will($this->returnValue($defaultGroup));
248+
249+
$dataCustomerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')
250+
->disableOriginalConstructor()
251+
->getMock();
252+
$this->customerRepositoryMock->expects($this->once())
253+
->method('getById')
254+
->with($customerId)
255+
->willReturn($dataCustomerMock);
226256

227257
$quoteMock = $this->getMock(
228258
'Magento\Quote\Model\Quote',
@@ -240,28 +270,9 @@ public function testGetQuote()
240270
'',
241271
false
242272
);
243-
244-
$defaultGroup = $this->getMockBuilder('Magento\Customer\Api\Data\GroupInterface')
245-
->getMock();
246-
$defaultGroup->expects($this->any())
247-
->method('getId')
248-
->will($this->returnValue($customerGroupId));
249-
$this->groupManagementMock->expects($this->any())
250-
->method('getDefaultGroup')
251-
->will($this->returnValue($defaultGroup));
252-
253-
$this->quoteRepositoryMock->expects($this->once())
254-
->method('create')
255-
->will($this->returnValue($quoteMock));
256-
$this->quote->expects($this->any())
257-
->method('getStoreId')
258-
->will($this->returnValue($storeId));
259273
$quoteMock->expects($this->once())
260274
->method('setStoreId')
261275
->with($storeId);
262-
$this->quote->expects($this->any())
263-
->method('getQuoteId')
264-
->will($this->returnValue(null));
265276
$quoteMock->expects($this->once())
266277
->method('setCustomerGroupId')
267278
->with($customerGroupId)
@@ -270,25 +281,9 @@ public function testGetQuote()
270281
->method('setIsActive')
271282
->with(false)
272283
->will($this->returnSelf());
273-
$this->quoteRepositoryMock->expects($this->once())
274-
->method('save')
275-
->with($quoteMock);
276284
$quoteMock->expects($this->once())
277285
->method('getId')
278286
->will($this->returnValue($quoteId));
279-
$this->quote->expects($this->any())
280-
->method('setQuoteId')
281-
->with($quoteId);
282-
$this->quote->expects($this->any())
283-
->method('getCustomerId')
284-
->will($this->returnValue($customerId));
285-
$dataCustomerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')
286-
->disableOriginalConstructor()
287-
->getMock();
288-
$this->customerRepositoryMock->expects($this->once())
289-
->method('getById')
290-
->with($customerId)
291-
->willReturn($dataCustomerMock);
292287
$quoteMock->expects($this->once())
293288
->method('assignCustomer')
294289
->with($dataCustomerMock);
@@ -299,19 +294,47 @@ public function testGetQuote()
299294
->method('setIsSuperMode')
300295
->with(true);
301296

297+
$this->quoteRepositoryMock->expects($this->once())
298+
->method('create')
299+
->will($this->returnValue($quoteMock));
300+
$this->quoteRepositoryMock->expects($this->once())
301+
->method('save')
302+
->with($quoteMock);
303+
302304
$this->assertEquals($quoteMock, $this->quote->getQuote());
303305
}
304306

305307
/**
306308
* Run test getQuote method
307309
*
308310
* @return void
311+
* @dataProvider getQuoteDataProvider
309312
*/
310-
public function testGetQuoteGet()
313+
public function testGetQuoteWithQuoteId($customerId, $quoteCustomerId, $expectedNumberOfInvokes)
311314
{
312-
$storeId = 10;
313315
$quoteId = 22;
314-
$customerId = 66;
316+
$storeId = 10;
317+
318+
$this->quote->expects($this->any())
319+
->method('getQuoteId')
320+
->will($this->returnValue($quoteId));
321+
$this->quote->expects($this->any())
322+
->method('setQuoteId')
323+
->with($quoteId);
324+
$this->quote->expects($this->any())
325+
->method('getStoreId')
326+
->will($this->returnValue($storeId));
327+
$this->quote->expects($this->any())
328+
->method('getCustomerId')
329+
->will($this->returnValue($customerId));
330+
331+
$dataCustomerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')
332+
->disableOriginalConstructor()
333+
->getMock();
334+
$this->customerRepositoryMock->expects($this->$expectedNumberOfInvokes())
335+
->method('getById')
336+
->with($customerId)
337+
->willReturn($dataCustomerMock);
315338

316339
$quoteMock = $this->getMock(
317340
'Magento\Quote\Model\Quote',
@@ -323,43 +346,17 @@ public function testGetQuoteGet()
323346
'assignCustomer',
324347
'setIgnoreOldQty',
325348
'setIsSuperMode',
349+
'getCustomerId',
326350
'__wakeup'
327351
],
328352
[],
329353
'',
330354
false
331355
);
332-
333-
$this->quoteRepositoryMock->expects($this->once())
334-
->method('create')
335-
->will($this->returnValue($quoteMock));
336-
$this->quote->expects($this->any())
337-
->method('getStoreId')
338-
->will($this->returnValue($storeId));
339356
$quoteMock->expects($this->once())
340357
->method('setStoreId')
341358
->with($storeId);
342-
$this->quote->expects($this->any())
343-
->method('getQuoteId')
344-
->will($this->returnValue($quoteId));
345-
$this->quoteRepositoryMock->expects($this->once())
346-
->method('get')
347-
->with($quoteId)
348-
->willReturn($quoteMock);
349-
$this->quote->expects($this->any())
350-
->method('setQuoteId')
351-
->with($quoteId);
352-
$this->quote->expects($this->any())
353-
->method('getCustomerId')
354-
->will($this->returnValue($customerId));
355-
$dataCustomerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')
356-
->disableOriginalConstructor()
357-
->getMock();
358-
$this->customerRepositoryMock->expects($this->once())
359-
->method('getById')
360-
->with($customerId)
361-
->willReturn($dataCustomerMock);
362-
$quoteMock->expects($this->once())
359+
$quoteMock->expects($this->$expectedNumberOfInvokes())
363360
->method('assignCustomer')
364361
->with($dataCustomerMock);
365362
$quoteMock->expects($this->once())
@@ -368,7 +365,29 @@ public function testGetQuoteGet()
368365
$quoteMock->expects($this->once())
369366
->method('setIsSuperMode')
370367
->with(true);
368+
$quoteMock->expects($this->once())
369+
->method('getCustomerId')
370+
->will($this->returnValue($quoteCustomerId));
371+
372+
$this->quoteRepositoryMock->expects($this->once())
373+
->method('create')
374+
->will($this->returnValue($quoteMock));
375+
$this->quoteRepositoryMock->expects($this->once())
376+
->method('get')
377+
->with($quoteId)
378+
->willReturn($quoteMock);
371379

372380
$this->assertEquals($quoteMock, $this->quote->getQuote());
373381
}
382+
383+
/**
384+
* @return array
385+
*/
386+
public function getQuoteDataProvider()
387+
{
388+
return [
389+
'customer ids different' => [66, null, 'once'],
390+
'customer ids same' => [66, 66, 'never'],
391+
];
392+
}
374393
}

0 commit comments

Comments
 (0)