|
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\Request; |
|
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\Environment; |
|
37
|
|
|
use Payone\Core\Helper\Shop; |
|
38
|
|
|
use Payone\Core\Model\PayoneConfig; |
|
39
|
|
|
use Locale; |
|
40
|
|
|
|
|
41
|
|
|
class RequestTest extends \PHPUnit_Framework_TestCase |
|
42
|
|
|
{ |
|
43
|
|
|
/** |
|
44
|
|
|
* @var ObjectManager |
|
45
|
|
|
*/ |
|
46
|
|
|
private $objectManager; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var Request |
|
50
|
|
|
*/ |
|
51
|
|
|
private $request; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
|
55
|
|
|
*/ |
|
56
|
|
|
private $scopeConfig; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var string |
|
60
|
|
|
*/ |
|
61
|
|
|
private $encoding = 'UTF-8'; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @var string |
|
65
|
|
|
*/ |
|
66
|
|
|
private $version = '1.2.3'; |
|
67
|
|
|
|
|
68
|
|
|
protected function setUp() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->objectManager = new ObjectManager($this); |
|
71
|
|
|
|
|
72
|
|
|
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock(); |
|
73
|
|
|
$context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig]); |
|
74
|
|
|
|
|
75
|
|
|
$store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock(); |
|
76
|
|
|
$store->method('getCode')->willReturn(null); |
|
77
|
|
|
|
|
78
|
|
|
$storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock(); |
|
79
|
|
|
$storeManager->method('getStore')->willReturn($store); |
|
80
|
|
|
|
|
81
|
|
|
$environmentHelper = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock(); |
|
82
|
|
|
$environmentHelper->method('getEncoding')->willReturn($this->encoding); |
|
83
|
|
|
|
|
84
|
|
|
$shopHelper = $this->getMockBuilder(Shop::class)->disableOriginalConstructor()->getMock(); |
|
85
|
|
|
$shopHelper->method('getMagentoVersion')->willReturn($this->version); |
|
86
|
|
|
|
|
87
|
|
|
$this->request = $this->objectManager->getObject(Request::class, [ |
|
88
|
|
|
'context' => $context, |
|
89
|
|
|
'storeManager' => $storeManager, |
|
90
|
|
|
'environmentHelper' => $environmentHelper, |
|
91
|
|
|
'shopHelper' => $shopHelper |
|
92
|
|
|
]); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testGetBankaccountCheckRequest() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
98
|
|
|
->method('getValue') |
|
99
|
|
|
->willReturnMap( |
|
100
|
|
|
[ |
|
101
|
|
|
['payone_payment/'.PayoneConfig::METHOD_DEBIT.'/check_bankaccount', ScopeInterface::SCOPE_STORE, null, '1'], |
|
102
|
|
|
['payone_payment/'.PayoneConfig::METHOD_DEBIT.'/mode', ScopeInterface::SCOPE_STORE, null, 'live'], |
|
103
|
|
|
['payone_general/global/mid', ScopeInterface::SCOPE_STORE, null, '12345'], |
|
104
|
|
|
['payone_general/global/aid', ScopeInterface::SCOPE_STORE, null, '54321'], |
|
105
|
|
|
['payone_general/global/portalid', ScopeInterface::SCOPE_STORE, null, '0815'], |
|
106
|
|
|
['payone_general/global/key', ScopeInterface::SCOPE_STORE, null, 'abcde'], |
|
107
|
|
|
['payone_payment/'.PayoneConfig::METHOD_DEBIT.'/bankaccountcheck_type', ScopeInterface::SCOPE_STORE, null, '1'], |
|
108
|
|
|
] |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
$result = $this->request->getBankaccountCheckRequest(); |
|
112
|
|
|
$expected = [ |
|
113
|
|
|
'request' => 'bankaccountcheck', |
|
114
|
|
|
'responsetype' => 'JSON', |
|
115
|
|
|
'mode' => 'live', |
|
116
|
|
|
'mid' => '12345', |
|
117
|
|
|
'aid' => '54321', |
|
118
|
|
|
'portalid' => '0815', |
|
119
|
|
|
'encoding' => $this->encoding, |
|
120
|
|
|
'language' => Locale::getPrimaryLanguage(Locale::getDefault()), |
|
121
|
|
|
'checktype' => '1', |
|
122
|
|
|
'hash' => $this->request->getBankaccountCheckRequestHash(), |
|
123
|
|
|
'integrator_name' => 'Magento2', |
|
124
|
|
|
'integrator_version' => $this->version, |
|
125
|
|
|
'solution_name' => 'fatchip', |
|
126
|
|
|
'solution_version' => PayoneConfig::MODULE_VERSION, |
|
127
|
|
|
]; |
|
128
|
|
|
$this->assertEquals($expected, $result); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function testGetBankaccountCheckRequestEmpty() |
|
132
|
|
|
{ |
|
133
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
134
|
|
|
->method('getValue') |
|
135
|
|
|
->willReturnMap([['payone_payment/'.PayoneConfig::METHOD_DEBIT.'/check_bankaccount', ScopeInterface::SCOPE_STORE, null, '0']]); |
|
136
|
|
|
$result = $this->request->getBankaccountCheckRequest(); |
|
137
|
|
|
$expected = ''; |
|
138
|
|
|
$this->assertEquals($expected, $result); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function testGetHostedIframeRequest() |
|
142
|
|
|
{ |
|
143
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
|
|
144
|
|
|
->method('getValue') |
|
145
|
|
|
->willReturnMap( |
|
146
|
|
|
[ |
|
147
|
|
|
['payone_payment/'.PayoneConfig::METHOD_CREDITCARD.'/mode', ScopeInterface::SCOPE_STORE, null, 'live'], |
|
148
|
|
|
['payone_general/global/mid', ScopeInterface::SCOPE_STORE, null, '12345'], |
|
149
|
|
|
['payone_general/global/aid', ScopeInterface::SCOPE_STORE, null, '54321'], |
|
150
|
|
|
['payone_general/global/portalid', ScopeInterface::SCOPE_STORE, null, '0815'], |
|
151
|
|
|
['payone_general/global/key', ScopeInterface::SCOPE_STORE, null, 'abcde'], |
|
152
|
|
|
] |
|
153
|
|
|
); |
|
154
|
|
|
|
|
155
|
|
|
$result = $this->request->getHostedIframeRequest(); |
|
156
|
|
|
$expected = [ |
|
157
|
|
|
'request' => 'creditcardcheck', |
|
158
|
|
|
'responsetype' => 'JSON', |
|
159
|
|
|
'mode' => 'live', |
|
160
|
|
|
'mid' => '12345', |
|
161
|
|
|
'aid' => '54321', |
|
162
|
|
|
'portalid' => '0815', |
|
163
|
|
|
'encoding' => $this->encoding, |
|
164
|
|
|
'storecarddata' => 'yes', |
|
165
|
|
|
'hash' => $this->request->getHostedIframeRequestCCHash() |
|
166
|
|
|
]; |
|
167
|
|
|
$this->assertEquals($expected, $result); |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
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.