PaymentVaultConfigurationProcessTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Vault\Test\Unit\Plugin;
  7. /**
  8. * Class PaymentVaultConfigurationProcessTest.
  9. */
  10. class PaymentVaultConfigurationProcessTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  14. */
  15. private $storeManager;
  16. /**
  17. * @var \Magento\Store\Api\Data\StoreInterface|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $store;
  20. /**
  21. * @var \Magento\Vault\Api\PaymentMethodListInterface|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. private $vaultList;
  24. /**
  25. * @var \Magento\Payment\Api\PaymentMethodListInterface|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. private $paymentMethodList;
  28. /**
  29. * @var \Magento\Checkout\Block\Checkout\LayoutProcessor|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. private $layoutProcessor;
  32. /**
  33. * @var \Magento\Vault\Plugin\PaymentVaultConfigurationProcess
  34. */
  35. private $plugin;
  36. /**
  37. * Set up
  38. */
  39. protected function setUp()
  40. {
  41. $this->storeManager = $this
  42. ->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
  43. ->disableOriginalConstructor()
  44. ->setMethods(['getStore'])
  45. ->getMockForAbstractClass();
  46. $this->store = $this
  47. ->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
  48. ->disableOriginalConstructor()
  49. ->setMethods(['getId'])
  50. ->getMockForAbstractClass();
  51. $this->vaultList = $this
  52. ->getMockBuilder(\Magento\Vault\Api\PaymentMethodListInterface::class)
  53. ->disableOriginalConstructor()
  54. ->setMethods(['getActiveList'])
  55. ->getMockForAbstractClass();
  56. $this->paymentMethodList = $this
  57. ->getMockBuilder(\Magento\Payment\Api\PaymentMethodListInterface::class)
  58. ->disableOriginalConstructor()
  59. ->setMethods(['getActiveList'])
  60. ->getMockForAbstractClass();
  61. $this->layoutProcessor = $this
  62. ->getMockBuilder(\Magento\Checkout\Block\Checkout\LayoutProcessor::class)
  63. ->disableOriginalConstructor()
  64. ->setMethods(['process'])
  65. ->getMockForAbstractClass();
  66. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  67. $this->plugin = $objectManagerHelper->getObject(
  68. \Magento\Vault\Plugin\PaymentVaultConfigurationProcess::class,
  69. [
  70. 'vaultPaymentList' => $this->vaultList,
  71. 'paymentMethodList' => $this->paymentMethodList,
  72. 'storeManager' => $this->storeManager
  73. ]
  74. );
  75. }
  76. /**
  77. * @param array $jsLayout
  78. * @param array $activeVaultList
  79. * @param array $activePaymentList
  80. * @param array $expectedResult
  81. * @dataProvider beforeProcessDataProvider
  82. */
  83. public function testBeforeProcess($jsLayout, $activeVaultList, $activePaymentList, $expectedResult)
  84. {
  85. $this->store->expects($this->once())->method('getId')->willReturn(1);
  86. $this->storeManager->expects($this->once())->method('getStore')->willReturn($this->store);
  87. $this->vaultList->expects($this->once())->method('getActiveList')->with(1)->willReturn($activeVaultList);
  88. $this->paymentMethodList->expects($this->once())
  89. ->method('getActiveList')
  90. ->with(1)
  91. ->willReturn($activePaymentList);
  92. $result = $this->plugin->beforeProcess($this->layoutProcessor, $jsLayout);
  93. $this->assertEquals($result[0], $expectedResult);
  94. }
  95. /**
  96. * Data provider for BeforeProcess.
  97. *
  98. * @return array
  99. */
  100. public function beforeProcessDataProvider()
  101. {
  102. $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
  103. ['children']['payment']['children']['renders']['children'] = [
  104. 'vault' => [
  105. 'methods' => []
  106. ],
  107. 'braintree' => [
  108. 'methods' => [
  109. 'braintree_paypal' => [],
  110. 'braintree' => []
  111. ]
  112. ],
  113. 'paypal-payments' => [
  114. 'methods' => [
  115. 'payflowpro' => [],
  116. 'payflow_link' => []
  117. ]
  118. ]
  119. ];
  120. $result1['components']['checkout']['children']['steps']['children']['billing-step']
  121. ['children']['payment']['children']['renders']['children'] = [];
  122. $result2['components']['checkout']['children']['steps']['children']['billing-step']
  123. ['children']['payment']['children']['renders']['children'] = [
  124. 'vault' => [
  125. 'methods' => []
  126. ],
  127. 'braintree' => [
  128. 'methods' => [
  129. 'braintree_paypal' => []
  130. ]
  131. ]
  132. ];
  133. $vaultPaymentMethod = $this
  134. ->getMockBuilder(\Magento\Vault\Api\PaymentMethodListInterface::class)
  135. ->disableOriginalConstructor()
  136. ->setMethods(['getCode', 'getProviderCode'])
  137. ->getMockForAbstractClass();
  138. $vaultPaymentMethod->expects($this->any())->method('getCode')->willReturn('braintree_paypal_vault');
  139. $vaultPaymentMethod->expects($this->any())->method('getProviderCode')->willReturn('braintree_paypal');
  140. return [
  141. [$jsLayout, [], [], $result1],
  142. [$jsLayout, [$vaultPaymentMethod], [$vaultPaymentMethod], $result2]
  143. ];
  144. }
  145. }