|
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\Order; |
|
30
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
|
31
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface; |
|
32
|
|
|
use Payone\Core\Helper\Database; |
|
33
|
|
|
use Payone\Core\Helper\Customer; |
|
34
|
|
|
use Magento\Sales\Model\Order as OrderCore; |
|
35
|
|
|
use Magento\Sales\Model\OrderFactory; |
|
36
|
|
|
use Magento\Quote\Model\Quote\Address; |
|
37
|
|
|
use Magento\Framework\Exception\LocalizedException; |
|
38
|
|
|
use Magento\Quote\Model\Quote; |
|
39
|
|
|
use Magento\Quote\Model\ResourceModel\Quote\Address\Rate; |
|
40
|
|
|
use Magento\Directory\Model\Region; |
|
41
|
|
|
|
|
42
|
|
|
class OrderTestTest extends \PHPUnit_Framework_TestCase |
|
43
|
|
|
{ |
|
44
|
|
|
/** |
|
45
|
|
|
* @var ObjectManager |
|
46
|
|
|
*/ |
|
47
|
|
|
private $objectManager; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var Order |
|
51
|
|
|
*/ |
|
52
|
|
|
private $order; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
|
56
|
|
|
*/ |
|
57
|
|
|
private $scopeConfig; |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var OrderCore|\PHPUnit_Framework_MockObject_MockObject |
|
61
|
|
|
*/ |
|
62
|
|
|
private $orderCore; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var Customer|\PHPUnit_Framework_MockObject_MockObject |
|
66
|
|
|
*/ |
|
67
|
|
|
private $customerHelper; |
|
68
|
|
|
|
|
69
|
|
|
protected function setUp() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->objectManager = new ObjectManager($this); |
|
72
|
|
|
|
|
73
|
|
|
$databaseHelper = $this->getMockBuilder(Database::class)->disableOriginalConstructor()->getMock(); |
|
74
|
|
|
$databaseHelper->method('getOrderIncrementIdByTxid')->willReturn('000000001'); |
|
75
|
|
|
|
|
76
|
|
|
$this->customerHelper = $this->getMockBuilder(Customer::class)->disableOriginalConstructor()->getMock(); |
|
77
|
|
|
|
|
78
|
|
|
$this->orderCore = $this->getMockBuilder(OrderCore::class)->disableOriginalConstructor()->getMock(); |
|
79
|
|
|
$this->orderCore->method('loadByIncrementId')->willReturn($this->orderCore); |
|
80
|
|
|
$orderFactory = $this->getMockBuilder(OrderFactory::class)->disableOriginalConstructor()->getMock(); |
|
81
|
|
|
$orderFactory->method('create')->willReturn($this->orderCore); |
|
82
|
|
|
|
|
83
|
|
|
$this->order = $this->objectManager->getObject(Order::class, [ |
|
84
|
|
|
'databaseHelper' => $databaseHelper, |
|
85
|
|
|
'customerHelper' => $this->customerHelper, |
|
86
|
|
|
'orderFactory' => $orderFactory |
|
87
|
|
|
]); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function testGetOrderByTxid() |
|
91
|
|
|
{ |
|
92
|
|
|
$this->orderCore->method('getId')->willReturn('1'); |
|
93
|
|
|
|
|
94
|
|
|
$result = $this->order->getOrderByTxid('238'); |
|
95
|
|
|
$this->assertInstanceOf(OrderCore::class, $result); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function testGetOrderByTxidNull() |
|
99
|
|
|
{ |
|
100
|
|
|
$this->orderCore->method('getId')->willReturn(false); |
|
101
|
|
|
|
|
102
|
|
|
$result = $this->order->getOrderByTxid('238'); |
|
103
|
|
|
$this->assertNull($result); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testGetShippingMethod() |
|
107
|
|
|
{ |
|
108
|
|
|
$expected = 'free_free'; |
|
109
|
|
|
|
|
110
|
|
|
$rate1 = $this->getMockBuilder(Rate::class) |
|
111
|
|
|
->disableOriginalConstructor() |
|
112
|
|
|
->setMethods(['getPrice', 'getCode']) |
|
113
|
|
|
->getMock(); |
|
114
|
|
|
$rate2 = clone $rate1; |
|
115
|
|
|
$rate1->method('getPrice')->willReturn('5.00'); |
|
116
|
|
|
$rate1->method('getCode')->willReturn('not_free'); |
|
117
|
|
|
$rate2->method('getPrice')->willReturn('0.00'); |
|
118
|
|
|
$rate2->method('getCode')->willReturn($expected); |
|
119
|
|
|
$rates = [ |
|
120
|
|
|
'key' => [ |
|
121
|
|
|
$rate1, |
|
122
|
|
|
$rate2 |
|
123
|
|
|
] |
|
124
|
|
|
]; |
|
125
|
|
|
|
|
126
|
|
|
$quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock(); |
|
127
|
|
|
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); |
|
128
|
|
|
$address->method('getGroupedAllShippingRates')->willReturn($rates); |
|
129
|
|
|
|
|
130
|
|
|
$result = $this->order->getShippingMethod($quote, $address); |
|
131
|
|
|
$this->assertEquals($expected, $result); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
View Code Duplication |
public function testGetShippingMethodFalse() |
|
|
|
|
|
|
135
|
|
|
{ |
|
136
|
|
|
$quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock(); |
|
137
|
|
|
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); |
|
138
|
|
|
$address->method('getGroupedAllShippingRates')->willReturn([]); |
|
139
|
|
|
|
|
140
|
|
|
$result = $this->order->getShippingMethod($quote, $address); |
|
141
|
|
|
$this->assertFalse($result); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function testSetShippingMethod() |
|
145
|
|
|
{ |
|
146
|
|
|
$rate = $this->getMockBuilder(Rate::class) |
|
147
|
|
|
->disableOriginalConstructor() |
|
148
|
|
|
->setMethods(['getPrice', 'getCode']) |
|
149
|
|
|
->getMock(); |
|
150
|
|
|
$rate->method('getPrice')->willReturn('0.00'); |
|
151
|
|
|
$rate->method('getCode')->willReturn('free_free'); |
|
152
|
|
|
$rates = ['key' => [$rate]]; |
|
153
|
|
|
|
|
154
|
|
|
$expected = 'free_free'; |
|
155
|
|
|
|
|
156
|
|
|
$quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock(); |
|
157
|
|
|
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); |
|
158
|
|
|
$address->method('getGroupedAllShippingRates')->willReturn($rates); |
|
159
|
|
|
$address->method('getShippingMethod')->willReturn($expected); |
|
160
|
|
|
|
|
161
|
|
|
$result = $this->order->setShippingMethod($address, $quote); |
|
162
|
|
|
$this->assertEquals($expected, $result->getShippingMethod()); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
View Code Duplication |
public function testSetShippingMethodException() |
|
|
|
|
|
|
166
|
|
|
{ |
|
167
|
|
|
$quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock(); |
|
168
|
|
|
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); |
|
169
|
|
|
$address->method('getGroupedAllShippingRates')->willReturn([]); |
|
170
|
|
|
|
|
171
|
|
|
$this->setExpectedException(LocalizedException::class); |
|
172
|
|
|
$this->order->setShippingMethod($address, $quote); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function testFillSingleAddress() |
|
176
|
|
|
{ |
|
177
|
|
|
$address = $this->objectManager->getObject(Address::class); |
|
178
|
|
|
$firstname = 'Paul'; |
|
179
|
|
|
$lastname = 'Tester'; |
|
180
|
|
|
$street = 'Washington Blvd 13'; |
|
181
|
|
|
$city = 'San Diego'; |
|
182
|
|
|
$zip = '12345'; |
|
183
|
|
|
$country = 'US'; |
|
184
|
|
|
$state = 'CA'; |
|
185
|
|
|
$regionId = '5'; |
|
186
|
|
|
|
|
187
|
|
|
$region = $this->getMockBuilder(Region::class)->disableOriginalConstructor()->getMock(); |
|
188
|
|
|
$region->method('getId')->willReturn($regionId); |
|
189
|
|
|
$this->customerHelper->method('getRegion')->willReturn($region); |
|
|
|
|
|
|
190
|
|
|
|
|
191
|
|
|
$result = $this->order->fillSingleAddress($address, $firstname, $lastname, $street, $city, $zip, $country, $state); |
|
192
|
|
|
$this->assertEquals($firstname, $result->getFirstname()); |
|
193
|
|
|
$this->assertEquals($lastname, $result->getLastname()); |
|
194
|
|
|
$this->assertEquals($street, $result->getStreet()[0]); |
|
195
|
|
|
$this->assertEquals($city, $result->getCity()); |
|
196
|
|
|
$this->assertEquals($zip, $result->getPostcode()); |
|
197
|
|
|
$this->assertEquals($country, $result->getCountryId()); |
|
198
|
|
|
$this->assertEquals($regionId, $result->getRegionId()); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.