123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- /**
- *
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Quote\Test\Unit\Model\GuestCart;
- class GuestCartManagementTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $quoteManagementMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $quoteRepositoryMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $quoteIdMaskFactoryMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $quoteIdMaskMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $cartRepositoryMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $quoteMock;
- /**
- * @var \Magento\Quote\Model\GuestCart\GuestCartManagement
- */
- protected $guestCartManagement;
- protected function setUp()
- {
- $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->quoteManagementMock = $this->getMockForAbstractClass(
- \Magento\Quote\Api\CartManagementInterface::class,
- [],
- '',
- false,
- true,
- true,
- []
- );
- $this->quoteIdMaskFactoryMock = $this->createPartialMock(
- \Magento\Quote\Model\QuoteIdMaskFactory::class,
- ['create']
- );
- $this->quoteIdMaskMock = $this->createPartialMock(
- \Magento\Quote\Model\QuoteIdMask::class,
- ['getQuoteId', 'getMaskedId', 'load', 'save', 'setQuoteId']
- );
- $this->cartRepositoryMock = $this->createMock(\Magento\Quote\Api\CartRepositoryInterface::class);
- $this->quoteMock = $this->getMockForAbstractClass(
- \Magento\Quote\Api\Data\CartInterface::class,
- [],
- '',
- false,
- true,
- true,
- ['setCheckoutMethod']
- );
- $this->guestCartManagement = $objectManager->getObject(
- \Magento\Quote\Model\GuestCart\GuestCartManagement::class,
- [
- 'quoteManagement' => $this->quoteManagementMock,
- 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock,
- 'cartRepository' => $this->cartRepositoryMock
- ]
- );
- }
- public function testCreateEmptyCart()
- {
- $maskedCartId = 'masked1cart2id3';
- $cartId = 1;
- $this->quoteIdMaskMock->expects($this->once())->method('setQuoteId')->with($cartId)->willReturnSelf();
- $this->quoteIdMaskMock->expects($this->once())->method('save')->willReturnSelf();
- $this->quoteIdMaskMock->expects($this->once())->method('getMaskedId')->willReturn($maskedCartId);
- $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
- $this->quoteManagementMock->expects($this->once())->method('createEmptyCart')->willReturn($cartId);
- $this->assertEquals($maskedCartId, $this->guestCartManagement->createEmptyCart());
- }
- public function testAssignCustomer()
- {
- $maskedCartId = 'masked1cart2id3';
- $cartId = 1;
- $customerId = 1;
- $storeId = 1;
- $this->quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf();
- $this->quoteIdMaskMock->expects($this->once())->method('getQuoteId')->willReturn($maskedCartId);
- $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
- $this->quoteManagementMock->expects($this->once())->method('assignCustomer')->willReturn(true);
- $this->assertEquals(true, $this->guestCartManagement->assignCustomer($cartId, $customerId, $storeId));
- }
- public function testPlaceOrder()
- {
- $maskedCartId = 'masked1cart2id3';
- $cartId = 1;
- $orderId = 1;
- $this->quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf();
- $this->cartRepositoryMock->expects($this->once())->method('get')->willReturn($this->quoteMock);
- $this->quoteMock->expects($this->once())->method('setCheckoutMethod');
- $this->quoteIdMaskMock->expects($this->any())->method('getQuoteId')->willReturn($maskedCartId);
- $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
- $this->quoteManagementMock->expects($this->once())->method('placeOrder')->willReturn($orderId);
- $this->assertEquals($orderId, $this->guestCartManagement->placeOrder($cartId));
- }
- }
|