PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/dev/tests/integration/testsuite/Magento/Authorizenet/Controller/Directpost/Payment/ResponseTest.php

https://bitbucket.org/leminhtamboy/wisi
PHP | 249 lines | 192 code | 18 blank | 39 comment | 0 complexity | 6d4dcc29f69f8f9e33a58a451ee8e4ae MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. <?php
  2. /**
  3. * Copyright © 2013-2017 Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Authorizenet\Controller\Directpost\Payment;
  7. /**
  8. * Contains tests for Authorize.net Direct Post response handler.
  9. *
  10. * @magentoAppArea frontend
  11. */
  12. class ResponseTest extends \Magento\TestFramework\TestCase\AbstractController
  13. {
  14. /**
  15. * Tests the controller for declines.
  16. *
  17. * @param int $invoiceNum
  18. * @param string $hash
  19. * @param string $errorMsg
  20. * @param array $params
  21. * @return void
  22. *
  23. * @dataProvider responseActionAuthorizeCaptureDeclineDataProvider
  24. */
  25. public function testResponseActionAuthorizeCaptureDecline($invoiceNum, $hash, $errorMsg, array $params)
  26. {
  27. $controllerName = 'directpost_payment';
  28. $controllerModule = 'authorizenet';
  29. $controllerAction = 'response';
  30. $params['x_invoice_num'] = $invoiceNum;
  31. $params['x_MD5_Hash'] = $hash;
  32. $this->getRequest()->setControllerName(
  33. $controllerName
  34. )->setControllerModule(
  35. $controllerModule
  36. )->setActionName(
  37. $controllerAction
  38. )->setRouteName(
  39. $controllerModule
  40. )->setRequestUri("/{$controllerModule}/{$controllerName}/{$controllerAction}")
  41. ->setParams($params);
  42. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  43. /** @var \Magento\Authorizenet\Controller\Directpost\Payment\Response */
  44. $controller = $objectManager->create(\Magento\Authorizenet\Controller\Directpost\Payment\Response::class);
  45. $response = $controller->execute();
  46. $output = $response->getLayout()->getOutput();
  47. $expectedString = "{$controllerModule}/{$controllerName}/redirect/x_invoice_num/{$params['x_invoice_num']}/"
  48. . "success/0/error_msg/{$errorMsg}/controller_action_name/{$controllerName}/";
  49. $this->assertContains('window.location', $output);
  50. $this->assertContains($expectedString, $output);
  51. }
  52. /**
  53. * Tests the controller for created blocks used for sending emails that should not affect layout response.
  54. *
  55. * @param string $hash
  56. * @param array $params
  57. * @return void
  58. *
  59. * @dataProvider responseActionAuthorizeCaptureSuccessDataProvider
  60. */
  61. public function testBlockCreationAffectingResult($hash, array $params)
  62. {
  63. $controllerName = 'directpost_payment';
  64. $controllerModule = 'authorizenet';
  65. $controllerAction = 'response';
  66. $params['x_invoice_num'] = 100000002;
  67. $params['x_MD5_Hash'] = $hash;
  68. $this->getRequest()->setControllerName(
  69. $controllerName
  70. )->setControllerModule(
  71. $controllerModule
  72. )->setActionName(
  73. $controllerAction
  74. )->setRouteName(
  75. $controllerModule
  76. )->setRequestUri("/{$controllerModule}/{$controllerName}/{$controllerAction}")
  77. ->setParams($params);
  78. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  79. $directpostMock = $this->getMockBuilder(\Magento\Authorizenet\Model\Directpost::class)
  80. ->disableOriginalConstructor()
  81. ->getMock();
  82. $objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
  83. ->setMethods(['create'])
  84. ->getMockForAbstractClass();
  85. $objectManagerMock->expects($this->atLeastOnce())
  86. ->method('create')
  87. ->with(\Magento\Authorizenet\Model\Directpost::class)
  88. ->willReturn($directpostMock);
  89. $context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  90. \Magento\Backend\App\Action\Context::class,
  91. [
  92. 'objectManager' => $objectManagerMock,
  93. ]
  94. );
  95. /** @var \Magento\Authorizenet\Controller\Directpost\Payment\Response $controller */
  96. $controller = $objectManager->create(
  97. \Magento\Authorizenet\Controller\Directpost\Payment\Response::class,
  98. [
  99. 'context' => $context,
  100. ]
  101. );
  102. // create one block for potential layout stack modification that should not affect response
  103. /** @var \Magento\Authorizenet\Block\Adminhtml\Order\View\Info\FraudDetails $block */
  104. $block = $objectManager->get(\Magento\Framework\View\LayoutInterface::class)
  105. ->createBlock(\Magento\Authorizenet\Block\Adminhtml\Order\View\Info\FraudDetails::class);
  106. $block->setTemplate('Magento_Payment::order/view/info/fraud_details.phtml');
  107. $response = $controller->execute();
  108. $output = $response->getLayout()->getOutput();
  109. $expectedString = "{$controllerModule}/{$controllerName}/redirect/x_invoice_num/{$params['x_invoice_num']}/"
  110. . "success/1/controller_action_name/{$controllerName}/";
  111. $this->assertContains('window.location', $output);
  112. $this->assertContains($expectedString, $output);
  113. }
  114. /**
  115. * @return array
  116. */
  117. public function responseActionAuthorizeCaptureDeclineDataProvider()
  118. {
  119. $postArray = [
  120. 'x_response_code' => 1,
  121. 'x_response_reason_code' => 1,
  122. 'x_response_reason_text' => 'This transaction has been approved.',
  123. 'x_avs_code' => 'Y',
  124. 'x_auth_code' => 'G0L0XR',
  125. 'x_trans_id' => '60016479791',
  126. 'x_method' => 'CC',
  127. 'x_card_type' => 'American Express',
  128. 'x_account_number' => 'XXXX0002',
  129. 'x_first_name' => 'Name',
  130. 'x_last_name' => 'Surname',
  131. 'x_company' => null,
  132. 'x_address' => 'Address',
  133. 'x_city' => 'Austin',
  134. 'x_state' => 'Texas',
  135. 'x_zip' => '78753',
  136. 'x_country' => 'US',
  137. 'x_phone' => '5127242323',
  138. 'x_fax' => null,
  139. 'x_email' => 'customer@example.com',
  140. 'x_description' => null,
  141. 'x_type' => 'auth_capture',
  142. 'x_cust_id' => null,
  143. 'x_ship_to_first_name' => null,
  144. 'x_ship_to_last_name' => null,
  145. 'x_ship_to_company' => null,
  146. 'x_ship_to_address' => null,
  147. 'x_ship_to_city' => null,
  148. 'x_ship_to_state' => null,
  149. 'x_ship_to_zip' => null,
  150. 'x_ship_to_country' => null,
  151. 'x_amount' => 100.00,
  152. 'x_tax' => 0.00,
  153. 'x_duty' => 0.00,
  154. 'x_freight' => 0.00,
  155. 'x_tax_exempt' => false,
  156. 'x_po_num' => null,
  157. 'x_SHA2_Hash' => null,
  158. 'x_cvv2_resp_code' => 'P',
  159. 'x_cavv_response' => 2,
  160. 'x_test_request' => false,
  161. 'controller_action_name' => 'directpost_payment',
  162. 'is_secure' => null,
  163. ];
  164. return [
  165. 'error_hash' => [
  166. 'invoice_num' => '1231231',
  167. 'x_MD5_Hash' => 'F9AE81A5DA36057D1312D71C904FCCF2',
  168. 'error_msg' => 'The%20transaction%20was%20declined%20because%20the%20'
  169. . 'response%20hash%20validation%20failed.',
  170. 'post' => $postArray,
  171. ],
  172. ];
  173. }
  174. /**
  175. * @return array
  176. */
  177. public function responseActionAuthorizeCaptureSuccessDataProvider()
  178. {
  179. $postArray = [
  180. 'x_response_code' => 1,
  181. 'x_response_reason_code' => 1,
  182. 'x_response_reason_text' => 'This transaction has been approved.',
  183. 'x_avs_code' => 'Y',
  184. 'x_auth_code' => 'G0L0XR',
  185. 'x_trans_id' => '60016479791',
  186. 'x_method' => 'CC',
  187. 'x_card_type' => 'American Express',
  188. 'x_account_number' => 'XXXX0002',
  189. 'x_first_name' => 'Name',
  190. 'x_last_name' => 'Surname',
  191. 'x_company' => null,
  192. 'x_address' => 'Address',
  193. 'x_city' => 'Austin',
  194. 'x_state' => 'Texas',
  195. 'x_zip' => '78753',
  196. 'x_country' => 'US',
  197. 'x_phone' => '5127242323',
  198. 'x_fax' => null,
  199. 'x_email' => 'integrationtest@magento.com',
  200. 'x_description' => null,
  201. 'x_type' => 'auth_capture',
  202. 'x_cust_id' => null,
  203. 'x_ship_to_first_name' => null,
  204. 'x_ship_to_last_name' => null,
  205. 'x_ship_to_company' => null,
  206. 'x_ship_to_address' => null,
  207. 'x_ship_to_city' => null,
  208. 'x_ship_to_state' => null,
  209. 'x_ship_to_zip' => null,
  210. 'x_ship_to_country' => null,
  211. 'x_amount' => 120.15,
  212. 'x_tax' => 0.00,
  213. 'x_duty' => 0.00,
  214. 'x_freight' => 0.00,
  215. 'x_tax_exempt' => false,
  216. 'x_po_num' => null,
  217. 'x_SHA2_Hash' => null,
  218. 'x_cvv2_resp_code' => 'P',
  219. 'x_cavv_response' => 2,
  220. 'x_test_request' => false,
  221. 'controller_action_name' => 'directpost_payment',
  222. 'is_secure' => null,
  223. ];
  224. return [
  225. 'success' => [
  226. 'x_MD5_Hash' => '35DCF749F7760193FB8254886E1D1522',
  227. 'post' => $postArray,
  228. ],
  229. ];
  230. }
  231. }