|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * |
| 4 | + * Copyright © 2015 Magento. All rights reserved. |
| 5 | + * See COPYING.txt for license details. |
| 6 | + */ |
| 7 | +namespace Magento\Quote\Test\Unit\Model\GuestCart; |
| 8 | + |
| 9 | +class GuestCartTotalRepositoryTest extends \PHPUnit_Framework_TestCase |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @var \Magento\Quote\Model\GuestCart\GuestCartTotalRepository |
| 13 | + */ |
| 14 | + protected $model; |
| 15 | + |
| 16 | + /** |
| 17 | + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager |
| 18 | + */ |
| 19 | + protected $objectManager; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 23 | + */ |
| 24 | + private $quoteRepositoryMock; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 28 | + */ |
| 29 | + private $quoteMock; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 33 | + */ |
| 34 | + private $totalsFactoryMock; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 38 | + */ |
| 39 | + protected $addressMock; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject |
| 43 | + */ |
| 44 | + private $dataObjectHelperMock; |
| 45 | + |
| 46 | + /** |
| 47 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 48 | + */ |
| 49 | + protected $quoteIdMaskFactoryMock; |
| 50 | + |
| 51 | + /** |
| 52 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 53 | + */ |
| 54 | + protected $quoteIdMaskMock; |
| 55 | + |
| 56 | + public function setUp() |
| 57 | + { |
| 58 | + $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 59 | + $this->totalsFactoryMock = $this->getMock( |
| 60 | + 'Magento\Quote\Api\Data\TotalsInterfaceFactory', |
| 61 | + ['create'], |
| 62 | + [], |
| 63 | + '', |
| 64 | + false |
| 65 | + ); |
| 66 | + $this->quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); |
| 67 | + $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); |
| 68 | + $this->addressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false); |
| 69 | + $this->dataObjectHelperMock = $this->getMockBuilder('\Magento\Framework\Api\DataObjectHelper') |
| 70 | + ->disableOriginalConstructor() |
| 71 | + ->getMock(); |
| 72 | + $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); |
| 73 | + $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); |
| 74 | + |
| 75 | + $this->model = $this->objectManager->getObject( |
| 76 | + 'Magento\Quote\Model\GuestCart\GuestCartTotalRepository', |
| 77 | + [ |
| 78 | + 'totalsFactory' => $this->totalsFactoryMock, |
| 79 | + 'quoteRepository' => $this->quoteRepositoryMock, |
| 80 | + 'dataObjectHelper' => $this->dataObjectHelperMock, |
| 81 | + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock |
| 82 | + ] |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + public function testGetTotals() |
| 87 | + { |
| 88 | + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; |
| 89 | + $cartId = 12; |
| 90 | + |
| 91 | + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); |
| 92 | + $this->quoteIdMaskMock->expects($this->once()) |
| 93 | + ->method('load') |
| 94 | + ->with($maskedCartId, 'masked_id') |
| 95 | + ->willReturn($this->quoteIdMaskMock); |
| 96 | + $this->quoteIdMaskMock->expects($this->once()) |
| 97 | + ->method('getId') |
| 98 | + ->willReturn($cartId); |
| 99 | + |
| 100 | + $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId) |
| 101 | + ->will($this->returnValue($this->quoteMock)); |
| 102 | + $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressMock); |
| 103 | + $this->addressMock->expects($this->once())->method('getData')->willReturn(['addressData']); |
| 104 | + $this->quoteMock->expects($this->once())->method('getData')->willReturn(['quoteData']); |
| 105 | + |
| 106 | + $item = $this->getMock('Magento\Quote\Model\Quote\Item', [], [], '', false); |
| 107 | + $this->quoteMock->expects($this->once())->method('getAllItems')->will($this->returnValue([$item])); |
| 108 | + |
| 109 | + $totals = $this->getMock('Magento\Quote\Model\Cart\Totals', ['setItems'], [], '', false); |
| 110 | + $this->totalsFactoryMock->expects($this->once())->method('create')->willReturn($totals); |
| 111 | + $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray'); |
| 112 | + $totals->expects($this->once())->method('setItems'); |
| 113 | + |
| 114 | + $this->model->get($maskedCartId); |
| 115 | + } |
| 116 | +} |
0 commit comments