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