|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
|
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
7
|
|
|
* (at your option) any later version. |
|
8
|
|
|
* |
|
9
|
|
|
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
* GNU Lesser General Public License for more details. |
|
13
|
|
|
* |
|
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
15
|
|
|
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
* |
|
17
|
|
|
* PHP version 5 |
|
18
|
|
|
* |
|
19
|
|
|
* @category Payone |
|
20
|
|
|
* @package Payone_Magento2_Plugin |
|
21
|
|
|
* @author FATCHIP GmbH <[email protected]> |
|
22
|
|
|
* @copyright 2003 - 2017 Payone GmbH |
|
23
|
|
|
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
|
24
|
|
|
* @link http://www.payone.de |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace Payone\Core\Test\Unit\Helper; |
|
28
|
|
|
|
|
29
|
|
|
use Payone\Core\Helper\Payment; |
|
30
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
|
31
|
|
|
use Magento\Store\Model\StoreManagerInterface; |
|
32
|
|
|
use Magento\Store\Api\Data\StoreInterface; |
|
33
|
|
|
use Magento\Framework\App\Helper\Context; |
|
34
|
|
|
use Magento\Store\Model\ScopeInterface; |
|
35
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface; |
|
36
|
|
|
use Payone\Core\Model\PayoneConfig; |
|
37
|
|
|
use Payone\Core\Helper\Toolkit; |
|
38
|
|
|
use Payone\Core\Test\Unit\BaseTestCase; |
|
39
|
|
|
use Payone\Core\Model\Test\PayoneObjectManager; |
|
40
|
|
|
|
|
41
|
|
|
class PaymentTest extends BaseTestCase |
|
42
|
|
|
{ |
|
43
|
|
|
/** |
|
44
|
|
|
* @var ObjectManager|PayoneObjectManager |
|
45
|
|
|
*/ |
|
46
|
|
|
private $objectManager; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var Payment |
|
50
|
|
|
*/ |
|
51
|
|
|
private $payment; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
|
55
|
|
|
*/ |
|
56
|
|
|
private $scopeConfig; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var Toolkit |
|
60
|
|
|
*/ |
|
61
|
|
|
private $toolkitHelper; |
|
62
|
|
|
|
|
63
|
|
View Code Duplication |
protected function setUp() |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
$this->objectManager = $this->getObjectManager(); |
|
66
|
|
|
|
|
67
|
|
|
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock(); |
|
68
|
|
|
$context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig]); |
|
69
|
|
|
|
|
70
|
|
|
$store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock(); |
|
71
|
|
|
$store->method('getCode')->willReturn(null); |
|
72
|
|
|
|
|
73
|
|
|
$storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock(); |
|
74
|
|
|
$storeManager->method('getStore')->willReturn($store); |
|
75
|
|
|
|
|
76
|
|
|
$this->toolkitHelper = $this->objectManager->getObject(Toolkit::class); |
|
77
|
|
|
|
|
78
|
|
|
$this->payment = $this->objectManager->getObject(Payment::class, [ |
|
79
|
|
|
'context' => $context, |
|
80
|
|
|
'storeManager' => $storeManager, |
|
81
|
|
|
'toolkitHelper' => $this->toolkitHelper |
|
82
|
|
|
]); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testGetAvailablePaymentTypes() |
|
86
|
|
|
{ |
|
87
|
|
|
$result = $this->payment->getAvailablePaymentTypes(); |
|
88
|
|
|
$this->assertContains(PayoneConfig::METHOD_CREDITCARD, $result); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
View Code Duplication |
public function testGetAvailableCreditcardTypes() |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
$creditcardTypes = 'V,M'; |
|
94
|
|
|
$expected = [ |
|
95
|
|
|
['id' => 'V', 'title' => 'Visa'], |
|
96
|
|
|
['id' => 'M', 'title' => 'Mastercard'] |
|
97
|
|
|
]; |
|
98
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
99
|
|
|
->method('getValue') |
|
100
|
|
|
->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_CREDITCARD.'/types', ScopeInterface::SCOPE_STORE, null, $creditcardTypes]]); |
|
101
|
|
|
|
|
102
|
|
|
$result = $this->payment->getAvailableCreditcardTypes(); |
|
103
|
|
|
$this->assertEquals($expected, $result); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
View Code Duplication |
public function testIsCheckCvcActive() |
|
|
|
|
|
|
107
|
|
|
{ |
|
108
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
109
|
|
|
->method('getValue') |
|
110
|
|
|
->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_CREDITCARD.'/check_cvc', ScopeInterface::SCOPE_STORE, null, 1]]); |
|
111
|
|
|
$result = $this->payment->isCheckCvcActive(); |
|
112
|
|
|
$this->assertTrue($result); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
View Code Duplication |
public function testIsMandateManagementActive() |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
118
|
|
|
->method('getValue') |
|
119
|
|
|
->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_DEBIT.'/sepa_mandate_enabled', ScopeInterface::SCOPE_STORE, null, 1]]); |
|
120
|
|
|
$result = $this->payment->isMandateManagementActive(); |
|
121
|
|
|
$this->assertTrue($result); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
View Code Duplication |
public function testIsMandateManagementDownloadActive() |
|
|
|
|
|
|
125
|
|
|
{ |
|
126
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
127
|
|
|
->method('getValue') |
|
128
|
|
|
->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_DEBIT.'/sepa_mandate_download_enabled', ScopeInterface::SCOPE_STORE, null, 1]]); |
|
129
|
|
|
$result = $this->payment->isMandateManagementDownloadActive(); |
|
130
|
|
|
$this->assertTrue($result); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function testGetStatusMappingByCode() |
|
134
|
|
|
{ |
|
135
|
|
|
$mapping = [ |
|
136
|
|
|
'key' => [ |
|
137
|
|
|
'txaction' => 'appointed', |
|
138
|
|
|
'state_status' => 'processing' |
|
139
|
|
|
] |
|
140
|
|
|
]; |
|
141
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
142
|
|
|
->method('getValue') |
|
143
|
|
|
->willReturnMap([['payone_general/statusmapping/'.PayoneConfig::METHOD_CREDITCARD, ScopeInterface::SCOPE_STORE, null, $this->toolkitHelper->serialize($mapping)]]); |
|
144
|
|
|
$result = $this->payment->getStatusMappingByCode(PayoneConfig::METHOD_CREDITCARD); |
|
145
|
|
|
$expected = ['appointed' => 'processing']; |
|
146
|
|
|
$this->assertEquals($expected, $result); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function testGetBankaccountCheckBlockedMessage() |
|
150
|
|
|
{ |
|
151
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
152
|
|
|
->method('getValue') |
|
153
|
|
|
->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_DEBIT.'/message_response_blocked/', ScopeInterface::SCOPE_STORE, null, '']]); |
|
154
|
|
|
$result = $this->payment->getBankaccountCheckBlockedMessage(); |
|
155
|
|
|
$expected = 'Bankdata invalid.'; |
|
156
|
|
|
$this->assertEquals($expected, $result); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
View Code Duplication |
public function testIsPayPalExpressActive() |
|
|
|
|
|
|
160
|
|
|
{ |
|
161
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
162
|
|
|
->method('getValue') |
|
163
|
|
|
->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_PAYPAL.'/express_active', ScopeInterface::SCOPE_STORE, null, 1]]); |
|
164
|
|
|
$result = $this->payment->isPayPalExpressActive(); |
|
165
|
|
|
$this->assertTrue($result); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
public function testGetPaymentAbbreviation() |
|
169
|
|
|
{ |
|
170
|
|
|
$result = $this->payment->getPaymentAbbreviation(PayoneConfig::METHOD_CREDITCARD); |
|
171
|
|
|
$expected = 'cc'; |
|
172
|
|
|
$this->assertEquals($expected, $result); |
|
173
|
|
|
|
|
174
|
|
|
$result = $this->payment->getPaymentAbbreviation('not_existing'); |
|
175
|
|
|
$expected = 'unknown'; |
|
176
|
|
|
$this->assertEquals($expected, $result); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
View Code Duplication |
public function testGetKlarnaStoreIds() |
|
|
|
|
|
|
180
|
|
|
{ |
|
181
|
|
|
$storeIds = ['key' => ['store_id' => '123', 'countries' => ['DE', 'AT']]]; |
|
182
|
|
|
|
|
183
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
184
|
|
|
->method('getValue') |
|
185
|
|
|
->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_KLARNA.'/klarna_config', ScopeInterface::SCOPE_STORE, null, $this->toolkitHelper->serialize($storeIds)]]); |
|
186
|
|
|
|
|
187
|
|
|
$expected = ['DE' => '123', 'AT' => '123']; |
|
188
|
|
|
$result = $this->payment->getKlarnaStoreIds(); |
|
189
|
|
|
$this->assertEquals($expected, $result); |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.