Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EditBillingTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class EditBillingTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $controller;
20 
24  protected $configMock;
25 
29  protected $objectManagerMock;
30 
34  protected $stateMock;
35 
39  protected $viewMock;
40 
44  protected $layoutMock;
45 
49  protected $addressFormMock;
50 
54  protected $urlMock;
55 
59  protected $pageMock;
60 
64  protected $titleMock;
65 
69  protected $checkoutMock;
70 
74  protected $request;
75 
76  protected function setUp()
77  {
78  $objectManager = new ObjectManager($this);
79  $this->configMock = $this->createMock(\Magento\Framework\View\Page\Config::class);
80  $this->checkoutMock =
81  $this->createMock(\Magento\Multishipping\Model\Checkout\Type\Multishipping::class);
82  $this->titleMock = $this->createMock(\Magento\Framework\View\Page\Title::class);
83  $this->layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
84  $this->viewMock = $this->createMock(\Magento\Framework\App\ViewInterface::class);
85  $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
86  $this->stateMock =
87  $this->createMock(\Magento\Multishipping\Model\Checkout\Type\Multishipping\State::class);
88  $valueMap = [
89  [\Magento\Multishipping\Model\Checkout\Type\Multishipping\State::class, $this->stateMock],
90  [\Magento\Multishipping\Model\Checkout\Type\Multishipping::class, $this->checkoutMock]
91  ];
92  $this->objectManagerMock->expects($this->any())->method('get')->willReturnMap($valueMap);
93  $this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
94  ->disableOriginalConstructor()
95  ->setMethods([])
96  ->getMockForAbstractClass();
97  $response = $this->getMockBuilder(\Magento\Framework\App\ResponseInterface::class)
98  ->disableOriginalConstructor()
99  ->setMethods([])
100  ->getMockForAbstractClass();
101  $contextMock = $this->createMock(\Magento\Framework\App\Action\Context::class);
102  $contextMock->expects($this->atLeastOnce())
103  ->method('getRequest')
104  ->will($this->returnValue($this->request));
105  $contextMock->expects($this->atLeastOnce())
106  ->method('getResponse')
107  ->will($this->returnValue($response));
108  $contextMock->expects($this->any())->method('getView')->willReturn($this->viewMock);
109  $contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock);
110  $methods = ['setTitle', 'getTitle', 'setSuccessUrl', 'setBackUrl', 'setErrorUrl', '__wakeUp'];
111  $this->addressFormMock =
112  $this->createPartialMock(\Magento\Customer\Block\Address\Edit::class, $methods);
113  $this->urlMock = $this->createMock(\Magento\Framework\UrlInterface::class);
114  $contextMock->expects($this->any())->method('getUrl')->willReturn($this->urlMock);
115  $this->pageMock = $this->createMock(\Magento\Framework\View\Result\Page::class);
116  $this->pageMock->expects($this->any())->method('getConfig')->willReturn($this->configMock);
117  $this->configMock->expects($this->any())->method('getTitle')->willReturn($this->titleMock);
118  $this->viewMock->expects($this->any())->method('getPage')->willReturn($this->pageMock);
119  $this->controller = $objectManager->getObject(
120  \Magento\Multishipping\Controller\Checkout\Address\EditBilling::class,
121  ['context' => $contextMock]
122  );
123  }
124 
125  public function testExecute()
126  {
127  $this->stateMock
128  ->expects($this->once())
129  ->method('setActiveStep')
130  ->with(\Magento\Multishipping\Model\Checkout\Type\Multishipping\State::STEP_BILLING);
131  $this->request->expects($this->once())->method('getParam')->with('id')->willReturn(1);
132  $this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf();
133  $this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
134  $this->layoutMock
135  ->expects($this->once())
136  ->method('getBlock')
137  ->with('customer_address_edit')
138  ->willReturn($this->addressFormMock);
139  $this->addressFormMock
140  ->expects($this->once())
141  ->method('setTitle')
142  ->with('Edit Billing Address')
143  ->willReturnSelf();
144  $helperMock = $this->createPartialMock(\Magento\Multishipping\Helper\Data::class, ['__']);
145  $helperMock->expects($this->any())->method('__')->willReturn('Edit Billing Address');
146  $this->addressFormMock->expects($this->once())->method('setSuccessUrl')->with('success/url')->willReturnSelf();
147  $this->addressFormMock->expects($this->once())->method('setErrorUrl')->with('error/url')->willReturnSelf();
148  $valueMap = [
149  ['*/*/saveBilling', ['id' => 1], 'success/url'],
150  ['*/*/*', ['id' => 1], 'error/url'],
151  ['*/checkout/overview', null, 'back/address']
152  ];
153  $this->urlMock->expects($this->any())->method('getUrl')->willReturnMap($valueMap);
154  $this->titleMock->expects($this->once())->method('getDefault')->willReturn('default_title');
155  $this->addressFormMock->expects($this->once())->method('getTitle')->willReturn('Address title');
156  $this->titleMock->expects($this->once())->method('set')->with('Address title - default_title');
157  $this->addressFormMock->expects($this->once())->method('setBackUrl')->with('back/address');
158  $this->viewMock->expects($this->once())->method('renderLayout');
159  $this->controller->execute();
160  }
161 
163  {
164  $this->stateMock
165  ->expects($this->once())
166  ->method('setActiveStep')
167  ->with(\Magento\Multishipping\Model\Checkout\Type\Multishipping\State::STEP_BILLING);
168  $this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf();
169  $this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
170  $this->layoutMock
171  ->expects($this->once())
172  ->method('getBlock')
173  ->with('customer_address_edit');
174  $this->urlMock->expects($this->never())->method('getUrl');
175  $this->viewMock->expects($this->once())->method('renderLayout');
176  $this->controller->execute();
177  }
178 }
$response
Definition: 404.php:11
$objectManager
Definition: bootstrap.php:17
$methods
Definition: billing.phtml:71