Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentVaultConfigurationProcessTest.php
Go to the documentation of this file.
1 <?php
7 
11 class PaymentVaultConfigurationProcessTest extends \PHPUnit\Framework\TestCase
12 {
16  private $storeManager;
17 
21  private $store;
22 
26  private $vaultList;
27 
31  private $paymentMethodList;
32 
36  private $layoutProcessor;
37 
41  private $plugin;
42 
46  protected function setUp()
47  {
48  $this->storeManager = $this
49  ->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
50  ->disableOriginalConstructor()
51  ->setMethods(['getStore'])
52  ->getMockForAbstractClass();
53  $this->store = $this
54  ->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
55  ->disableOriginalConstructor()
56  ->setMethods(['getId'])
57  ->getMockForAbstractClass();
58  $this->vaultList = $this
59  ->getMockBuilder(\Magento\Vault\Api\PaymentMethodListInterface::class)
60  ->disableOriginalConstructor()
61  ->setMethods(['getActiveList'])
62  ->getMockForAbstractClass();
63  $this->paymentMethodList = $this
64  ->getMockBuilder(\Magento\Payment\Api\PaymentMethodListInterface::class)
65  ->disableOriginalConstructor()
66  ->setMethods(['getActiveList'])
67  ->getMockForAbstractClass();
68  $this->layoutProcessor = $this
69  ->getMockBuilder(\Magento\Checkout\Block\Checkout\LayoutProcessor::class)
70  ->disableOriginalConstructor()
71  ->setMethods(['process'])
72  ->getMockForAbstractClass();
73 
74  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
75  $this->plugin = $objectManagerHelper->getObject(
76  \Magento\Vault\Plugin\PaymentVaultConfigurationProcess::class,
77  [
78  'vaultPaymentList' => $this->vaultList,
79  'paymentMethodList' => $this->paymentMethodList,
80  'storeManager' => $this->storeManager
81  ]
82  );
83  }
84 
92  public function testBeforeProcess($jsLayout, $activeVaultList, $activePaymentList, $expectedResult)
93  {
94  $this->store->expects($this->once())->method('getId')->willReturn(1);
95  $this->storeManager->expects($this->once())->method('getStore')->willReturn($this->store);
96  $this->vaultList->expects($this->once())->method('getActiveList')->with(1)->willReturn($activeVaultList);
97  $this->paymentMethodList->expects($this->once())
98  ->method('getActiveList')
99  ->with(1)
100  ->willReturn($activePaymentList);
101  $result = $this->plugin->beforeProcess($this->layoutProcessor, $jsLayout);
102  $this->assertEquals($result[0], $expectedResult);
103  }
104 
110  public function beforeProcessDataProvider()
111  {
112  $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
113  ['children']['payment']['children']['renders']['children'] = [
114  'vault' => [
115  'methods' => []
116  ],
117  'braintree' => [
118  'methods' => [
119  'braintree_paypal' => [],
120  'braintree' => []
121  ]
122  ],
123  'paypal-payments' => [
124  'methods' => [
125  'payflowpro' => [],
126  'payflow_link' => []
127  ]
128  ]
129  ];
130  $result1['components']['checkout']['children']['steps']['children']['billing-step']
131  ['children']['payment']['children']['renders']['children'] = [];
132  $result2['components']['checkout']['children']['steps']['children']['billing-step']
133  ['children']['payment']['children']['renders']['children'] = [
134  'vault' => [
135  'methods' => []
136  ],
137  'braintree' => [
138  'methods' => [
139  'braintree_paypal' => []
140  ]
141  ]
142  ];
143 
144  $vaultPaymentMethod = $this
145  ->getMockBuilder(\Magento\Vault\Api\PaymentMethodListInterface::class)
146  ->disableOriginalConstructor()
147  ->setMethods(['getCode', 'getProviderCode'])
148  ->getMockForAbstractClass();
149 
150  $vaultPaymentMethod->expects($this->any())->method('getCode')->willReturn('braintree_paypal_vault');
151  $vaultPaymentMethod->expects($this->any())->method('getProviderCode')->willReturn('braintree_paypal');
152 
153  return [
154  [$jsLayout, [], [], $result1],
155  [$jsLayout, [$vaultPaymentMethod], [$vaultPaymentMethod], $result2]
156  ];
157  }
158 }
testBeforeProcess($jsLayout, $activeVaultList, $activePaymentList, $expectedResult)