|
| 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 | +use Magento\Quote\Test\Unit\Model\GuestCart\GuestCartTestHelper; |
| 10 | + |
| 11 | +class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @var \Magento\Quote\Model\GuestCart\GuestBillingAddressManagement |
| 15 | + */ |
| 16 | + protected $model; |
| 17 | + |
| 18 | + /** |
| 19 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 20 | + */ |
| 21 | + protected $quoteRepositoryMock; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 25 | + */ |
| 26 | + protected $validatorMock; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 30 | + */ |
| 31 | + protected $quoteIdMaskFactoryMock; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 35 | + */ |
| 36 | + protected $quoteIdMaskMock; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var string |
| 40 | + */ |
| 41 | + protected $maskedCartId; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var int |
| 45 | + */ |
| 46 | + protected $cartId; |
| 47 | + |
| 48 | + /** |
| 49 | + * @return void |
| 50 | + */ |
| 51 | + protected function setUp() |
| 52 | + { |
| 53 | + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 54 | + $this->quoteRepositoryMock = $this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false); |
| 55 | + $this->validatorMock = $this->getMock('\Magento\Quote\Model\QuoteAddressValidator', [], [], '', false); |
| 56 | + $logger = $this->getMock('\Psr\Log\LoggerInterface'); |
| 57 | + $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); |
| 58 | + $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); |
| 59 | + |
| 60 | + $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; |
| 61 | + $this->cartId = 11; |
| 62 | + |
| 63 | + $guestCartTestHelper = new GuestCartTestHelper($this); |
| 64 | + list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( |
| 65 | + $this->maskedCartId, |
| 66 | + $this->cartId |
| 67 | + ); |
| 68 | + |
| 69 | + $this->model = $objectManager->getObject( |
| 70 | + 'Magento\Quote\Model\GuestCart\GuestBillingAddressManagement', |
| 71 | + [ |
| 72 | + 'quoteRepository' => $this->quoteRepositoryMock, |
| 73 | + 'addressValidator' => $this->validatorMock, |
| 74 | + 'logger' => $logger, |
| 75 | + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock |
| 76 | + ] |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @return void |
| 82 | + */ |
| 83 | + public function testGetAddress() |
| 84 | + { |
| 85 | + $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); |
| 86 | + $this->quoteRepositoryMock->expects($this->once())->method('getActive') |
| 87 | + ->with($this->cartId )->will($this->returnValue($quoteMock)); |
| 88 | + |
| 89 | + $addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); |
| 90 | + $quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock)); |
| 91 | + |
| 92 | + $this->assertEquals($addressMock, $this->model->get($this->maskedCartId )); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * @return void |
| 97 | + */ |
| 98 | + public function testAssingAddress() |
| 99 | + { |
| 100 | + $address = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false, false); |
| 101 | + |
| 102 | + $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); |
| 103 | + $this->quoteRepositoryMock->expects($this->once()) |
| 104 | + ->method('getActive') |
| 105 | + ->with($this->cartId ) |
| 106 | + ->will($this->returnValue($quoteMock)); |
| 107 | + |
| 108 | + $this->validatorMock->expects($this->once())->method('validate') |
| 109 | + ->with($address) |
| 110 | + ->will($this->returnValue(true)); |
| 111 | + |
| 112 | + $quoteMock->expects($this->once())->method('setBillingAddress')->with($address); |
| 113 | + $quoteMock->expects($this->once())->method('setDataChanges')->with(true); |
| 114 | + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); |
| 115 | + $addressId = 1; |
| 116 | + $billingAddressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); |
| 117 | + $billingAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId)); |
| 118 | + $quoteMock->expects($this->once())->method('getBillingAddress') |
| 119 | + ->will($this->returnValue($billingAddressMock)); |
| 120 | + |
| 121 | + $this->assertEquals($addressId, $this->model->assign($this->maskedCartId , $address)); |
| 122 | + } |
| 123 | +} |
0 commit comments