1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Multishipping\Test\Unit\Controller\Checkout\Address;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class EditBillingTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Multishipping\Controller\Checkout\Address\EditBilling
*/
protected $controller;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $configMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $objectManagerMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $stateMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $viewMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $layoutMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $addressFormMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $urlMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $pageMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $titleMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $checkoutMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $request;
protected function setUp()
{
$objectManager = new ObjectManager($this);
$this->configMock = $this->createMock(\Magento\Framework\View\Page\Config::class);
$this->checkoutMock =
$this->createMock(\Magento\Multishipping\Model\Checkout\Type\Multishipping::class);
$this->titleMock = $this->createMock(\Magento\Framework\View\Page\Title::class);
$this->layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
$this->viewMock = $this->createMock(\Magento\Framework\App\ViewInterface::class);
$this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
$this->stateMock =
$this->createMock(\Magento\Multishipping\Model\Checkout\Type\Multishipping\State::class);
$valueMap = [
[\Magento\Multishipping\Model\Checkout\Type\Multishipping\State::class, $this->stateMock],
[\Magento\Multishipping\Model\Checkout\Type\Multishipping::class, $this->checkoutMock]
];
$this->objectManagerMock->expects($this->any())->method('get')->willReturnMap($valueMap);
$this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
->disableOriginalConstructor()
->setMethods([])
->getMockForAbstractClass();
$response = $this->getMockBuilder(\Magento\Framework\App\ResponseInterface::class)
->disableOriginalConstructor()
->setMethods([])
->getMockForAbstractClass();
$contextMock = $this->createMock(\Magento\Framework\App\Action\Context::class);
$contextMock->expects($this->atLeastOnce())
->method('getRequest')
->will($this->returnValue($this->request));
$contextMock->expects($this->atLeastOnce())
->method('getResponse')
->will($this->returnValue($response));
$contextMock->expects($this->any())->method('getView')->willReturn($this->viewMock);
$contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock);
$methods = ['setTitle', 'getTitle', 'setSuccessUrl', 'setBackUrl', 'setErrorUrl', '__wakeUp'];
$this->addressFormMock =
$this->createPartialMock(\Magento\Customer\Block\Address\Edit::class, $methods);
$this->urlMock = $this->createMock(\Magento\Framework\UrlInterface::class);
$contextMock->expects($this->any())->method('getUrl')->willReturn($this->urlMock);
$this->pageMock = $this->createMock(\Magento\Framework\View\Result\Page::class);
$this->pageMock->expects($this->any())->method('getConfig')->willReturn($this->configMock);
$this->configMock->expects($this->any())->method('getTitle')->willReturn($this->titleMock);
$this->viewMock->expects($this->any())->method('getPage')->willReturn($this->pageMock);
$this->controller = $objectManager->getObject(
\Magento\Multishipping\Controller\Checkout\Address\EditBilling::class,
['context' => $contextMock]
);
}
public function testExecute()
{
$this->stateMock
->expects($this->once())
->method('setActiveStep')
->with(\Magento\Multishipping\Model\Checkout\Type\Multishipping\State::STEP_BILLING);
$this->request->expects($this->once())->method('getParam')->with('id')->willReturn(1);
$this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf();
$this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
$this->layoutMock
->expects($this->once())
->method('getBlock')
->with('customer_address_edit')
->willReturn($this->addressFormMock);
$this->addressFormMock
->expects($this->once())
->method('setTitle')
->with('Edit Billing Address')
->willReturnSelf();
$helperMock = $this->createPartialMock(\Magento\Multishipping\Helper\Data::class, ['__']);
$helperMock->expects($this->any())->method('__')->willReturn('Edit Billing Address');
$this->addressFormMock->expects($this->once())->method('setSuccessUrl')->with('success/url')->willReturnSelf();
$this->addressFormMock->expects($this->once())->method('setErrorUrl')->with('error/url')->willReturnSelf();
$valueMap = [
['*/*/saveBilling', ['id' => 1], 'success/url'],
['*/*/*', ['id' => 1], 'error/url'],
['*/checkout/overview', null, 'back/address']
];
$this->urlMock->expects($this->any())->method('getUrl')->willReturnMap($valueMap);
$this->titleMock->expects($this->once())->method('getDefault')->willReturn('default_title');
$this->addressFormMock->expects($this->once())->method('getTitle')->willReturn('Address title');
$this->titleMock->expects($this->once())->method('set')->with('Address title - default_title');
$this->addressFormMock->expects($this->once())->method('setBackUrl')->with('back/address');
$this->viewMock->expects($this->once())->method('renderLayout');
$this->controller->execute();
}
public function testExecuteWhenCustomerAddressBlockNotExist()
{
$this->stateMock
->expects($this->once())
->method('setActiveStep')
->with(\Magento\Multishipping\Model\Checkout\Type\Multishipping\State::STEP_BILLING);
$this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf();
$this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
$this->layoutMock
->expects($this->once())
->method('getBlock')
->with('customer_address_edit');
$this->urlMock->expects($this->never())->method('getUrl');
$this->viewMock->expects($this->once())->method('renderLayout');
$this->controller->execute();
}
}