Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentConfigurationProcessTest.php
Go to the documentation of this file.
1 <?php
7 
11 class PaymentConfigurationProcessTest extends \PHPUnit\Framework\TestCase
12 {
16  private $storeManager;
17 
21  private $store;
22 
26  private $paymentMethodList;
27 
31  private $layoutProcessor;
32 
36  private $plugin;
37 
41  protected function setUp()
42  {
43  $this->storeManager = $this
44  ->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
45  ->disableOriginalConstructor()
46  ->setMethods(['getStore'])
47  ->getMockForAbstractClass();
48  $this->store = $this
49  ->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
50  ->disableOriginalConstructor()
51  ->setMethods(['getId'])
52  ->getMockForAbstractClass();
53  $this->paymentMethodList = $this
54  ->getMockBuilder(\Magento\Payment\Api\PaymentMethodListInterface::class)
55  ->disableOriginalConstructor()
56  ->setMethods(['getActiveList'])
57  ->getMockForAbstractClass();
58  $this->layoutProcessor = $this
59  ->getMockBuilder(\Magento\Checkout\Block\Checkout\LayoutProcessor::class)
60  ->disableOriginalConstructor()
61  ->setMethods(['process'])
62  ->getMockForAbstractClass();
63 
64  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
65  $this->plugin = $objectManagerHelper->getObject(
66  \Magento\Payment\Plugin\PaymentConfigurationProcess::class,
67  [
68  'paymentMethodList' => $this->paymentMethodList,
69  'storeManager' => $this->storeManager
70  ]
71  );
72  }
73 
80  public function testBeforeProcess($jsLayout, $activePaymentList, $expectedResult)
81  {
82  $this->store->expects($this->once())->method('getId')->willReturn(1);
83  $this->storeManager->expects($this->once())->method('getStore')->willReturn($this->store);
84  $this->paymentMethodList->expects($this->once())
85  ->method('getActiveList')
86  ->with(1)
87  ->willReturn($activePaymentList);
88 
89  $result = $this->plugin->beforeProcess($this->layoutProcessor, $jsLayout);
90  $this->assertEquals($result[0], $expectedResult);
91  }
92 
98  public function beforeProcessDataProvider()
99  {
100  $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
101  ['children']['payment']['children']['renders']['children'] = [
102  'braintree' => [
103  'methods' => [
104  'braintree_paypal' => [],
105  'braintree' => []
106  ]
107  ],
108  'paypal-payments' => [
109  'methods' => [
110  'payflowpro' => [],
111  'payflow_link' => []
112  ]
113  ]
114  ];
115  $result1['components']['checkout']['children']['steps']['children']['billing-step']
116  ['children']['payment']['children']['renders']['children'] = [];
117  $result2['components']['checkout']['children']['steps']['children']['billing-step']
118  ['children']['payment']['children']['renders']['children'] = [
119  'braintree' => [
120  'methods' => [
121  'braintree' => [],
122  'braintree_paypal' => []
123  ]
124  ]
125  ];
126 
127  $braintreePaymentMethod = $this
128  ->getMockBuilder(\Magento\Payment\Api\Data\PaymentMethodInterface::class)
129  ->disableOriginalConstructor()
130  ->setMethods(['getCode'])
131  ->getMockForAbstractClass();
132  $braintreePaypalPaymentMethod = $this
133  ->getMockBuilder(\Magento\Payment\Api\Data\PaymentMethodInterface::class)
134  ->disableOriginalConstructor()
135  ->setMethods(['getCode'])
136  ->getMockForAbstractClass();
137 
138  $braintreePaymentMethod->expects($this->any())->method('getCode')->willReturn('braintree');
139  $braintreePaypalPaymentMethod->expects($this->any())->method('getCode')->willReturn('braintree_paypal');
140 
141  return [
142  [$jsLayout, [], $result1],
143  [$jsLayout, [$braintreePaymentMethod, $braintreePaypalPaymentMethod], $result2]
144  ];
145  }
146 }