|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2013-2017 Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Payment\Test\Unit\Plugin; |
| 7 | + |
| 8 | +/** |
| 9 | + * Class PaymentConfigurationProcessTest. |
| 10 | + */ |
| 11 | +class PaymentConfigurationProcessTest extends \PHPUnit_Framework_TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject |
| 15 | + */ |
| 16 | + private $storeManager; |
| 17 | + |
| 18 | + /** |
| 19 | + * @var \Magento\Store\Api\Data\StoreInterface|\PHPUnit_Framework_MockObject_MockObject |
| 20 | + */ |
| 21 | + private $store; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var \Magento\Payment\Api\PaymentMethodListInterface|\PHPUnit_Framework_MockObject_MockObject |
| 25 | + */ |
| 26 | + private $paymentMethodList; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var \Magento\Checkout\Block\Checkout\LayoutProcessor|\PHPUnit_Framework_MockObject_MockObject |
| 30 | + */ |
| 31 | + private $layoutProcessor; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var \Magento\Payment\Plugin\PaymentConfigurationProcess |
| 35 | + */ |
| 36 | + private $plugin; |
| 37 | + |
| 38 | + /** |
| 39 | + * Set up |
| 40 | + */ |
| 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 | + |
| 74 | + /** |
| 75 | + * @param array $jsLayout |
| 76 | + * @param array $activePaymentList |
| 77 | + * @param array $expectedResult |
| 78 | + * @dataProvider beforeProcessDataProvider |
| 79 | + */ |
| 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 | + |
| 93 | + /** |
| 94 | + * Data provider for BeforeProcess. |
| 95 | + * |
| 96 | + * @return array |
| 97 | + */ |
| 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 | +} |
0 commit comments