27 private $objectManagerHelper;
37 private $responseMock;
42 private $uiFactoryMock;
52 private $authorizationMock;
62 private $actionFlagMock;
72 private $uiComponentContextMock;
78 private $dataProviderMock;
83 private $uiComponentMock;
88 private $uiComponentTypeResolverMock;
93 private $resultJsonFactoryMock;
102 $this->requestMock = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
103 ->disableOriginalConstructor()
105 $this->responseMock = $this->getMockBuilder(\
Magento\Framework\
App\
Response\Http::class)
106 ->disableOriginalConstructor()
108 $this->contextMock = $this->getMockBuilder(\
Magento\Backend\
App\Action\Context::class)
109 ->disableOriginalConstructor()
111 $this->uiFactoryMock = $this->getMockBuilder(\
Magento\Framework\View\Element\UiComponentFactory::class)
112 ->disableOriginalConstructor()
114 $this->authorizationMock = $this->getMockBuilder(\
Magento\Framework\AuthorizationInterface::class)
115 ->getMockForAbstractClass();
116 $this->sessionMock = $this->getMockBuilder(\
Magento\Backend\Model\Session::class)
117 ->disableOriginalConstructor()
119 $this->actionFlagMock = $this->getMockBuilder(\
Magento\Framework\
App\ActionFlag::class)
120 ->disableOriginalConstructor()
122 $this->helperMock = $this->getMockBuilder(\
Magento\Backend\Helper\Data::class)
123 ->disableOriginalConstructor()
125 $this->uiComponentContextMock = $this->getMockForAbstractClass(
126 ContextInterface::class
128 $this->dataProviderMock = $this->getMockForAbstractClass(
131 $this->uiComponentMock = $this->getMockForAbstractClass(
132 \
Magento\Framework\View\Element\UiComponentInterface::class,
141 $this->resultJsonFactoryMock = $this->getMockBuilder(
142 \
Magento\Framework\Controller\Result\JsonFactory::class
144 ->disableOriginalConstructor()
147 $this->loggerMock = $this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class);
149 $this->contextMock->expects($this->any())
150 ->method(
'getRequest')
151 ->willReturn($this->requestMock);
152 $this->contextMock->expects($this->any())
153 ->method(
'getResponse')
154 ->willReturn($this->responseMock);
155 $this->contextMock->expects($this->any())
156 ->method(
'getAuthorization')
157 ->willReturn($this->authorizationMock);
158 $this->contextMock->expects($this->any())
159 ->method(
'getSession')
160 ->willReturn($this->sessionMock);
161 $this->contextMock->expects($this->any())
162 ->method(
'getActionFlag')
163 ->willReturn($this->actionFlagMock);
164 $this->contextMock->expects($this->any())
165 ->method(
'getHelper')
166 ->willReturn($this->helperMock);
167 $this->uiComponentContextMock->expects($this->once())
168 ->method(
'getDataProvider')
169 ->willReturn($this->dataProviderMock);
170 $this->uiComponentTypeResolverMock = $this->getMockBuilder(UiComponentTypeResolver::class)
171 ->disableOriginalConstructor()
174 $this->objectManagerHelper =
new ObjectManagerHelper($this);
176 $this->render = $this->objectManagerHelper->getObject(
177 \
Magento\Ui\Controller\Adminhtml\Index\Render::class,
179 'context' => $this->contextMock,
180 'factory' => $this->uiFactoryMock,
181 'contentTypeResolver' => $this->uiComponentTypeResolverMock,
182 'resultJsonFactory' => $this->resultJsonFactoryMock,
183 'logger' => $this->loggerMock,
191 $renderedData =
'<html>data</html>';
193 $this->requestMock->expects($this->any())
197 $this->requestMock->expects($this->any())
198 ->method(
'getParams')
200 $this->responseMock->expects($this->once())
201 ->method(
'appendBody')
202 ->willThrowException(
new \Exception(
'exception'));
204 $jsonResultMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Json::class)
205 ->disableOriginalConstructor()
206 ->setMethods([
'setData'])
209 $this->resultJsonFactoryMock->expects($this->once())
211 ->willReturn($jsonResultMock);
213 $jsonResultMock->expects($this->once())
217 $this->loggerMock->expects($this->once())
221 $this->dataProviderMock->expects($this->once())
222 ->method(
'getConfigData')
225 $this->uiComponentMock->expects($this->once())
227 ->willReturn($renderedData);
228 $this->uiComponentMock->expects($this->once())
229 ->method(
'getChildComponents')
231 $this->uiComponentMock->expects($this->once())
232 ->method(
'getContext')
233 ->willReturn($this->uiComponentContextMock);
234 $this->uiFactoryMock->expects($this->once())
236 ->willReturn($this->uiComponentMock);
238 $this->render->executeAjaxRequest();
244 $renderedData =
'<html>data</html>';
246 $this->requestMock->expects($this->any())
250 $this->requestMock->expects($this->any())
251 ->method(
'getParams')
253 $this->responseMock->expects($this->once())
254 ->method(
'appendBody')
255 ->with($renderedData);
256 $this->dataProviderMock->expects($this->once())
257 ->method(
'getConfigData')
260 $this->uiComponentMock->expects($this->once())
262 ->willReturn($renderedData);
263 $this->uiComponentMock->expects($this->once())
264 ->method(
'getChildComponents')
266 $this->uiComponentMock->expects($this->any())
267 ->method(
'getContext')
268 ->willReturn($this->uiComponentContextMock);
269 $this->uiFactoryMock->expects($this->once())
271 ->willReturn($this->uiComponentMock);
272 $this->uiComponentTypeResolverMock->expects($this->once())
274 ->with($this->uiComponentContextMock)
275 ->willReturn(
'application/json');
276 $this->responseMock->expects($this->once())->method(
'setHeader')
277 ->with(
'Content-Type',
'application/json',
true);
279 $this->render->executeAjaxRequest();
291 $renderedData =
'<html>data</html>';
293 $this->requestMock->expects($this->any())
297 $this->requestMock->expects($this->any())
298 ->method(
'getParams')
301 $this->requestMock->expects($this->once())
305 $this->responseMock->expects($this->never())
306 ->method(
'setRedirect');
307 $this->responseMock->expects($this->any())
308 ->method(
'appendBody')
309 ->with($renderedData);
311 $this->dataProviderMock->expects($this->once())
312 ->method(
'getConfigData')
313 ->willReturn($dataProviderConfig);
315 $this->authorizationMock->expects($this->exactly($authCallCount))
316 ->method(
'isAllowed')
317 ->with(isset($dataProviderConfig[
'aclResource']) ? $dataProviderConfig[
'aclResource'] :
null)
320 $this->uiComponentMock->expects($this->any())
322 ->willReturn($renderedData);
323 $this->uiComponentMock->expects($this->any())
324 ->method(
'getChildComponents')
326 $this->uiComponentMock->expects($this->any())
327 ->method(
'getContext')
328 ->willReturn($this->uiComponentContextMock);
329 $this->uiFactoryMock->expects($this->once())
331 ->willReturn($this->uiComponentMock);
333 $this->render->executeAjaxRequest();
341 $aclResource =
'Magento_Test::index_index';
344 'dataProviderConfig' => [
'aclResource' => $aclResource],
348 'dataProviderConfig' => [
'aclResource' => $aclResource],
352 'dataProviderConfig' => [],
executeAjaxRequestWithoutPermissionsDataProvider()
testExecuteAjaxRequestWithoutPermissions(array $dataProviderConfig, $isAllowed, $authCallCount=1)
testExecuteAjaxRequestException()
if(!isset($_GET['name'])) $name