|
9 | 9 | */
|
10 | 10 | namespace Magento\Checkout\Test\Unit\Model;
|
11 | 11 |
|
12 |
| -use \Magento\Checkout\Model\Session; |
| 12 | +use Magento\Checkout\Model\Session; |
| 13 | +use Magento\Framework\Exception\NoSuchEntityException; |
13 | 14 |
|
14 | 15 | /**
|
15 | 16 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
@@ -374,6 +375,60 @@ public function testGetStepData()
|
374 | 375 | $this->assertEquals($stepData['complex']['key'], $session->getStepData('complex', 'key'));
|
375 | 376 | }
|
376 | 377 |
|
| 378 | + /** |
| 379 | + * Ensure that if quote not exist for customer quote will be null |
| 380 | + * |
| 381 | + * @return void |
| 382 | + */ |
| 383 | + public function testGetQuote(): void |
| 384 | + { |
| 385 | + $quoteRepository = $this->createMock(\Magento\Quote\Api\CartRepositoryInterface::class); |
| 386 | + $storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class); |
| 387 | + $customerSession = $this->createMock(\Magento\Customer\Model\Session::class); |
| 388 | + $quoteFactory = $this->createMock(\Magento\Quote\Model\QuoteFactory::class); |
| 389 | + $quote = $this->createMock(\Magento\Quote\Model\Quote::class); |
| 390 | + |
| 391 | + $quoteFactory->expects($this->once()) |
| 392 | + ->method('create') |
| 393 | + ->willReturn($quote); |
| 394 | + $customerSession->expects($this->exactly(3)) |
| 395 | + ->method('isLoggedIn') |
| 396 | + ->willReturn(true); |
| 397 | + $store = $this->getMockBuilder(\Magento\Store\Model\Store::class) |
| 398 | + ->disableOriginalConstructor() |
| 399 | + ->setMethods(['getWebsiteId', '__wakeup']) |
| 400 | + ->getMock(); |
| 401 | + $storeManager->expects($this->any()) |
| 402 | + ->method('getStore') |
| 403 | + ->will($this->returnValue($store)); |
| 404 | + $storage = $this->getMockBuilder(\Magento\Framework\Session\Storage::class) |
| 405 | + ->disableOriginalConstructor() |
| 406 | + ->setMethods(['setData', 'getData']) |
| 407 | + ->getMock(); |
| 408 | + $storage->expects($this->at(0)) |
| 409 | + ->method('getData') |
| 410 | + ->willReturn(1); |
| 411 | + $quoteRepository->expects($this->once()) |
| 412 | + ->method('getActiveForCustomer') |
| 413 | + ->willThrowException(new NoSuchEntityException()); |
| 414 | + $quote->expects($this->once()) |
| 415 | + ->method('setCustomer') |
| 416 | + ->with(null); |
| 417 | + |
| 418 | + $constructArguments = $this->_helper->getConstructArguments( |
| 419 | + \Magento\Checkout\Model\Session::class, |
| 420 | + [ |
| 421 | + 'storeManager' => $storeManager, |
| 422 | + 'quoteRepository' => $quoteRepository, |
| 423 | + 'customerSession' => $customerSession, |
| 424 | + 'storage' => $storage, |
| 425 | + 'quoteFactory' => $quoteFactory |
| 426 | + ] |
| 427 | + ); |
| 428 | + $this->_session = $this->_helper->getObject(\Magento\Checkout\Model\Session::class, $constructArguments); |
| 429 | + $this->_session->getQuote(); |
| 430 | + } |
| 431 | + |
377 | 432 | public function testSetStepData()
|
378 | 433 | {
|
379 | 434 | $stepData = [
|
|
0 commit comments