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\Controller\Onepage; |
28
|
|
|
|
29
|
|
|
use Magento\Quote\Model\Quote; |
30
|
|
|
use Payone\Core\Controller\Onepage\PlaceOrder as ClassToTest; |
31
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
32
|
|
|
use Magento\Checkout\Model\Session; |
33
|
|
|
use Magento\Framework\App\Action\Context; |
34
|
|
|
use Magento\Checkout\Api\AgreementsValidatorInterface; |
35
|
|
|
use Magento\Quote\Api\CartManagementInterface; |
36
|
|
|
use Magento\Framework\App\Console\Response; |
37
|
|
|
use Magento\Store\App\Response\Redirect as RedirectResponse; |
38
|
|
|
use Magento\Framework\UrlInterface; |
39
|
|
|
use Magento\Framework\App\Request\Http; |
40
|
|
|
use Magento\Framework\Message\ManagerInterface; |
41
|
|
|
use Magento\Quote\Model\Quote\Address; |
42
|
|
|
|
43
|
|
|
class PlaceOrderTest extends \PHPUnit_Framework_TestCase |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* @var ClassToTest |
47
|
|
|
*/ |
48
|
|
|
private $classToTest; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var ObjectManager |
52
|
|
|
*/ |
53
|
|
|
private $objectManager; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var Session|\PHPUnit_Framework_MockObject_MockObject |
57
|
|
|
*/ |
58
|
|
|
private $checkoutSession; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var AgreementsValidatorInterface|\PHPUnit_Framework_MockObject_MockObject |
62
|
|
|
*/ |
63
|
|
|
private $agreementValidator; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var CartManagementInterface|\PHPUnit_Framework_MockObject_MockObject |
67
|
|
|
*/ |
68
|
|
|
private $cartManagement; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject |
72
|
|
|
*/ |
73
|
|
|
private $request; |
74
|
|
|
|
75
|
|
|
protected function setUp() |
76
|
|
|
{ |
77
|
|
|
$this->objectManager = new ObjectManager($this); |
78
|
|
|
|
79
|
|
|
$redirectResponse = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock(); |
80
|
|
|
|
81
|
|
|
$redirect = $this->getMockBuilder(RedirectResponse::class)->disableOriginalConstructor()->getMock(); |
82
|
|
|
$redirect->method('redirect')->willReturn($redirectResponse); |
83
|
|
|
|
84
|
|
|
$response = $this->getMockBuilder(Response::class) |
85
|
|
|
->disableOriginalConstructor() |
86
|
|
|
->setMethods(['setRedirect']) |
87
|
|
|
->getMock(); |
88
|
|
|
|
89
|
|
|
$url = $this->getMockBuilder(UrlInterface::class)->disableOriginalConstructor()->getMock(); |
90
|
|
|
|
91
|
|
|
$this->request = $this->getMockBuilder(Http::class)->disableOriginalConstructor()->setMethods(['getBeforeForwardInfo'])->getMock(); |
92
|
|
|
|
93
|
|
|
$messageManager = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock(); |
94
|
|
|
|
95
|
|
|
$context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); |
96
|
|
|
$context->method('getRedirect')->willReturn($redirect); |
97
|
|
|
$context->method('getRequest')->willReturn($this->request); |
98
|
|
|
$context->method('getResponse')->willReturn($response); |
99
|
|
|
$context->method('getUrl')->willReturn($url); |
100
|
|
|
$context->method('getMessageManager')->willReturn($messageManager); |
101
|
|
|
|
102
|
|
|
$address = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock(); |
103
|
|
|
|
104
|
|
|
$quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock(); |
105
|
|
|
$quote->method('getBillingAddress')->willReturn($address); |
106
|
|
|
$quote->method('getShippingAddress')->willReturn($address); |
107
|
|
|
$quote->method('getIsVirtual')->willReturn(false); |
108
|
|
|
$quote->method('getId')->willReturn('12345'); |
109
|
|
|
$quote->method('setIsActive')->willReturn($quote); |
110
|
|
|
|
111
|
|
|
$this->checkoutSession = $this->getMockBuilder(Session::class) |
112
|
|
|
->disableOriginalConstructor() |
113
|
|
|
->setMethods(['getQuote', 'setLastQuoteId', 'setLastSuccessQuoteId', 'unsPayoneWorkorderId']) |
114
|
|
|
->getMock(); |
115
|
|
|
$this->checkoutSession->method('getQuote')->willReturn($quote); |
116
|
|
|
$this->checkoutSession->method('setLastQuoteId')->willReturn($this->checkoutSession); |
117
|
|
|
$this->checkoutSession->method('setLastSuccessQuoteId')->willReturn($this->checkoutSession); |
118
|
|
|
|
119
|
|
|
$this->agreementValidator = $this->getMockBuilder(AgreementsValidatorInterface::class)->disableOriginalConstructor()->getMock(); |
120
|
|
|
$this->agreementValidator->method('isValid')->willReturn(false); |
121
|
|
|
|
122
|
|
|
$this->cartManagement = $this->getMockBuilder(CartManagementInterface::class)->disableOriginalConstructor()->getMock(); |
123
|
|
|
|
124
|
|
|
$this->classToTest = $this->objectManager->getObject(ClassToTest::class, [ |
125
|
|
|
'context' => $context, |
126
|
|
|
'checkoutSession' => $this->checkoutSession, |
127
|
|
|
'agreementValidator' => $this->agreementValidator, |
128
|
|
|
'cartManagement' => $this->cartManagement |
129
|
|
|
]); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testExecute() |
133
|
|
|
{ |
134
|
|
|
$this->request->method('getBeforeForwardInfo')->willReturn(false); |
135
|
|
|
$result = $this->classToTest->execute(); |
|
|
|
|
136
|
|
|
$this->assertNull($result); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function testExecuteValidation() |
140
|
|
|
{ |
141
|
|
|
$this->request->method('getBeforeForwardInfo')->willReturn([]); |
142
|
|
|
$result = $this->classToTest->execute(); |
|
|
|
|
143
|
|
|
$this->assertNull($result); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function testExecuteException() |
147
|
|
|
{ |
148
|
|
|
$exception = new \Exception(); |
149
|
|
|
$this->cartManagement->method('placeOrder')->willThrowException($exception); |
150
|
|
|
|
151
|
|
|
$this->request->method('getBeforeForwardInfo')->willReturn(false); |
152
|
|
|
$result = $this->classToTest->execute(); |
|
|
|
|
153
|
|
|
$this->assertNull($result); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.