3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Paypal \Test \Unit \Controller \Transparent ;
7
9
8
10
use Magento \Framework \App \Action \Context ;
9
11
use Magento \Framework \Controller \Result \JsonFactory ;
10
12
use Magento \Framework \Session \Generic ;
11
13
use Magento \Framework \Session \SessionManager ;
12
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13
14
use Magento \Paypal \Controller \Transparent \RequestSecureToken ;
14
15
use Magento \Paypal \Model \Payflow \Service \Request \SecureToken ;
15
16
use Magento \Paypal \Model \Payflow \Transparent ;
17
+ use PHPUnit \Framework \MockObject \MockObject ;
16
18
17
19
/**
18
20
* Class RequestSecureTokenTest
22
24
class RequestSecureTokenTest extends \PHPUnit \Framework \TestCase
23
25
{
24
26
/**
25
- * @var Transparent|\PHPUnit_Framework_MockObject_MockObject
27
+ * @var Transparent|MockObject
26
28
*/
27
- protected $ transparentMock ;
29
+ private $ transparent ;
28
30
29
31
/**
30
- * @var RequestSecureToken|\PHPUnit_Framework_MockObject_MockObject
32
+ * @var RequestSecureToken|MockObject
31
33
*/
32
- protected $ controller ;
34
+ private $ controller ;
33
35
34
36
/**
35
- * @var Context|\PHPUnit_Framework_MockObject_MockObject
37
+ * @var Context|MockObject
36
38
*/
37
- protected $ contextMock ;
39
+ private $ context ;
38
40
39
41
/**
40
- * @var JsonFactory|\PHPUnit_Framework_MockObject_MockObject
42
+ * @var JsonFactory|MockObject
41
43
*/
42
- protected $ resultJsonFactoryMock ;
44
+ private $ resultJsonFactory ;
43
45
44
46
/**
45
- * @var Generic|\PHPUnit_Framework_MockObject_MockObject
47
+ * @var Generic|MockObject
46
48
*/
47
- protected $ sessionTransparentMock ;
49
+ private $ sessionTransparent ;
48
50
49
51
/**
50
- * @var SecureToken|\PHPUnit_Framework_MockObject_MockObject
52
+ * @var SecureToken|MockObject
51
53
*/
52
- protected $ secureTokenServiceMock ;
54
+ private $ secureTokenService ;
53
55
54
56
/**
55
- * @var SessionManager|\PHPUnit_Framework_MockObject_MockObject
57
+ * @var SessionManager|MockObject
56
58
*/
57
- protected $ sessionManagerMock ;
59
+ private $ sessionManager ;
58
60
59
61
/**
60
62
* Set up
@@ -64,45 +66,46 @@ class RequestSecureTokenTest extends \PHPUnit\Framework\TestCase
64
66
protected function setUp ()
65
67
{
66
68
67
- $ this ->contextMock = $ this ->getMockBuilder (\Magento \Framework \App \Action \Context::class)
69
+ $ this ->context = $ this ->getMockBuilder (\Magento \Framework \App \Action \Context::class)
68
70
->disableOriginalConstructor ()
69
71
->getMock ();
70
- $ this ->resultJsonFactoryMock = $ this ->getMockBuilder (\Magento \Framework \Controller \Result \JsonFactory::class)
72
+ $ this ->resultJsonFactory = $ this ->getMockBuilder (\Magento \Framework \Controller \Result \JsonFactory::class)
71
73
->setMethods (['create ' ])
72
74
->disableOriginalConstructor ()
73
75
->getMock ();
74
- $ this ->sessionTransparentMock = $ this ->getMockBuilder (\Magento \Framework \Session \Generic::class)
76
+ $ this ->sessionTransparent = $ this ->getMockBuilder (\Magento \Framework \Session \Generic::class)
75
77
->setMethods (['setQuoteId ' ])
76
78
->disableOriginalConstructor ()
77
79
->getMock ();
78
- $ this ->secureTokenServiceMock = $ this ->getMockBuilder (
80
+ $ this ->secureTokenService = $ this ->getMockBuilder (
79
81
\Magento \Paypal \Model \Payflow \Service \Request \SecureToken::class
80
82
)
81
83
->setMethods (['requestToken ' ])
82
84
->disableOriginalConstructor ()
83
85
->getMock ();
84
- $ this ->sessionManagerMock = $ this ->getMockBuilder (\Magento \Framework \Session \SessionManager::class)
86
+ $ this ->sessionManager = $ this ->getMockBuilder (\Magento \Framework \Session \SessionManager::class)
85
87
->setMethods (['getQuote ' ])
86
88
->disableOriginalConstructor ()
87
89
->getMock ();
88
- $ this ->transparentMock = $ this ->getMockBuilder (\Magento \Paypal \Model \Payflow \Transparent::class)
89
- ->setMethods (['getCode ' ])
90
+ $ this ->transparent = $ this ->getMockBuilder (\Magento \Paypal \Model \Payflow \Transparent::class)
91
+ ->setMethods (['getCode ' , ' isActive ' ])
90
92
->disableOriginalConstructor ()
91
93
->getMock ();
92
94
93
95
$ this ->controller = new \Magento \Paypal \Controller \Transparent \RequestSecureToken (
94
- $ this ->contextMock ,
95
- $ this ->resultJsonFactoryMock ,
96
- $ this ->sessionTransparentMock ,
97
- $ this ->secureTokenServiceMock ,
98
- $ this ->sessionManagerMock ,
99
- $ this ->transparentMock
96
+ $ this ->context ,
97
+ $ this ->resultJsonFactory ,
98
+ $ this ->sessionTransparent ,
99
+ $ this ->secureTokenService ,
100
+ $ this ->sessionManager ,
101
+ $ this ->transparent
100
102
);
101
103
}
102
104
103
105
public function testExecuteSuccess ()
104
106
{
105
107
$ quoteId = 99 ;
108
+ $ storeId = 2 ;
106
109
$ tokenFields = ['fields-1 ' , 'fields-2 ' , 'fields-3 ' ];
107
110
$ secureToken = 'token_hash ' ;
108
111
$ resultExpectation = [
@@ -116,28 +119,32 @@ public function testExecuteSuccess()
116
119
$ quoteMock = $ this ->getMockBuilder (\Magento \Quote \Model \Quote::class)
117
120
->disableOriginalConstructor ()
118
121
->getMock ();
122
+ $ quoteMock ->method ('getStoreId ' )
123
+ ->willReturn ($ storeId );
119
124
$ tokenMock = $ this ->getMockBuilder (\Magento \Framework \DataObject::class)
120
125
->disableOriginalConstructor ()
121
126
->getMock ();
122
127
$ jsonMock = $ this ->getMockBuilder (\Magento \Framework \Controller \Result \Json::class)
123
128
->disableOriginalConstructor ()
124
129
->getMock ();
125
130
126
- $ this ->sessionManagerMock ->expects ($ this ->atLeastOnce ())
131
+ $ this ->sessionManager ->expects ($ this ->atLeastOnce ())
127
132
->method ('getQuote ' )
128
133
->willReturn ($ quoteMock );
134
+ $ this ->transparent ->method ('isActive ' )
135
+ ->with ($ storeId )
136
+ ->willReturn (true );
129
137
$ quoteMock ->expects ($ this ->once ())
130
138
->method ('getId ' )
131
139
->willReturn ($ quoteId );
132
- $ this ->sessionTransparentMock ->expects ($ this ->once ())
140
+ $ this ->sessionTransparent ->expects ($ this ->once ())
133
141
->method ('setQuoteId ' )
134
142
->with ($ quoteId );
135
- $ this ->secureTokenServiceMock ->expects ($ this ->once ())
143
+ $ this ->secureTokenService ->expects ($ this ->once ())
136
144
->method ('requestToken ' )
137
145
->with ($ quoteMock )
138
146
->willReturn ($ tokenMock );
139
- $ this ->transparentMock ->expects ($ this ->once ())
140
- ->method ('getCode ' )
147
+ $ this ->transparent ->method ('getCode ' )
141
148
->willReturn ('transparent ' );
142
149
$ tokenMock ->expects ($ this ->atLeastOnce ())
143
150
->method ('getData ' )
@@ -147,7 +154,7 @@ public function testExecuteSuccess()
147
154
['securetoken ' , null , $ secureToken ]
148
155
]
149
156
);
150
- $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
157
+ $ this ->resultJsonFactory ->expects ($ this ->once ())
151
158
->method ('create ' )
152
159
->willReturn ($ jsonMock );
153
160
$ jsonMock ->expects ($ this ->once ())
@@ -161,6 +168,7 @@ public function testExecuteSuccess()
161
168
public function testExecuteTokenRequestException ()
162
169
{
163
170
$ quoteId = 99 ;
171
+ $ storeId = 2 ;
164
172
$ resultExpectation = [
165
173
'success ' => false ,
166
174
'error ' => true ,
@@ -170,24 +178,29 @@ public function testExecuteTokenRequestException()
170
178
$ quoteMock = $ this ->getMockBuilder (\Magento \Quote \Model \Quote::class)
171
179
->disableOriginalConstructor ()
172
180
->getMock ();
181
+ $ quoteMock ->method ('getStoreId ' )
182
+ ->willReturn ($ storeId );
173
183
$ jsonMock = $ this ->getMockBuilder (\Magento \Framework \Controller \Result \Json::class)
174
184
->disableOriginalConstructor ()
175
185
->getMock ();
176
186
177
- $ this ->sessionManagerMock ->expects ($ this ->atLeastOnce ())
187
+ $ this ->sessionManager ->expects ($ this ->atLeastOnce ())
178
188
->method ('getQuote ' )
179
189
->willReturn ($ quoteMock );
180
190
$ quoteMock ->expects ($ this ->once ())
181
191
->method ('getId ' )
182
192
->willReturn ($ quoteId );
183
- $ this ->sessionTransparentMock ->expects ($ this ->once ())
193
+ $ this ->transparent ->method ('isActive ' )
194
+ ->with ($ storeId )
195
+ ->willReturn (true );
196
+ $ this ->sessionTransparent ->expects ($ this ->once ())
184
197
->method ('setQuoteId ' )
185
198
->with ($ quoteId );
186
- $ this ->secureTokenServiceMock ->expects ($ this ->once ())
199
+ $ this ->secureTokenService ->expects ($ this ->once ())
187
200
->method ('requestToken ' )
188
201
->with ($ quoteMock )
189
202
->willThrowException (new \Exception ());
190
- $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
203
+ $ this ->resultJsonFactory ->expects ($ this ->once ())
191
204
->method ('create ' )
192
205
->willReturn ($ jsonMock );
193
206
$ jsonMock ->expects ($ this ->once ())
@@ -211,10 +224,10 @@ public function testExecuteEmptyQuoteError()
211
224
->disableOriginalConstructor ()
212
225
->getMock ();
213
226
214
- $ this ->sessionManagerMock ->expects ($ this ->atLeastOnce ())
227
+ $ this ->sessionManager ->expects ($ this ->atLeastOnce ())
215
228
->method ('getQuote ' )
216
229
->willReturn ($ quoteMock );
217
- $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
230
+ $ this ->resultJsonFactory ->expects ($ this ->once ())
218
231
->method ('create ' )
219
232
->willReturn ($ jsonMock );
220
233
$ jsonMock ->expects ($ this ->once ())
0 commit comments