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\Service\V1\Data; |
28
|
|
|
|
29
|
|
|
use Payone\Core\Service\V1\InstallmentPlan as ClassToTest; |
30
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
31
|
|
|
use Payone\Core\Service\V1\Data\InstallmentPlanResponse; |
32
|
|
|
use Payone\Core\Api\Data\InstallmentPlanResponseInterfaceFactory; |
33
|
|
|
use Magento\Checkout\Model\Session; |
34
|
|
|
use Magento\Quote\Model\Quote; |
35
|
|
|
use Payone\Core\Model\Api\Request\Genericpayment\PreCheck; |
36
|
|
|
use Payone\Core\Model\Api\Request\Genericpayment\Calculation; |
37
|
|
|
use Payone\Core\Block\Payolution\InstallmentPlan; |
38
|
|
|
use Payone\Core\Test\Unit\BaseTestCase; |
39
|
|
|
use Payone\Core\Model\Test\PayoneObjectManager; |
40
|
|
|
|
41
|
|
|
class InstallmentPlanTest extends BaseTestCase |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* @var ClassToTest |
45
|
|
|
*/ |
46
|
|
|
private $classToTest; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var InstallmentPlanResponse|\PHPUnit_Framework_MockObject_MockObject |
50
|
|
|
*/ |
51
|
|
|
private $response; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var PreCheck|\PHPUnit_Framework_MockObject_MockObject |
55
|
|
|
*/ |
56
|
|
|
private $precheck; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var Calculation|\PHPUnit_Framework_MockObject_MockObject |
60
|
|
|
*/ |
61
|
|
|
private $calculation; |
62
|
|
|
|
63
|
|
|
protected function setUp() |
64
|
|
|
{ |
65
|
|
|
$objectManager = $this->getObjectManager(); |
66
|
|
|
|
67
|
|
|
$this->response = $objectManager->getObject(InstallmentPlanResponse::class); |
68
|
|
|
#$responseFactory = $objectManager->getObject(InstallmentPlanResponseFactory::class); |
|
|
|
|
69
|
|
|
$responseFactory = $this->getMockBuilder(InstallmentPlanResponseInterfaceFactory::class) |
70
|
|
|
->disableOriginalConstructor() |
71
|
|
|
->setMethods(['create']) |
72
|
|
|
->getMock(); |
73
|
|
|
$responseFactory->method('create')->willReturn($this->response); |
74
|
|
|
|
75
|
|
|
$quote = $this->getMockBuilder(Quote::class) |
76
|
|
|
->disableOriginalConstructor() |
77
|
|
|
->setMethods(['getBaseGrandTotal']) |
78
|
|
|
->getMock(); |
79
|
|
|
$quote->method('getBaseGrandTotal')->willReturn(100); |
80
|
|
|
|
81
|
|
|
$checkoutSession = $this->getMockBuilder(Session::class) |
82
|
|
|
->disableOriginalConstructor() |
83
|
|
|
->setMethods(['setInstallmentDraftLinks', 'setInstallmentWorkorderId', 'getQuote']) |
84
|
|
|
->getMock(); |
85
|
|
|
$checkoutSession->method('getQuote')->willReturn($quote); |
86
|
|
|
|
87
|
|
|
$this->precheck = $this->getMockBuilder(PreCheck::class)->disableOriginalConstructor()->getMock(); |
88
|
|
|
$this->calculation = $this->getMockBuilder(Calculation::class)->disableOriginalConstructor()->getMock(); |
89
|
|
|
|
90
|
|
|
$block = $this->getMockBuilder(InstallmentPlan::class) |
91
|
|
|
->disableOriginalConstructor() |
92
|
|
|
->setMethods(['setInstallmentData', 'setCode', 'toHtml']) |
93
|
|
|
->getMock(); |
94
|
|
|
$block->method('toHtml')->willReturn('InstallmentPlanHtml'); |
95
|
|
|
|
96
|
|
|
$this->classToTest = $objectManager->getObject(ClassToTest::class, [ |
97
|
|
|
'responseFactory' => $responseFactory, |
98
|
|
|
'checkoutSession' => $checkoutSession, |
99
|
|
|
'precheck' => $this->precheck, |
100
|
|
|
'calculation' => $this->calculation, |
101
|
|
|
'block' => $block |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testGetInstallmentPlan() |
106
|
|
|
{ |
107
|
|
|
$precheck = ['status' => 'OK']; |
108
|
|
|
$this->precheck->method('sendRequest')->willReturn($precheck); |
109
|
|
|
|
110
|
|
|
$calculation = [ |
111
|
|
|
'status' => 'OK', |
112
|
|
|
'workorderid' => 'WORKORDERID', |
113
|
|
|
'add_paydata[PaymentDetails_1_Duration]' => '3', |
114
|
|
|
'add_paydata[PaymentDetails_1_MinimumInstallmentFee]' => '0', |
115
|
|
|
'add_paydata[PaymentDetails_1_InterestRate]' => '14.95', |
116
|
|
|
'add_paydata[PaymentDetails_1_Usage]' => 'Calculated by calculation service', |
117
|
|
|
'add_paydata[PaymentDetails_1_EffectiveInterestRate]' => '16.03', |
118
|
|
|
'add_paydata[PaymentDetails_1_TotalAmount]' => '1278.09', |
119
|
|
|
'add_paydata[PaymentDetails_1_OriginalAmount]' => '1249.50', |
120
|
|
|
'add_paydata[PaymentDetails_1_Currency]' => 'EUR', |
121
|
|
|
'add_paydata[PaymentDetails_1_StandardCreditInformationUrl]' => 'http://installmentdraft.test', |
122
|
|
|
'add_paydata[PaymentDetails_1_Installment_1_Amount]' => '426.03', |
123
|
|
|
'add_paydata[PaymentDetails_1_Installment_1_Due]' => '2017-08-20', |
124
|
|
|
'add_paydata[PaymentDetails_1_Installment_2_Amount]' => '426.03', |
125
|
|
|
'add_paydata[PaymentDetails_1_Installment_2_Due]' => '2017-09-20', |
126
|
|
|
'add_paydata[PaymentDetails_1_Installment_3_Amount]' => '426.03', |
127
|
|
|
'add_paydata[PaymentDetails_1_Installment_3_Due]' => '2017-10-20', |
128
|
|
|
]; |
129
|
|
|
$this->calculation->method('sendRequest')->willReturn($calculation); |
130
|
|
|
|
131
|
|
|
$result = $this->classToTest->getInstallmentPlan('19900909'); |
132
|
|
|
$this->assertTrue($result->getSuccess()); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testGetInstallmentPlanErrorPre() |
136
|
|
|
{ |
137
|
|
|
$precheck = ['status' => 'ERROR', 'errorcode' => '123', 'customermessage' => 'error']; |
138
|
|
|
$this->precheck->method('sendRequest')->willReturn($precheck); |
139
|
|
|
|
140
|
|
|
$result = $this->classToTest->getInstallmentPlan('19900909'); |
141
|
|
|
$this->assertFalse($result->getSuccess()); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testGetInstallmentPlanErrorCalc() |
145
|
|
|
{ |
146
|
|
|
$precheck = ['status' => 'OK']; |
147
|
|
|
$this->precheck->method('sendRequest')->willReturn($precheck); |
148
|
|
|
|
149
|
|
|
$calculation = ['status' => 'ERROR', 'errorcode' => '123', 'customermessage' => 'error']; |
150
|
|
|
$this->calculation->method('sendRequest')->willReturn($calculation); |
151
|
|
|
|
152
|
|
|
$result = $this->classToTest->getInstallmentPlan('19900909'); |
153
|
|
|
$this->assertFalse($result->getSuccess()); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function testGetInstallmentPlanErrorUnknown() |
157
|
|
|
{ |
158
|
|
|
$this->precheck->method('sendRequest')->willReturn(false); |
159
|
|
|
|
160
|
|
|
$result = $this->classToTest->getInstallmentPlan('19900909'); |
161
|
|
|
$this->assertFalse($result->getSuccess()); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.