Skip to content

Commit fe686ca

Browse files
committed
MAGETWO-36381: Magento\Quote\Api\GuestShippingAddressManagement
- added unit tests
1 parent 7d359ba commit fe686ca

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
// @codingStandardsIgnoreFile
9+
10+
namespace Magento\Quote\Test\Unit\Model\GuestCart;
11+
12+
class GuestShippingAddressManagementTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var \Magento\Quote\Api\GuestShippingAddressManagementInterface
16+
*/
17+
protected $model;
18+
19+
/**
20+
* @var \PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
protected $quoteRepositoryMock;
23+
24+
/**
25+
* @var \PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
protected $quoteAddressMock;
28+
29+
/**
30+
* @var \PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
protected $validatorMock;
33+
34+
/**
35+
* @var \PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
protected $quoteIdMaskFactoryMock;
38+
39+
/**
40+
* @var \PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
protected $quoteIdMaskMock;
43+
44+
protected function setUp()
45+
{
46+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
47+
48+
$this->quoteRepositoryMock = $this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false);
49+
$this->quoteAddressMock = $this->getMock( '\Magento\Quote\Model\Quote\Address', [], [], '', false);
50+
$this->validatorMock = $this->getMock( 'Magento\Quote\Model\QuoteAddressValidator', [], [], '', false);
51+
$this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false);
52+
$this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false);
53+
$this->model = $objectManager->getObject(
54+
'Magento\Quote\Model\GuestCart\GuestShippingAddressManagement',
55+
[
56+
'quoteRepository' => $this->quoteRepositoryMock,
57+
'addressValidator' => $this->validatorMock,
58+
'logger' => $this->getMock('\Psr\Log\LoggerInterface'),
59+
'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock
60+
]
61+
);
62+
}
63+
64+
public function testAssignAddress()
65+
{
66+
$maskedCartId = 'f216207248d65c789b17be8545e0aa73';
67+
$cartId = 867;
68+
69+
$this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
70+
$this->quoteIdMaskMock->expects($this->once())
71+
->method('load')
72+
->with($maskedCartId, 'masked_id')
73+
->willReturn($this->quoteIdMaskMock);
74+
$this->quoteIdMaskMock->expects($this->once())
75+
->method('getId')
76+
->willReturn($cartId);
77+
78+
$quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false);
79+
$this->quoteRepositoryMock->expects($this->once())
80+
->method('getActive')
81+
->with($cartId)
82+
->will($this->returnValue($quoteMock));
83+
$quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false));
84+
85+
86+
$this->validatorMock->expects($this->once())->method('validate')
87+
->with($this->quoteAddressMock)
88+
->will($this->returnValue(true));
89+
90+
$quoteMock->expects($this->once())->method('setShippingAddress')->with($this->quoteAddressMock);
91+
$quoteMock->expects($this->once())->method('setDataChanges')->with(true);
92+
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock);
93+
94+
$addressId = 1;
95+
$shippingAddressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false);
96+
$shippingAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId));
97+
$quoteMock->expects($this->once())->method('getShippingAddress')
98+
->will($this->returnValue($shippingAddressMock));
99+
100+
$this->assertEquals($addressId, $this->model->assign($maskedCartId, $this->quoteAddressMock));
101+
}
102+
103+
public function testGetAddress()
104+
{
105+
$maskedCartId = 'f216207248d65c789b17be8545e0aa73';
106+
$cartId = 867;
107+
108+
$this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
109+
$this->quoteIdMaskMock->expects($this->once())
110+
->method('load')
111+
->with($maskedCartId, 'masked_id')
112+
->willReturn($this->quoteIdMaskMock);
113+
$this->quoteIdMaskMock->expects($this->once())
114+
->method('getId')
115+
->willReturn($cartId);
116+
117+
$quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false);
118+
$this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will(
119+
$this->returnValue($quoteMock)
120+
);
121+
122+
$addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false);
123+
$quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($addressMock));
124+
$quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue(false));
125+
$this->assertEquals($addressMock, $this->model->get($maskedCartId));
126+
}
127+
}

0 commit comments

Comments
 (0)