Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ListActionTest.php
Go to the documentation of this file.
1 <?php
8 
9 class ListActionTest extends \PHPUnit\Framework\TestCase
10 {
14  protected $object;
15 
19  protected $contextMock;
20 
24  protected $block;
25 
29  protected $layout;
30 
34  protected $view;
35 
39  protected $page;
40 
44  protected $menu;
45 
49  protected $config;
50 
54  protected $items;
55 
59  protected $title;
60 
65  protected function setUp()
66  {
67  $this->contextMock = $this->createPartialMock(\Magento\Backend\App\Action\Context::class, [
68  'getAuthorization',
69  'getSession',
70  'getActionFlag',
71  'getAuth',
72  'getView',
73  'getHelper',
74  'getBackendUrl',
75  'getFormKeyValidator',
76  'getLocaleResolver',
77  'getCanUseBaseUrl',
78  'getRequest',
79  'getResponse',
80  'getObjectManager',
81  'getMessageManager'
82  ]);
83 
84  $this->response = $this->createPartialMock(
85  \Magento\Framework\App\ResponseInterface::class,
86  ['setRedirect', 'sendResponse']
87  );
88 
89  $this->request = $this->getMockForAbstractClass(
90  \Magento\Framework\App\RequestInterface::class,
91  ['getParam', 'getRequest'],
92  '',
93  false
94  );
95 
96  $this->view = $this->createPartialMock(\Magento\Framework\App\ViewInterface::class, [
97  'loadLayout',
98  'getPage',
99  'getConfig',
100  'getTitle',
101  'loadLayoutUpdates',
102  'renderLayout',
103  'getDefaultLayoutHandle',
104  'generateLayoutXml',
105  'addPageLayoutHandles',
106  'generateLayoutBlocks',
107  'getLayout',
108  'addActionLayoutHandles',
109  'setIsLayoutLoaded',
110  'isLayoutLoaded'
111  ]);
112 
113  $this->block = $this->createPartialMock(
114  \Magento\Framework\View\Element\AbstractBlock::class,
115  ['setActive', 'getMenuModel']
116  );
117 
118  $this->layout = $this->getMockForAbstractClass(
119  \Magento\Framework\View\LayoutInterface::class,
120  ['getBlock'],
121  '',
122  false
123  );
124 
125  $this->menu = $this->createPartialMock(\Magento\Backend\Model\Menu::class, ['getParentItems']);
126 
127  $this->items = $this->createPartialMock(\Magento\Backend\Model\Menu\Item::class, ['getParentItems']);
128 
129  $this->contextMock->expects($this->any())->method("getRequest")->willReturn($this->request);
130  $this->contextMock->expects($this->any())->method("getResponse")->willReturn($this->response);
131  $this->contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->view));
132 
133  $this->page = $this->createPartialMock(\Magento\Framework\View\Result\Page::class, ['getConfig']);
134  $this->config = $this->createPartialMock(\Magento\Framework\View\Result\Page::class, ['getTitle']);
135  $this->title = $this->getMockBuilder('Title')
136  ->setMethods(['prepend'])
137  ->getMock();
138 
139  $this->block->expects($this->any())->method('setActive')->will($this->returnValue(1));
140  $this->view->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout));
141  $this->layout->expects($this->any())->method('getBlock')->with('menu')->will($this->returnValue($this->block));
142  $this->block->expects($this->any())->method('getMenuModel')->will($this->returnValue($this->menu));
143  $this->menu->expects($this->any())->method('getParentItems')->will($this->returnValue($this->items));
144 
145  $this->object = new \Magento\Indexer\Controller\Adminhtml\Indexer\ListAction($this->contextMock);
146  }
147 
148  public function testExecute()
149  {
150  $this->view->expects($this->any())
151  ->method('loadLayout')
152  ->will($this->returnValue(1));
153 
154  $this->view->expects($this->any())
155  ->method('getPage')
156  ->will($this->returnValue($this->page));
157 
158  $this->page->expects($this->any())
159  ->method('getConfig')
160  ->will($this->returnValue($this->config));
161 
162  $this->config->expects($this->any())
163  ->method('getTitle')
164  ->will($this->returnValue($this->title));
165 
166  $this->title->expects($this->any())
167  ->method('prepend')->with(__('Index Management'))
168  ->will($this->returnValue(1));
169 
170  $this->view->expects($this->any())
171  ->method('renderLayout')
172  ->will($this->returnValue(1));
173 
174  $result = $this->object->execute();
175  $this->assertNull($result);
176  }
177 }
__()
Definition: __.php:13