Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data Fields | Protected Member Functions | Protected Attributes
IntegrationTest Class Reference
Inheritance diagram for IntegrationTest:
DeleteTest EditTest IndexTest NewActionTest PermissionsDialogTest SaveTest TokensDialogTest TokensExchangeTest

Data Fields

const INTEGRATION_ID = 1
 

Protected Member Functions

 _createIntegrationController ($actionName)
 
 _verifyLoadAndRenderLayout ()
 
 _getSampleIntegrationData ()
 
 _getIntegrationModelMock ()
 

Protected Attributes

 $_controller
 
 $_objectManagerHelper
 
 $_objectManagerMock
 
 $_layoutFilterMock
 
 $_configMock
 
 $_eventManagerMock
 
 $_translateModelMock
 
 $_backendSessionMock
 
 $_backendActionCtxMock
 
 $securityCookieMock
 
 $_integrationSvcMock
 
 $_oauthSvcMock
 
 $_authMock
 
 $_userMock
 
 $_registryMock
 
 $_requestMock
 
 $_responseMock
 
 $_messageManager
 
 $_configScopeMock
 
 $_integrationHelperMock
 
 $_viewMock
 
 $_layoutMergeMock
 
 $_layoutMock
 
 $resultPageMock
 
 $viewConfigMock
 
 $pageTitleMock
 
 $_escaper
 
 $resultRedirectFactory
 
 $resultFactory
 

Detailed Description

@SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 18 of file IntegrationTest.php.

Member Function Documentation

◆ _createIntegrationController()

_createIntegrationController (   $actionName)
protected
Parameters
string$actionName
Returns
\Magento\Integration\Controller\Adminhtml\Integration @SuppressWarnings(PHPMD.ExcessiveMethodLength)

Create IntegrationController to test

Definition at line 207 of file IntegrationTest.php.

208  {
209  // Mock Layout passed into constructor
210  $this->_viewMock = $this->getMockBuilder(\Magento\Framework\App\ViewInterface::class)
211  ->getMock();
212  $this->_layoutMock = $this->getMockBuilder(\Magento\Framework\View\LayoutInterface::class)
213  ->setMethods(['getNode'])
214  ->getMockForAbstractClass();
215  $this->_layoutMergeMock = $this->getMockBuilder(
216  \Magento\Framework\View\Model\Layout\Merge::class
217  )->disableOriginalConstructor()->getMock();
218  $this->_layoutMock->expects(
219  $this->any()
220  )->method(
221  'getUpdate'
222  )->will(
223  $this->returnValue($this->_layoutMergeMock)
224  );
225  $testElement = new \Magento\Framework\Simplexml\Element('<test>test</test>');
226  $this->_layoutMock->expects($this->any())->method('getNode')->will($this->returnValue($testElement));
227  // for _setActiveMenu
228  $this->_viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->_layoutMock));
229  $blockMock = $this->getMockBuilder(\Magento\Backend\Block\Menu::class)->disableOriginalConstructor()->getMock();
230  $menuMock = $this->getMockBuilder(\Magento\Backend\Model\Menu::class)
231  ->setConstructorArgs([$this->createMock(\Psr\Log\LoggerInterface::class)])
232  ->getMock();
233  $loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
234  $loggerMock->expects($this->any())->method('critical')->will($this->returnSelf());
235  $menuMock->expects($this->any())->method('getParentItems')->will($this->returnValue([]));
236  $blockMock->expects($this->any())->method('getMenuModel')->will($this->returnValue($menuMock));
237  $this->_layoutMock->expects($this->any())->method('getMessagesBlock')->will($this->returnValue($blockMock));
238  $this->_layoutMock->expects($this->any())->method('getBlock')->will($this->returnValue($blockMock));
239  $this->_viewMock->expects($this->any())
240  ->method('getPage')
241  ->willReturn($this->resultPageMock);
242  $this->resultPageMock->expects($this->any())
243  ->method('getConfig')
244  ->willReturn($this->viewConfigMock);
245  $this->viewConfigMock->expects($this->any())
246  ->method('getTitle')
247  ->willReturn($this->pageTitleMock);
248 
249  $this->resultRedirectFactory = $this->getMockBuilder(\Magento\Backend\Model\View\Result\RedirectFactory::class)
250  ->disableOriginalConstructor()
251  ->setMethods(['create'])
252  ->getMock();
253 
254  $this->resultFactory = $this->getMockBuilder(\Magento\Framework\Controller\ResultFactory::class)
255  ->disableOriginalConstructor()
256  ->setMethods(['create'])
257  ->getMock();
258 
259  $this->_authMock->expects(
260  $this->any()
261  )->method(
262  'getUser'
263  )->will(
264  $this->returnValue($this->_userMock)
265  );
266 
267  $this->_userMock->expects($this->any())
268  ->method('load')
269  ->willReturn($this->_userMock);
270 
271  $this->_backendSessionMock->expects($this->any())
272  ->method('getIntegrationData')
273  ->willReturn(['all_resources' => 1]);
274 
275  $contextParameters = [
276  'view' => $this->_viewMock,
277  'objectManager' => $this->_objectManagerMock,
278  'session' => $this->_backendSessionMock,
279  'translator' => $this->_translateModelMock,
280  'request' => $this->_requestMock,
281  'response' => $this->_responseMock,
282  'messageManager' => $this->_messageManager,
283  'resultRedirectFactory' => $this->resultRedirectFactory,
284  'resultFactory' => $this->resultFactory,
285  'auth' => $this->_authMock,
286  'eventManager' => $this->_eventManagerMock
287  ];
288 
289  $this->_backendActionCtxMock = $this->_objectManagerHelper->getObject(
290  \Magento\Backend\App\Action\Context::class,
291  $contextParameters
292  );
293 
294  $integrationCollection =
295  $this->getMockBuilder(\Magento\Integration\Model\ResourceModel\Integration\Collection::class)
296  ->disableOriginalConstructor()
297  ->setMethods(['addUnsecureUrlsFilter', 'getSize'])
298  ->getMock();
299  $integrationCollection->expects($this->any())
300  ->method('addUnsecureUrlsFilter')
301  ->will($this->returnValue($integrationCollection));
302  $integrationCollection->expects($this->any())
303  ->method('getSize')
304  ->will($this->returnValue(0));
305 
306  $subControllerParams = [
307  'context' => $this->_backendActionCtxMock,
308  'integrationService' => $this->_integrationSvcMock,
309  'oauthService' => $this->_oauthSvcMock,
310  'registry' => $this->_registryMock,
311  'logger' => $loggerMock,
312  'integrationData' => $this->_integrationHelperMock,
313  'escaper' => $this->_escaper,
314  'integrationCollection' => $integrationCollection,
315  ];
317  $controller = $this->_objectManagerHelper->getObject(
318  '\\Magento\\Integration\\Controller\\Adminhtml\\Integration\\' . $actionName,
319  $subControllerParams
320  );
321  if ($actionName == 'Save') {
322  $reflection = new \ReflectionClass(get_class($controller));
323  $reflectionProperty = $reflection->getProperty('securityCookie');
324  $reflectionProperty->setAccessible(true);
325  $reflectionProperty->setValue($controller, $this->securityCookieMock);
326  }
327  return $controller;
328  }
$controller
Definition: info.phtml:14

◆ _getIntegrationModelMock()

_getIntegrationModelMock ( )
protected

Return integration model mock with sample data.

Returns
\Magento\Integration\Model\Integration|\PHPUnit_Framework_MockObject_MockObject

Definition at line 371 of file IntegrationTest.php.

372  {
373  $integrationModelMock = $this->createPartialMock(
374  \Magento\Integration\Model\Integration::class,
375  ['save', '__wakeup', 'setStatus', 'getData']
376  );
377 
378  $integrationModelMock->expects($this->any())->method('setStatus')->will($this->returnSelf());
379  $integrationModelMock->expects(
380  $this->any()
381  )->method(
382  'getData'
383  )->will(
384  $this->returnValue($this->_getSampleIntegrationData())
385  );
386 
387  return $integrationModelMock;
388  }

◆ _getSampleIntegrationData()

_getSampleIntegrationData ( )
protected

Return sample Integration Data

Returns
\Magento\Framework\DataObject

Definition at line 352 of file IntegrationTest.php.

353  {
354  return new \Magento\Framework\DataObject(
355  [
356  Info::DATA_NAME => 'nameTest',
357  Info::DATA_ID => self::INTEGRATION_ID,
358  'id' => self::INTEGRATION_ID,
360  Info::DATA_ENDPOINT => 'http://magento.ll/endpoint',
361  Info::DATA_SETUP_TYPE => IntegrationModel::TYPE_MANUAL,
362  ]
363  );
364  }

◆ _verifyLoadAndRenderLayout()

_verifyLoadAndRenderLayout ( )
protected

Common mock 'expect' pattern. Calls that need to be mocked out when \Magento\Backend\App\AbstractAction loadLayout() and renderLayout() are called.

Definition at line 335 of file IntegrationTest.php.

336  {
337  $map = [
338  [\Magento\Framework\App\Config\ScopeConfigInterface::class, $this->_configMock],
339  [\Magento\Backend\Model\Layout\Filter\Acl::class, $this->_layoutFilterMock],
340  [\Magento\Backend\Model\Session::class, $this->_backendSessionMock],
341  [\Magento\Framework\TranslateInterface::class, $this->_translateModelMock],
342  [\Magento\Framework\Config\ScopeInterface::class, $this->_configScopeMock],
343  ];
344  $this->_objectManagerMock->expects($this->any())->method('get')->will($this->returnValueMap($map));
345  }

Field Documentation

◆ $_authMock

$_authMock
protected

Definition at line 57 of file IntegrationTest.php.

◆ $_backendActionCtxMock

$_backendActionCtxMock
protected

Definition at line 45 of file IntegrationTest.php.

◆ $_backendSessionMock

$_backendSessionMock
protected

Definition at line 42 of file IntegrationTest.php.

◆ $_configMock

$_configMock
protected

Definition at line 33 of file IntegrationTest.php.

◆ $_configScopeMock

$_configScopeMock
protected

Definition at line 75 of file IntegrationTest.php.

◆ $_controller

$_controller
protected

Definition at line 21 of file IntegrationTest.php.

◆ $_escaper

$_escaper
protected

Definition at line 107 of file IntegrationTest.php.

◆ $_eventManagerMock

$_eventManagerMock
protected

Definition at line 36 of file IntegrationTest.php.

◆ $_integrationHelperMock

$_integrationHelperMock
protected

Definition at line 78 of file IntegrationTest.php.

◆ $_integrationSvcMock

$_integrationSvcMock
protected

Definition at line 51 of file IntegrationTest.php.

◆ $_layoutFilterMock

$_layoutFilterMock
protected

Definition at line 30 of file IntegrationTest.php.

◆ $_layoutMergeMock

$_layoutMergeMock
protected

Definition at line 84 of file IntegrationTest.php.

◆ $_layoutMock

$_layoutMock
protected

Definition at line 87 of file IntegrationTest.php.

◆ $_messageManager

$_messageManager
protected

Definition at line 72 of file IntegrationTest.php.

◆ $_oauthSvcMock

$_oauthSvcMock
protected

Definition at line 54 of file IntegrationTest.php.

◆ $_objectManagerHelper

$_objectManagerHelper
protected

Definition at line 24 of file IntegrationTest.php.

◆ $_objectManagerMock

$_objectManagerMock
protected

Definition at line 27 of file IntegrationTest.php.

◆ $_registryMock

$_registryMock
protected

Definition at line 63 of file IntegrationTest.php.

◆ $_requestMock

$_requestMock
protected

Definition at line 66 of file IntegrationTest.php.

◆ $_responseMock

$_responseMock
protected

Definition at line 69 of file IntegrationTest.php.

◆ $_translateModelMock

$_translateModelMock
protected

Definition at line 39 of file IntegrationTest.php.

◆ $_userMock

$_userMock
protected

Definition at line 60 of file IntegrationTest.php.

◆ $_viewMock

$_viewMock
protected

Definition at line 81 of file IntegrationTest.php.

◆ $pageTitleMock

$pageTitleMock
protected

Definition at line 102 of file IntegrationTest.php.

◆ $resultFactory

$resultFactory
protected

Definition at line 117 of file IntegrationTest.php.

◆ $resultPageMock

$resultPageMock
protected

Definition at line 92 of file IntegrationTest.php.

◆ $resultRedirectFactory

$resultRedirectFactory
protected

Definition at line 112 of file IntegrationTest.php.

◆ $securityCookieMock

$securityCookieMock
protected

Definition at line 48 of file IntegrationTest.php.

◆ $viewConfigMock

$viewConfigMock
protected

Definition at line 97 of file IntegrationTest.php.

◆ INTEGRATION_ID

const INTEGRATION_ID = 1

Sample integration ID

Definition at line 120 of file IntegrationTest.php.


The documentation for this class was generated from the following file: