Skip to content

Commit 860a9f0

Browse files
author
Cari Spruiell
committed
MAGETWO-36428: Magento\Quote\Model\Quote\Item\Repository
- added "ForCustomer" test cases
1 parent 790182c commit 860a9f0

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,38 @@ public function testSave()
160160
$this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock));
161161
}
162162

163+
/**
164+
* @return void
165+
*/
166+
public function testSaveForCustomer()
167+
{
168+
$customerId = 1;
169+
$cartId = 13;
170+
$this->quoteRepositoryMock->expects($this->once())->method('getActiveForCustomer')
171+
->with($customerId)
172+
->will($this->returnValue($this->quoteMock));
173+
$this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId);
174+
$this->dataMock->expects($this->once())->method('getQty')->will($this->returnValue(12));
175+
$this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
176+
$this->quoteRepositoryMock->expects($this->once())
177+
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
178+
$this->productRepositoryMock->expects($this->once())
179+
->method('get')
180+
->will($this->returnValue($this->productMock));
181+
$this->dataMock->expects($this->once())->method('getSku');
182+
$this->quoteMock->expects($this->once())->method('addProduct')->with($this->productMock, 12);
183+
$this->quoteMock->expects($this->never())->method('getItemById');
184+
$this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
185+
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
186+
$this->quoteMock
187+
->expects($this->once())
188+
->method('getItemByProduct')
189+
->with($this->productMock)
190+
->will($this->returnValue($this->quoteItemMock));
191+
$this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue(null));
192+
$this->assertEquals($this->quoteItemMock, $this->repository->saveForCustomer($customerId, $this->dataMock));
193+
}
194+
163195
/**
164196
* @return void
165197
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
@@ -319,6 +351,36 @@ public function testDelete()
319351
$this->repository->delete($this->dataMock);
320352
}
321353

354+
/**
355+
* @return void
356+
*/
357+
public function testDeleteByIdForCustomer()
358+
{
359+
$customerId = 1;
360+
$cartId = 11;
361+
$itemId = 5;
362+
$this->quoteRepositoryMock->expects($this->once())->method('getActiveForCustomer')
363+
->with($customerId)
364+
->will($this->returnValue($this->quoteMock));
365+
$this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId);
366+
$this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->dataMock);
367+
$this->dataMock->expects($this->once())->method('setQuoteId')
368+
->with($cartId)->willReturn($this->dataMock);
369+
$this->dataMock->expects($this->once())->method('setItemId')
370+
->with($itemId)->willReturn($this->dataMock);
371+
$this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
372+
$this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId);
373+
$this->quoteRepositoryMock->expects($this->once())
374+
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
375+
$this->quoteMock->expects($this->once())
376+
->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock));
377+
$this->quoteMock->expects($this->once())->method('removeItem');
378+
$this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
379+
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
380+
381+
$this->assertTrue($this->repository->deleteByIdForCustomer($customerId, $itemId));
382+
}
383+
322384
/**
323385
* @return void
324386
*/
@@ -334,6 +396,27 @@ public function testGetList()
334396
$this->assertEquals([$itemMock], $this->repository->getList(33));
335397
}
336398

399+
/**
400+
* @return void
401+
*/
402+
public function testGetListForCustomer()
403+
{
404+
$cartId = 1;
405+
$customerId = 33;
406+
$quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false);
407+
$this->quoteRepositoryMock->expects($this->once())->method('getActiveForCustomer')
408+
->with($customerId)
409+
->will($this->returnValue($quoteMock));
410+
$quoteMock->expects($this->once())->method('getId')->willReturn($cartId);
411+
$this->quoteRepositoryMock->expects($this->once())->method('getActive')
412+
->with($cartId)
413+
->will($this->returnValue($quoteMock));
414+
$itemMock = $this->getMock('\Magento\Quote\Model\Quote\Item', [], [], '', false);
415+
$quoteMock->expects($this->any())->method('getAllItems')->will($this->returnValue([$itemMock]));
416+
417+
$this->assertEquals([$itemMock], $this->repository->getListForCustomer($customerId));
418+
}
419+
337420
/**
338421
* @return void
339422
*/

0 commit comments

Comments
 (0)