Skip to content

Commit 7d71288

Browse files
committed
MAGETWO-50972: Move to Shopping Cart action does not work inside creation offline order
- Add unit test on call getForCustomer() method after get()
1 parent 9ef56a9 commit 7d71288

File tree

1 file changed

+89
-14
lines changed

1 file changed

+89
-14
lines changed

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

Lines changed: 89 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Magento\Framework\Api\SortOrder;
1313
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
14+
use Magento\Quote\Model\QuoteRepository\LoadHandler;
1415

1516
class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
1617
{
@@ -54,6 +55,11 @@ class QuoteRepositoryTest extends \PHPUnit_Framework_TestCase
5455
*/
5556
private $extensionAttributesJoinProcessorMock;
5657

58+
/**
59+
* @var LoadHandler|\PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
private $loadHandlerMock;
62+
5763
protected function setUp()
5864
{
5965
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -107,6 +113,12 @@ protected function setUp()
107113
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock
108114
]
109115
);
116+
117+
$this->loadHandlerMock = $this->getMock(LoadHandler::class, [], [], '', false);
118+
$reflection = new \ReflectionClass(get_class($this->model));
119+
$reflectionProperty = $reflection->getProperty('loadHandler');
120+
$reflectionProperty->setAccessible(true);
121+
$reflectionProperty->setValue($this->model, $this->loadHandlerMock);
110122
}
111123

112124
/**
@@ -132,23 +144,74 @@ public function testGetWithExceptionById()
132144

133145
public function testGet()
134146
{
135-
$this->markTestSkipped('MAGETWO-48531');
136147
$cartId = 15;
137148

138-
$this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock);
139-
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
140-
$this->storeMock->expects($this->once())->method('getId')->willReturn(1);
141-
$this->quoteMock->expects($this->never())->method('setSharedStoreIds');
142-
$this->quoteMock->expects($this->once())
149+
$this->quoteFactoryMock->expects(static::once())
150+
->method('create')
151+
->willReturn($this->quoteMock);
152+
$this->storeManagerMock->expects(static::once())
153+
->method('getStore')
154+
->willReturn($this->storeMock);
155+
$this->storeMock->expects(static::once())
156+
->method('getId')
157+
->willReturn(1);
158+
$this->quoteMock->expects(static::never())
159+
->method('setSharedStoreIds');
160+
$this->quoteMock->expects(static::once())
143161
->method('load')
144162
->with($cartId)
145163
->willReturn($this->storeMock);
146-
$this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId);
164+
$this->quoteMock->expects(static::once())
165+
->method('getId')
166+
->willReturn($cartId);
167+
$this->quoteMock->expects(static::never())
168+
->method('getCustomerId');
169+
$this->loadHandlerMock->expects(static::once())
170+
->method('load')
171+
->with($this->quoteMock);
147172

148173
$this->assertEquals($this->quoteMock, $this->model->get($cartId));
149174
$this->assertEquals($this->quoteMock, $this->model->get($cartId));
150175
}
151176

177+
public function testGetForCustomerAfterGet()
178+
{
179+
$cartId = 15;
180+
$customerId = 23;
181+
182+
$this->quoteFactoryMock->expects(static::exactly(2))
183+
->method('create')
184+
->willReturn($this->quoteMock);
185+
$this->storeManagerMock->expects(static::exactly(2))
186+
->method('getStore')
187+
->willReturn($this->storeMock);
188+
$this->storeMock->expects(static::exactly(2))
189+
->method('getId')
190+
->willReturn(1);
191+
$this->quoteMock->expects(static::never())
192+
->method('setSharedStoreIds');
193+
$this->quoteMock->expects(static::once())
194+
->method('load')
195+
->with($cartId)
196+
->willReturn($this->storeMock);
197+
$this->quoteMock->expects(static::once())
198+
->method('loadByCustomer')
199+
->with($customerId)
200+
->willReturn($this->storeMock);
201+
$this->quoteMock->expects(static::exactly(3))
202+
->method('getId')
203+
->willReturn($cartId);
204+
$this->quoteMock->expects(static::any())
205+
->method('getCustomerId')
206+
->willReturn($customerId);
207+
$this->loadHandlerMock->expects(static::exactly(2))
208+
->method('load')
209+
->with($this->quoteMock);
210+
211+
$this->assertEquals($this->quoteMock, $this->model->get($cartId));
212+
$this->assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
213+
}
214+
152215
public function testGetWithSharedStoreIds()
153216
{
154217
$this->markTestSkipped('MAGETWO-48531');
@@ -174,19 +237,31 @@ public function testGetWithSharedStoreIds()
174237

175238
public function testGetForCustomer()
176239
{
177-
$this->markTestSkipped('MAGETWO-48531');
178240
$cartId = 17;
179241
$customerId = 23;
180242

181-
$this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock);
182-
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
183-
$this->storeMock->expects($this->once())->method('getId')->willReturn(1);
184-
$this->quoteMock->expects($this->never())->method('setSharedStoreIds');
185-
$this->quoteMock->expects($this->once())
243+
$this->quoteFactoryMock->expects(static::once())
244+
->method('create')
245+
->willReturn($this->quoteMock);
246+
$this->storeManagerMock->expects(static::once())
247+
->method('getStore')
248+
->willReturn($this->storeMock);
249+
$this->storeMock->expects(static::once())
250+
->method('getId')
251+
->willReturn(1);
252+
$this->quoteMock->expects(static::never())
253+
->method('setSharedStoreIds');
254+
$this->quoteMock->expects(static::once())
186255
->method('loadByCustomer')
187256
->with($customerId)
188257
->willReturn($this->storeMock);
189-
$this->quoteMock->expects($this->exactly(2))->method('getId')->willReturn($cartId);
258+
$this->quoteMock->expects(static::exactly(2))
259+
->method('getId')
260+
->willReturn($cartId);
261+
262+
$this->loadHandlerMock->expects(static::once())
263+
->method('load')
264+
->with($this->quoteMock);
190265

191266
$this->assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));
192267
$this->assertEquals($this->quoteMock, $this->model->getForCustomer($customerId));

0 commit comments

Comments
 (0)