|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Multishipping\Test\Unit\Model\Cart\Controller; |
| 7 | + |
| 8 | +class CartPluginTest extends \PHPUnit_Framework_TestCase |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @var \Magento\Multishipping\Model\Cart\Controller\CartPlugin |
| 12 | + */ |
| 13 | + private $model; |
| 14 | + |
| 15 | + /** |
| 16 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 17 | + */ |
| 18 | + private $cartRepositoryMock; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 22 | + */ |
| 23 | + private $checkoutSessionMock; |
| 24 | + |
| 25 | + protected function setUp() |
| 26 | + { |
| 27 | + $this->cartRepositoryMock = $this->getMock('\Magento\Quote\Api\CartRepositoryInterface'); |
| 28 | + $this->checkoutSessionMock = $this->getMock('\Magento\Checkout\Model\Session', [], [], '', false); |
| 29 | + $this->model = new \Magento\Multishipping\Model\Cart\Controller\CartPlugin( |
| 30 | + $this->cartRepositoryMock, |
| 31 | + $this->checkoutSessionMock |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + public function testBeforeDispatch() |
| 36 | + { |
| 37 | + $addressId = 100; |
| 38 | + $quoteMock = $this->getMock( |
| 39 | + '\Magento\Quote\Model\Quote', |
| 40 | + [ |
| 41 | + 'isMultipleShippingAddresses', |
| 42 | + 'getAllShippingAddresses', |
| 43 | + 'removeAddress', |
| 44 | + 'getShippingAddress', |
| 45 | + 'setIsMultiShipping', |
| 46 | + 'collectTotals' |
| 47 | + ], |
| 48 | + [], |
| 49 | + '', |
| 50 | + false |
| 51 | + ); |
| 52 | + $this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($quoteMock); |
| 53 | + |
| 54 | + $addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); |
| 55 | + $addressMock->expects($this->once())->method('getId')->willReturn($addressId); |
| 56 | + |
| 57 | + $quoteMock->expects($this->once())->method('isMultipleShippingAddresses')->willReturn(true); |
| 58 | + $quoteMock->expects($this->once())->method('getAllShippingAddresses')->willReturn([$addressMock]); |
| 59 | + $quoteMock->expects($this->once())->method('removeAddress')->with($addressId)->willReturnSelf(); |
| 60 | + $quoteMock->expects($this->once())->method('getShippingAddress'); |
| 61 | + $quoteMock->expects($this->once())->method('setIsMultiShipping')->with(false)->willReturnSelf(); |
| 62 | + $quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf(); |
| 63 | + |
| 64 | + $this->cartRepositoryMock->expects($this->once())->method('save')->with($quoteMock); |
| 65 | + |
| 66 | + $this->model->beforeDispatch( |
| 67 | + $this->getMock('\Magento\Checkout\Controller\Cart', [], [], '', false), |
| 68 | + $this->getMock('\Magento\Framework\App\RequestInterface') |
| 69 | + ); |
| 70 | + } |
| 71 | +} |
0 commit comments