|
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\Model\ResourceModel; |
|
28
|
|
|
|
|
29
|
|
|
use Payone\Core\Model\ResourceModel\CheckedAddresses as ClassToTest; |
|
30
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
|
31
|
|
|
use Payone\Core\Helper\Shop; |
|
32
|
|
|
use Magento\Quote\Api\Data\AddressInterface; |
|
33
|
|
|
use Magento\Framework\Model\ResourceModel\Db\Context; |
|
34
|
|
|
use Magento\Framework\App\ResourceConnection; |
|
35
|
|
|
use Magento\Framework\DB\Adapter\AdapterInterface; |
|
36
|
|
|
|
|
37
|
|
|
class CheckedAddressesTest extends \PHPUnit_Framework_TestCase |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* @var ClassToTest |
|
41
|
|
|
*/ |
|
42
|
|
|
private $classToTest; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var ObjectManager |
|
46
|
|
|
*/ |
|
47
|
|
|
private $objectManager; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var AddressInterface|\PHPUnit_Framework_MockObject_MockObject |
|
51
|
|
|
*/ |
|
52
|
|
|
private $address; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var Shop|\PHPUnit_Framework_MockObject_MockObject |
|
56
|
|
|
*/ |
|
57
|
|
|
private $shopHelper; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject |
|
61
|
|
|
*/ |
|
62
|
|
|
private $connection; |
|
63
|
|
|
|
|
64
|
|
|
protected function setUp() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->objectManager = new ObjectManager($this); |
|
67
|
|
|
|
|
68
|
|
|
$this->address = $this->getMockBuilder(AddressInterface::class)->disableOriginalConstructor()->getMock(); |
|
69
|
|
|
$this->address->method('getFirstname')->willReturn('Paul'); |
|
70
|
|
|
$this->address->method('getLastname')->willReturn('Payer'); |
|
71
|
|
|
$this->address->method('getCompany')->willReturn('Testcompany Ldt.'); |
|
72
|
|
|
$this->address->method('getStreet')->willReturn(['Teststr. 12', '3rd floor']); |
|
73
|
|
|
$this->address->method('getPostcode')->willReturn('54321'); |
|
74
|
|
|
$this->address->method('getCity')->willReturn('Berlin'); |
|
75
|
|
|
$this->address->method('getCountryId')->willReturn('DE'); |
|
76
|
|
|
$this->address->method('getRegionCode')->willReturn(''); |
|
77
|
|
|
|
|
78
|
|
|
$this->shopHelper = $this->getMockBuilder(Shop::class)->disableOriginalConstructor()->getMock(); |
|
79
|
|
|
|
|
80
|
|
|
$this->connection = $this->getMockBuilder(AdapterInterface::class)->disableOriginalConstructor()->getMock(); |
|
81
|
|
|
|
|
82
|
|
|
$resource = $this->getMockBuilder(ResourceConnection::class)->disableOriginalConstructor()->getMock(); |
|
83
|
|
|
$resource->method('getConnection')->willReturn($this->connection); |
|
84
|
|
|
|
|
85
|
|
|
$context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); |
|
86
|
|
|
$context->method('getResources')->willReturn($resource); |
|
87
|
|
|
|
|
88
|
|
|
$this->classToTest = $this->objectManager->getObject(ClassToTest::class, [ |
|
89
|
|
|
'context' => $context, |
|
90
|
|
|
'shopHelper' => $this->shopHelper |
|
91
|
|
|
]); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testAddCheckedAddress() |
|
95
|
|
|
{ |
|
96
|
|
|
$response = [ |
|
97
|
|
|
'firstname' => 'Paul', |
|
98
|
|
|
'lastname' => 'Payer', |
|
99
|
|
|
'company' => 'Testcompany Ltd.', |
|
100
|
|
|
'street' => 'Teststr. 12', |
|
101
|
|
|
'zip' => '12345', |
|
102
|
|
|
'city' => 'Berlin', |
|
103
|
|
|
'country' => 'DE', |
|
104
|
|
|
'state' => '', |
|
105
|
|
|
]; |
|
106
|
|
|
|
|
107
|
|
|
$result = $this->classToTest->addCheckedAddress($this->address, $response); |
|
108
|
|
|
$this->assertInstanceOf(ClassToTest::class, $result); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function testWasAddressCheckedBeforeNoLifetime() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->shopHelper->method('getConfigParam')->willReturn(null); |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
$result = $this->classToTest->wasAddressCheckedBefore($this->address, true); |
|
116
|
|
|
$this->assertFalse($result); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
View Code Duplication |
public function testWasAddressCheckedBeforeNoResult() |
|
|
|
|
|
|
120
|
|
|
{ |
|
121
|
|
|
$this->shopHelper->method('getConfigParam')->willReturn(5); |
|
|
|
|
|
|
122
|
|
|
$this->connection->method('fetchOne')->willReturn(false); |
|
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
$result = $this->classToTest->wasAddressCheckedBefore($this->address, true); |
|
125
|
|
|
$this->assertFalse($result); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
View Code Duplication |
public function testWasAddressCheckedBefore() |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
|
|
$this->shopHelper->method('getConfigParam')->willReturn(5); |
|
|
|
|
|
|
131
|
|
|
$this->connection->method('fetchOne')->willReturn('2017-01-01 01:01:01'); |
|
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
$result = $this->classToTest->wasAddressCheckedBefore($this->address, true); |
|
134
|
|
|
$this->assertTrue($result); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
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.