RequestTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Test\Unit\Controller\Token;
  7. /**
  8. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  9. */
  10. class RequestTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
  14. */
  15. protected $request;
  16. /**
  17. * @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $response;
  20. /**
  21. * @var \Magento\Backend\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $context;
  24. /**
  25. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager $objectManagerHelper
  26. */
  27. protected $objectManagerHelper;
  28. /**
  29. * @var \Magento\Framework\Oauth\OauthInterface|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. protected $frameworkOauthSvcMock;
  32. /**
  33. * @var \Magento\Framework\Oauth\Helper\Request|\PHPUnit_Framework_MockObject_MockObject
  34. */
  35. protected $helperMock;
  36. /**
  37. * @var \Magento\Integration\Controller\Token\Request
  38. */
  39. protected $requestAction;
  40. protected function setUp()
  41. {
  42. $this->request = $this->createPartialMock(\Magento\Framework\App\RequestInterface::class, [
  43. 'getMethod',
  44. 'getModuleName',
  45. 'setModuleName',
  46. 'getActionName',
  47. 'setActionName',
  48. 'getParam',
  49. 'setParams',
  50. 'getParams',
  51. 'getCookie',
  52. 'isSecure'
  53. ]);
  54. $this->response = $this->createMock(\Magento\Framework\App\Console\Response::class);
  55. /** @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
  56. $objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  57. /** @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
  58. $eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
  59. /** @var \Magento\Framework\View\Layout\ProcessorInterface|\PHPUnit_Framework_MockObject_MockObject */
  60. $update = $this->createMock(\Magento\Framework\View\Layout\ProcessorInterface::class);
  61. /** @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject */
  62. $layout = $this->createMock(\Magento\Framework\View\Layout::class);
  63. $layout->expects($this->any())->method('getUpdate')->will($this->returnValue($update));
  64. /** @var \Magento\Framework\View\Page\Config */
  65. $pageConfig = $this->createMock(\Magento\Framework\View\Page\Config::class);
  66. $pageConfig->expects($this->any())->method('addBodyClass')->will($this->returnSelf());
  67. /** @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */
  68. $page = $this->createPartialMock(
  69. \Magento\Framework\View\Result\Page::class,
  70. ['getConfig', 'initLayout', 'addPageLayoutHandles', 'getLayout']
  71. );
  72. $page->expects($this->any())->method('getConfig')->will($this->returnValue($pageConfig));
  73. $page->expects($this->any())->method('addPageLayoutHandles')->will($this->returnSelf());
  74. $page->expects($this->any())->method('getLayout')->will($this->returnValue($layout));
  75. /** @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject */
  76. $view = $this->createMock(\Magento\Framework\App\ViewInterface::class);
  77. $view->expects($this->any())->method('getLayout')->will($this->returnValue($layout));
  78. /** @var Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */
  79. $resultFactory = $this->createMock(\Magento\Framework\Controller\ResultFactory::class);
  80. $resultFactory->expects($this->any())->method('create')->will($this->returnValue($page));
  81. $this->context = $this->createMock(\Magento\Backend\App\Action\Context::class);
  82. $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
  83. $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($this->response));
  84. $this->context->expects($this->any())->method('getObjectManager')
  85. ->will($this->returnValue($objectManager));
  86. $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
  87. $this->context->expects($this->any())->method('getView')->will($this->returnValue($view));
  88. $this->context->expects($this->any())->method('getResultFactory')
  89. ->will($this->returnValue($resultFactory));
  90. $this->helperMock = $this->createMock(\Magento\Framework\Oauth\Helper\Request::class);
  91. $this->frameworkOauthSvcMock = $this->createMock(\Magento\Framework\Oauth\OauthInterface::class);
  92. /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager $objectManagerHelper */
  93. $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  94. $this->requestAction = $this->objectManagerHelper->getObject(
  95. \Magento\Integration\Controller\Token\Request::class,
  96. [
  97. 'context' => $this->context,
  98. 'oauthService'=> $this->frameworkOauthSvcMock,
  99. 'helper' => $this->helperMock,
  100. ]
  101. );
  102. }
  103. /**
  104. * Test the basic Request action.
  105. */
  106. public function testRequestAction()
  107. {
  108. $this->request->expects($this->any())
  109. ->method('getMethod')
  110. ->willReturn('GET');
  111. $this->helperMock->expects($this->once())
  112. ->method('getRequestUrl');
  113. $this->helperMock->expects($this->once())
  114. ->method('prepareRequest');
  115. $this->frameworkOauthSvcMock->expects($this->once())
  116. ->method('getRequestToken')
  117. ->willReturn(['response']);
  118. $this->response->expects($this->once())
  119. ->method('setBody');
  120. $this->requestAction->execute();
  121. }
  122. }