90 $this->contextMock = $this->createPartialMock(\
Magento\Backend\
App\Action\Context::class, [
98 'getFormKeyValidator',
107 $this->response = $this->createPartialMock(
108 \
Magento\Framework\
App\ResponseInterface::class,
109 [
'setRedirect',
'sendResponse']
112 $this->view = $this->createPartialMock(\
Magento\Framework\
App\ViewInterface::class, [
119 'getDefaultLayoutHandle',
120 'addPageLayoutHandles',
121 'generateLayoutBlocks',
124 'addActionLayoutHandles',
129 $this->session = $this->createPartialMock(\
Magento\Backend\Model\Session::class, [
'setIsUrlNotice']);
130 $this->session->expects($this->any())->method(
'setIsUrlNotice')->willReturn($this->objectManager);
131 $this->actionFlag = $this->createPartialMock(\
Magento\Framework\
App\ActionFlag::class, [
'get']);
132 $this->actionFlag->expects($this->any())->method(
"get")->willReturn($this->objectManager);
133 $this->objectManager = $this->createPartialMock(
134 \
Magento\Framework\TestFramework\Unit\Helper\ObjectManager::class,
137 $this->request = $this->getMockForAbstractClass(
138 \
Magento\Framework\
App\RequestInterface::class,
139 [
'getParam',
'getRequest'],
144 $this->response->expects($this->any())->method(
"setRedirect")->willReturn(1);
145 $this->page = $this->createMock(\
Magento\Framework\View\Result\Page::class);
146 $this->config = $this->createMock(\
Magento\Framework\View\Result\Page::class);
147 $this->title = $this->createMock(\
Magento\Framework\View\Page\Title::class);
148 $this->messageManager = $this->getMockForAbstractClass(
149 \
Magento\Framework\Message\ManagerInterface::class,
150 [
'addError',
'addSuccess'],
155 $this->indexReg = $this->createPartialMock(
156 \
Magento\Framework\Indexer\IndexerRegistry::class,
157 [
'get',
'setScheduled']
159 $this->helper = $this->createPartialMock(\
Magento\Backend\Helper\Data::class, [
'getUrl']);
160 $this->contextMock->expects($this->any())->method(
"getObjectManager")->willReturn($this->objectManager);
161 $this->contextMock->expects($this->any())->method(
"getRequest")->willReturn($this->request);
162 $this->contextMock->expects($this->any())->method(
"getResponse")->willReturn($this->response);
163 $this->contextMock->expects($this->any())->method(
"getMessageManager")->willReturn($this->messageManager);
164 $this->contextMock->expects($this->any())->method(
"getSession")->willReturn($this->session);
165 $this->contextMock->expects($this->any())->method(
"getActionFlag")->willReturn($this->actionFlag);
166 $this->contextMock->expects($this->any())->method(
"getHelper")->willReturn($this->helper);
175 public function testExecute($indexerIds, $exception, $expectsExceptionValues)
177 $this->model = new \Magento\Indexer\Controller\Adminhtml\Indexer\MassChangelog($this->contextMock);
178 $this->request->expects($this->any())
179 ->method(
'getParam')->with(
'indexer_ids')
180 ->will($this->returnValue($indexerIds));
182 if (!is_array($indexerIds)) {
183 $this->messageManager->expects($this->once())
184 ->method(
'addError')->with(
__(
'Please select indexers.'))
185 ->will($this->returnValue(1));
187 $this->objectManager->expects($this->any())
188 ->method(
'get')->with(\
Magento\Framework\Indexer\IndexerRegistry::class)
189 ->will($this->returnValue($this->indexReg));
190 $indexerInterface = $this->getMockForAbstractClass(
191 \
Magento\Framework\Indexer\IndexerInterface::class,
196 $this->indexReg->expects($this->any())
197 ->method(
'get')->with(1)
198 ->will($this->returnValue($indexerInterface));
200 if ($exception !==
null) {
201 $indexerInterface->expects($this->any())
202 ->method(
'setScheduled')->with(
true)->will($this->throwException($exception));
204 $indexerInterface->expects($this->any())
205 ->method(
'setScheduled')->with(
true)->will($this->returnValue(1));
208 $this->messageManager->expects($this->any())->method(
'addSuccess')->will($this->returnValue(1));
210 if ($exception !==
null) {
211 $this->messageManager
212 ->expects($this->exactly($expectsExceptionValues[2]))
214 ->with($exception->getMessage());
215 $this->messageManager->expects($this->exactly($expectsExceptionValues[1]))
216 ->method(
'addException')
217 ->with($exception,
"We couldn't change indexer(s)' mode because of an error.");
221 $this->helper->expects($this->any())->method(
"getUrl")->willReturn(
"magento.com");
222 $this->response->expects($this->any())->method(
"setRedirect")->willReturn(1);
224 $result = $this->model->execute();
237 "expectsValues" => [0, 0, 0]
242 "expectsException" => [1, 0, 0]
246 "exception" => new \Magento\Framework\Exception\LocalizedException(
__(
'Test Phrase')),
247 "expectsException" => [0, 0, 1]
251 "exception" => new \Exception(),
252 "expectsException" => [0, 1, 0]
testExecute($indexerIds, $exception, $expectsExceptionValues)