|
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\ConfigExport; |
|
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\Helper\Database; |
|
37
|
|
|
use Payone\Core\Helper\Config; |
|
38
|
|
|
use Payone\Core\Helper\Payment; |
|
39
|
|
|
|
|
40
|
|
|
class ConfigExportTest extends \PHPUnit_Framework_TestCase |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @var ObjectManager |
|
44
|
|
|
*/ |
|
45
|
|
|
private $objectManager; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var ConfigExport |
|
49
|
|
|
*/ |
|
50
|
|
|
private $configExport; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
|
54
|
|
|
*/ |
|
55
|
|
|
private $scopeConfig; |
|
56
|
|
|
|
|
57
|
|
|
protected function setUp() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->objectManager = new ObjectManager($this); |
|
60
|
|
|
|
|
61
|
|
|
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock(); |
|
62
|
|
|
$context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig]); |
|
63
|
|
|
|
|
64
|
|
|
$store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock(); |
|
65
|
|
|
$store->method('getCode')->willReturn(null); |
|
66
|
|
|
|
|
67
|
|
|
$storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock(); |
|
68
|
|
|
$storeManager->method('getStore')->willReturn($store); |
|
69
|
|
|
|
|
70
|
|
|
$databaseHelper = $this->getMockBuilder(Database::class)->disableOriginalConstructor()->getMock(); |
|
71
|
|
|
$databaseHelper->method('getModuleInfo')->willReturn([ |
|
72
|
|
|
['module' => 'Payone_Core', 'schema_version' => '1.3.1'], |
|
73
|
|
|
['module' => 'Another_Module', 'schema_version' => '2.3.4'] |
|
74
|
|
|
]); |
|
75
|
|
|
|
|
76
|
|
|
$configHelper = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); |
|
77
|
|
|
$configHelper->method('getForwardingUrls')->willReturn([ |
|
78
|
|
|
['txaction' => ['appointed', 'pending'], 'url' => 'http://forward.to', 'timeout' => 15], |
|
79
|
|
|
['txaction' => ['paid'], 'url' => 'http://forward.to', 'timeout' => null] |
|
80
|
|
|
]); |
|
81
|
|
|
|
|
82
|
|
|
$paymentHelper = $this->objectManager->getObject(Payment::class); |
|
83
|
|
|
|
|
84
|
|
|
$this->configExport = $this->objectManager->getObject(ConfigExport::class, [ |
|
85
|
|
|
'context' => $context, |
|
86
|
|
|
'storeManager' => $storeManager, |
|
87
|
|
|
'paymentHelper' => $paymentHelper, |
|
88
|
|
|
'databaseHelper' => $databaseHelper, |
|
89
|
|
|
'configHelper' => $configHelper |
|
90
|
|
|
]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function testGetModuleInfo() |
|
94
|
|
|
{ |
|
95
|
|
|
$result = $this->configExport->getModuleInfo(); |
|
96
|
|
|
$expected = [ |
|
97
|
|
|
'Payone_Core' => '1.3.1', |
|
98
|
|
|
'Another_Module' => '2.3.4' |
|
99
|
|
|
]; |
|
100
|
|
|
$this->assertEquals($expected, $result); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function testGetPaymentConfigNonGlobal() |
|
104
|
|
|
{ |
|
105
|
|
|
$expected = '12345'; |
|
106
|
|
|
|
|
107
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
108
|
|
|
->method('getValue') |
|
109
|
|
|
->willReturnMap( |
|
110
|
|
|
[ |
|
111
|
|
|
['payone_payment/payone_creditcard/use_global', ScopeInterface::SCOPE_STORE, null, 0], |
|
112
|
|
|
['payone_payment/payone_creditcard/mid', ScopeInterface::SCOPE_STORE, null, $expected] |
|
113
|
|
|
] |
|
114
|
|
|
); |
|
115
|
|
|
$result = $this->configExport->getPaymentConfig('mid', 'payone_creditcard', null, false); |
|
116
|
|
|
$this->assertEquals($expected, $result); |
|
117
|
|
|
$result = $this->configExport->getPaymentConfig('mid', 'payone_creditcard', null, true); |
|
118
|
|
|
$this->assertEquals($expected, $result); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function testGetPaymentConfigGlobal() |
|
122
|
|
|
{ |
|
123
|
|
|
$expected = '12345'; |
|
124
|
|
|
|
|
125
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
126
|
|
|
->method('getValue') |
|
127
|
|
|
->willReturnMap( |
|
128
|
|
|
[ |
|
129
|
|
|
['payone_payment/payone_creditcard/use_global', ScopeInterface::SCOPE_STORE, null, 1], |
|
130
|
|
|
['payone_payment/payone_creditcard/mid', ScopeInterface::SCOPE_STORE, null, 'random_mid'], |
|
131
|
|
|
['payone_general/global/mid', ScopeInterface::SCOPE_STORE, null, $expected] |
|
132
|
|
|
] |
|
133
|
|
|
); |
|
134
|
|
|
$result = $this->configExport->getPaymentConfig('mid', 'payone_creditcard', null, true); |
|
135
|
|
|
$this->assertEquals($expected, $result); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function testGetCountries() |
|
139
|
|
|
{ |
|
140
|
|
|
$expected = 'DE,FR,NL'; |
|
141
|
|
|
|
|
142
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
143
|
|
|
->method('getValue') |
|
144
|
|
|
->willReturnMap( |
|
145
|
|
|
[ |
|
146
|
|
|
['payone_payment/payone_creditcard/use_global', ScopeInterface::SCOPE_STORE, null, 0], |
|
147
|
|
|
['payone_payment/payone_creditcard/allowspecific', ScopeInterface::SCOPE_STORE, null, 1], |
|
148
|
|
|
['payone_payment/payone_creditcard/specificcountry', ScopeInterface::SCOPE_STORE, null, $expected], |
|
149
|
|
|
['payone_payment/payone_invoice/use_global', ScopeInterface::SCOPE_STORE, null, 1], |
|
150
|
|
|
['payone_general/global/allowspecific', ScopeInterface::SCOPE_STORE, null, 1], |
|
151
|
|
|
['payone_general/global/specificcountry', ScopeInterface::SCOPE_STORE, null, $expected], |
|
152
|
|
|
['payone_payment/payone_paypal/use_global', ScopeInterface::SCOPE_STORE, null, 0], |
|
153
|
|
|
['payone_general/payone_paypal/allowspecific', ScopeInterface::SCOPE_STORE, null, 0] |
|
154
|
|
|
] |
|
155
|
|
|
); |
|
156
|
|
|
|
|
157
|
|
|
$result = $this->configExport->getCountries('payone_creditcard', null); |
|
158
|
|
|
$this->assertEquals($expected, $result); |
|
159
|
|
|
|
|
160
|
|
|
$result = $this->configExport->getCountries('payone_invoice', null); |
|
161
|
|
|
$this->assertEquals($expected, $result); |
|
162
|
|
|
|
|
163
|
|
|
$result = $this->configExport->getCountries('payone_paypal', null); |
|
164
|
|
|
$expected = ''; |
|
165
|
|
|
$this->assertEquals($expected, $result); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
public function testGetForwardings() |
|
169
|
|
|
{ |
|
170
|
|
|
$result = $this->configExport->getForwardings(null); |
|
171
|
|
|
$expected = [ |
|
172
|
|
|
['status' => 'appointed,pending', 'url' => 'http://forward.to', 'timeout' => 15], |
|
173
|
|
|
['status' => 'paid', 'url' => 'http://forward.to', 'timeout' => 0], |
|
174
|
|
|
]; |
|
175
|
|
|
$this->assertEquals($expected, $result); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function testGetMappings() |
|
179
|
|
|
{ |
|
180
|
|
|
$config = ['random' => ['txaction' => 'appointed', 'state_status' => 'processing']]; |
|
181
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
182
|
|
|
->method('getValue') |
|
183
|
|
|
->willReturnMap( |
|
184
|
|
|
[ |
|
185
|
|
|
['payone_general/statusmapping/payone_creditcard', ScopeInterface::SCOPE_STORE, null, serialize($config)] |
|
186
|
|
|
] |
|
187
|
|
|
); |
|
188
|
|
|
|
|
189
|
|
|
$result = $this->configExport->getMappings(null); |
|
190
|
|
|
$expected = ['cc' => [['from' => 'appointed', 'to' => 'processing']]]; |
|
191
|
|
|
$this->assertEquals($result, $expected); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.