PaymentConfigurationProcessTest.php 5.1 KB

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