This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Database; |
||
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\Framework\App\Config\ScopeConfigInterface; |
||
35 | use Magento\Framework\App\ResourceConnection; |
||
36 | use Magento\Framework\DB\Adapter\AdapterInterface; |
||
37 | use Magento\Quote\Model\Quote\Address; |
||
38 | use Payone\Core\Test\Unit\BaseTestCase; |
||
39 | use Payone\Core\Model\Test\PayoneObjectManager; |
||
40 | |||
41 | class DatabaseTest extends BaseTestCase |
||
42 | { |
||
43 | /** |
||
44 | * @var ObjectManager|PayoneObjectManager |
||
45 | */ |
||
46 | private $objectManager; |
||
47 | |||
48 | /** |
||
49 | * @var Database |
||
50 | */ |
||
51 | private $database; |
||
52 | |||
53 | /** |
||
54 | * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
||
55 | */ |
||
56 | private $scopeConfig; |
||
57 | |||
58 | /** |
||
59 | * @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject |
||
60 | */ |
||
61 | private $connection; |
||
62 | |||
63 | /** |
||
64 | * @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject |
||
65 | */ |
||
66 | private $databaseResource; |
||
67 | |||
68 | protected function setUp() |
||
69 | { |
||
70 | $this->objectManager = $this->getObjectManager(); |
||
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('getId')->willReturn(15); |
||
77 | |||
78 | $storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock(); |
||
79 | $storeManager->method('getStore')->willReturn($store); |
||
80 | |||
81 | $this->connection = $this->getMockBuilder(AdapterInterface::class)->disableOriginalConstructor()->getMock(); |
||
82 | |||
83 | $this->databaseResource = $this->getMockBuilder(ResourceConnection::class)->disableOriginalConstructor()->getMock(); |
||
84 | $this->databaseResource->method('getConnection')->willReturn($this->connection); |
||
85 | |||
86 | $this->database = $this->objectManager->getObject(Database::class, [ |
||
87 | 'context' => $context, |
||
88 | 'storeManager' => $storeManager, |
||
89 | 'databaseResource' => $this->databaseResource |
||
90 | ]); |
||
91 | } |
||
92 | |||
93 | View Code Duplication | public function testGetStateByStatus() |
|
0 ignored issues
–
show
|
|||
94 | { |
||
95 | $expected = 'complete'; |
||
96 | |||
97 | $this->databaseResource->method('getTableName')->willReturn('sales_order_status_state'); |
||
98 | $this->connection->method('fetchOne')->willReturn($expected); |
||
99 | |||
100 | $result = $this->database->getStateByStatus($expected); |
||
101 | $this->assertEquals($expected, $result); |
||
102 | } |
||
103 | |||
104 | View Code Duplication | public function testGetOrderIncrementIdByTxid() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
105 | { |
||
106 | $expected = '000000123'; |
||
107 | |||
108 | $this->databaseResource->method('getTableName')->willReturn('payone_protocol_api'); |
||
109 | $this->connection->method('fetchOne')->willReturn($expected); |
||
110 | |||
111 | $result = $this->database->getOrderIncrementIdByTxid('200001234'); |
||
112 | $this->assertEquals($expected, $result); |
||
113 | } |
||
114 | |||
115 | public function testGetModuleInfo() |
||
116 | { |
||
117 | $expected = [ |
||
118 | ['module' => 'Test_Module', 'schema_version' => '1.2.3'], |
||
119 | ['module' => 'Another_Module', 'schema_version' => '2.1.7'] |
||
120 | ]; |
||
121 | |||
122 | $this->databaseResource->method('getTableName')->willReturn('setup_module'); |
||
123 | $this->connection->method('fetchAll')->willReturn($expected); |
||
124 | |||
125 | $result = $this->database->getModuleInfo(); |
||
126 | $this->assertEquals($expected, $result); |
||
127 | } |
||
128 | |||
129 | View Code Duplication | public function testGetIncrementIdByOrderId() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
130 | { |
||
131 | $expected = '000000001'; |
||
132 | |||
133 | $this->databaseResource->method('getTableName')->willReturn('sales_order'); |
||
134 | $this->connection->method('fetchOne')->willReturn($expected); |
||
135 | |||
136 | $result = $this->database->getIncrementIdByOrderId('1'); |
||
137 | $this->assertEquals($expected, $result); |
||
138 | } |
||
139 | |||
140 | View Code Duplication | public function testGetPayoneUserIdByCustNr() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
141 | { |
||
142 | $expected = '15'; |
||
143 | |||
144 | $this->databaseResource->method('getTableName')->willReturn('payone_protocol_transactionstatus'); |
||
145 | $this->connection->method('fetchOne')->willReturn($expected); |
||
146 | |||
147 | $result = $this->database->getPayoneUserIdByCustNr('803'); |
||
148 | $this->assertEquals($expected, $result); |
||
149 | } |
||
150 | |||
151 | View Code Duplication | public function testGetSequenceNumber() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
152 | { |
||
153 | $expected = 38; |
||
154 | |||
155 | $this->databaseResource->method('getTableName')->willReturn('payone_protocol_transactionstatus'); |
||
156 | $this->connection->method('fetchOne')->willReturn($expected - 1); |
||
157 | |||
158 | $result = $this->database->getSequenceNumber('1207'); |
||
159 | $this->assertEquals($expected, $result); |
||
160 | } |
||
161 | |||
162 | View Code Duplication | public function testGetSequenceNumberNull() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
163 | { |
||
164 | $expected = 0; |
||
165 | |||
166 | $this->databaseResource->method('getTableName')->willReturn('payone_protocol_transactionstatus'); |
||
167 | $this->connection->method('fetchOne')->willReturn(null); |
||
168 | |||
169 | $result = $this->database->getSequenceNumber('1207'); |
||
170 | $this->assertEquals($expected, $result); |
||
171 | } |
||
172 | |||
173 | View Code Duplication | public function testGetConfigParamWithoutCache() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
174 | { |
||
175 | $expected = '17123'; |
||
176 | |||
177 | $this->databaseResource->method('getTableName')->willReturn('payone_protocol_transactionstatus'); |
||
178 | $this->connection->method('fetchOne')->willReturn($expected); |
||
179 | |||
180 | $result = $this->database->getConfigParamWithoutCache('mid'); |
||
181 | $this->assertEquals($expected, $result); |
||
182 | } |
||
183 | |||
184 | public function testGetOldAddressStatus() |
||
185 | { |
||
186 | $expected = 'G'; |
||
187 | |||
188 | $address = $this->getMockBuilder(Address::class) |
||
189 | ->disableOriginalConstructor() |
||
190 | ->setMethods(['getFirstname', 'getLastname', 'getStreet', 'getCity', 'getRegion', 'getPostcode', 'getCountryId', 'getId', 'getCustomerId', 'getAddressType']) |
||
191 | ->getMock(); |
||
192 | $address->method('getFirstname')->willReturn('Paul'); |
||
193 | $address->method('getLastname')->willReturn('Payer'); |
||
194 | $address->method('getStreet')->willReturn(['Teststr. 3']); |
||
195 | $address->method('getCity')->willReturn('Paycity'); |
||
196 | $address->method('getRegion')->willReturn('Bremen'); |
||
197 | $address->method('getPostcode')->willReturn('12345'); |
||
198 | $address->method('getCountryId')->willReturn('DE'); |
||
199 | $address->method('getId')->willReturn('5'); |
||
200 | $address->method('getCustomerId')->willReturn('18'); |
||
201 | $address->method('getAddressType')->willReturn('billing'); |
||
202 | |||
203 | $this->databaseResource->method('getTableName')->willReturn('quote_address'); |
||
204 | $this->connection->method('fetchOne')->willReturn($expected); |
||
205 | |||
206 | $result = $this->database->getOldAddressStatus($address); |
||
207 | $this->assertEquals($expected, $result); |
||
208 | |||
209 | $result = $this->database->getOldAddressStatus($address, false); |
||
210 | $this->assertEquals($expected, $result); |
||
211 | } |
||
212 | } |
||
213 |
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.