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\Base; |
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 Magento\Framework\App\Request\Http; |
37
|
|
|
use Payone\Core\Test\Unit\BaseTestCase; |
38
|
|
|
use Payone\Core\Model\Test\PayoneObjectManager; |
39
|
|
|
|
40
|
|
|
class BaseTest extends BaseTestCase |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* @var ObjectManager|PayoneObjectManager |
44
|
|
|
*/ |
45
|
|
|
private $objectManager; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var Base |
49
|
|
|
*/ |
50
|
|
|
private $base; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
54
|
|
|
*/ |
55
|
|
|
private $scopeConfig; |
56
|
|
|
|
57
|
|
|
protected function setUp() |
58
|
|
|
{ |
59
|
|
|
$this->objectManager = $this->getObjectManager(); |
60
|
|
|
|
61
|
|
|
$request = $this->getMockBuilder(Http::class)->disableOriginalConstructor()->getMock(); |
62
|
|
|
$request->method('getParam')->willReturn('value'); |
63
|
|
|
|
64
|
|
|
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock(); |
65
|
|
|
$context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig, 'httpRequest' => $request]); |
66
|
|
|
|
67
|
|
|
$store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock(); |
68
|
|
|
$store->method('getCode')->willReturn(null); |
69
|
|
|
|
70
|
|
|
$storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock(); |
71
|
|
|
$storeManager->method('getStore')->willReturn($store); |
72
|
|
|
$storeManager->method('getStores')->willReturn(['de' => $store, 'en' => $store, 'fr' => $store, 'nl' => $store]); |
73
|
|
|
|
74
|
|
|
$this->base = $this->objectManager->getObject(Base::class, [ |
75
|
|
|
'context' => $context, |
76
|
|
|
'storeManager' => $storeManager |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testGetConfigParam() |
81
|
|
|
{ |
82
|
|
|
$expected = 'authorization'; |
83
|
|
|
|
84
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
85
|
|
|
->method('getValue') |
86
|
|
|
->willReturnMap( |
87
|
|
|
[ |
88
|
|
|
['payone_general/global/request_type', ScopeInterface::SCOPE_STORE, null, $expected] |
89
|
|
|
] |
90
|
|
|
); |
91
|
|
|
$result = $this->base->getConfigParam('request_type'); |
92
|
|
|
$this->assertEquals($expected, $result); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testGetConfigParamAllStores() |
96
|
|
|
{ |
97
|
|
|
$this->scopeConfig->expects($this->any()) |
|
|
|
|
98
|
|
|
->method('getValue') |
99
|
|
|
->willReturnMap( |
100
|
|
|
[ |
101
|
|
|
['payone_general/global/mid', ScopeInterface::SCOPE_STORE, 'de', '12345'], |
102
|
|
|
['payone_general/global/mid', ScopeInterface::SCOPE_STORE, 'en', '23456'], |
103
|
|
|
['payone_general/global/mid', ScopeInterface::SCOPE_STORE, 'fr', '12345'], |
104
|
|
|
['payone_general/global/mid', ScopeInterface::SCOPE_STORE, 'nl', '34567'], |
105
|
|
|
] |
106
|
|
|
); |
107
|
|
|
$result = $this->base->getConfigParamAllStores('mid'); |
108
|
|
|
$expected = ['12345', '23456', '34567']; |
109
|
|
|
$this->assertEquals($expected, $result); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testGetRequestParameter() |
113
|
|
|
{ |
114
|
|
|
$expected = 'value'; |
115
|
|
|
$result = $this->base->getRequestParameter('param'); |
116
|
|
|
$this->assertEquals($expected, $result); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: