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(
121 'getDefaultLayoutHandle',
122 'addPageLayoutHandles',
123 'generateLayoutBlocks',
126 'addActionLayoutHandles',
132 $this->session = $this->createPartialMock(\
Magento\Backend\Model\Session::class, [
'setIsUrlNotice']);
133 $this->session->expects($this->any())->method(
'setIsUrlNotice')->willReturn($this->objectManager);
134 $this->actionFlag = $this->createPartialMock(\
Magento\Framework\
App\ActionFlag::class, [
'get']);
135 $this->actionFlag->expects($this->any())->method(
"get")->willReturn($this->objectManager);
136 $this->objectManager = $this->createPartialMock(
137 \
Magento\Framework\TestFramework\Unit\Helper\ObjectManager::class,
140 $this->request = $this->getMockForAbstractClass(
141 \
Magento\Framework\
App\RequestInterface::class,
142 [
'getParam',
'getRequest'],
147 $this->response->expects($this->any())->method(
"setRedirect")->willReturn(1);
148 $this->page = $this->createMock(\
Magento\Framework\View\Result\Page::class);
149 $this->config = $this->createMock(\
Magento\Framework\View\Result\Page::class);
150 $this->title = $this->createMock(\
Magento\Framework\View\Page\Title::class);
151 $this->messageManager = $this->getMockForAbstractClass(
152 \
Magento\Framework\Message\ManagerInterface::class,
153 [
'addError',
'addSuccess'],
158 $this->indexReg = $this->createPartialMock(
159 \
Magento\Framework\Indexer\IndexerRegistry::class,
160 [
'get',
'setScheduled']
162 $this->helper = $this->createPartialMock(\
Magento\Backend\Helper\Data::class, [
'getUrl']);
163 $this->contextMock->expects($this->any())->method(
"getObjectManager")->willReturn($this->objectManager);
164 $this->contextMock->expects($this->any())->method(
"getRequest")->willReturn($this->request);
165 $this->contextMock->expects($this->any())->method(
"getResponse")->willReturn($this->response);
166 $this->contextMock->expects($this->any())->method(
"getMessageManager")->willReturn($this->messageManager);
167 $this->contextMock->expects($this->any())->method(
"getSession")->willReturn($this->session);
168 $this->contextMock->expects($this->any())->method(
"getActionFlag")->willReturn($this->actionFlag);
169 $this->contextMock->expects($this->any())->method(
"getHelper")->willReturn($this->helper);
178 public function testExecute($indexerIds, $exception, $expectsExceptionValues)
180 $this->model = new \Magento\Indexer\Controller\Adminhtml\Indexer\MassOnTheFly($this->contextMock);
181 $this->request->expects($this->any())
182 ->method(
'getParam')->with(
'indexer_ids')
183 ->will($this->returnValue($indexerIds));
185 if (!is_array($indexerIds)) {
186 $this->messageManager->expects($this->once())
187 ->method(
'addError')->with(
__(
'Please select indexers.'))
188 ->will($this->returnValue(1));
190 $this->objectManager->expects($this->any())
191 ->method(
'get')->with(\
Magento\Framework\Indexer\IndexerRegistry::class)
192 ->will($this->returnValue($this->indexReg));
193 $indexerInterface = $this->getMockForAbstractClass(
194 \
Magento\Framework\Indexer\IndexerInterface::class,
199 $this->indexReg->expects($this->any())
200 ->method(
'get')->with(1)
201 ->will($this->returnValue($indexerInterface));
203 if ($exception !==
null) {
204 $indexerInterface->expects($this->any())
205 ->method(
'setScheduled')->with(
false)->will($this->throwException($exception));
207 $indexerInterface->expects($this->any())
208 ->method(
'setScheduled')->with(
false)->will($this->returnValue(1));
211 $this->messageManager->expects($this->any())->method(
'addSuccess')->will($this->returnValue(1));
213 if ($exception !==
null) {
214 $this->messageManager->expects($this->exactly($expectsExceptionValues[2]))
216 ->with($exception->getMessage());
217 $this->messageManager->expects($this->exactly($expectsExceptionValues[1]))
218 ->method(
'addException')
219 ->with($exception,
"We couldn't change indexer(s)' mode because of an error.");
223 $this->helper->expects($this->any())->method(
"getUrl")->willReturn(
"magento.com");
224 $this->response->expects($this->any())->method(
"setRedirect")->willReturn(1);
226 $result = $this->model->execute();
239 "expectsValues" => [0, 0, 0]
244 "expectsException" => [1, 0, 0]
248 "exception" => new \Magento\Framework\Exception\LocalizedException(
__(
'Test Phrase')),
249 "expectsException" => [0, 0, 1]
253 "exception" => new \Exception(),
254 "expectsException" => [0, 1, 0]
testExecute($indexerIds, $exception, $expectsExceptionValues)