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