6
6
7
7
namespace Magento \Paypal \Test \Unit \Model \Api ;
8
8
9
+ use Magento \Framework \Exception \LocalizedException ;
9
10
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
10
11
use Magento \Paypal \Model \Info ;
11
12
@@ -35,7 +36,7 @@ class NvpTest extends \PHPUnit\Framework\TestCase
35
36
/** @var \Magento\Paypal\Model\Api\ProcessableException|\PHPUnit_Framework_MockObject_MockObject */
36
37
protected $ processableException ;
37
38
38
- /** @var \Magento\Framework\Exception\ LocalizedException|\PHPUnit_Framework_MockObject_MockObject */
39
+ /** @var LocalizedException|\PHPUnit_Framework_MockObject_MockObject */
39
40
protected $ exception ;
40
41
41
42
/** @var \Magento\Framework\HTTP\Adapter\Curl|\PHPUnit_Framework_MockObject_MockObject */
@@ -47,6 +48,9 @@ class NvpTest extends \PHPUnit\Framework\TestCase
47
48
/** @var \Magento\Payment\Model\Method\Logger|\PHPUnit_Framework_MockObject_MockObject */
48
49
protected $ customLoggerMock ;
49
50
51
+ /**
52
+ * {@inheritDoc}
53
+ */
50
54
protected function setUp ()
51
55
{
52
56
$ this ->customerAddressHelper = $ this ->createMock (\Magento \Customer \Helper \Address::class);
@@ -64,26 +68,32 @@ protected function setUp()
64
68
);
65
69
$ processableExceptionFactory ->expects ($ this ->any ())
66
70
->method ('create ' )
67
- ->will ($ this ->returnCallback (function ($ arguments ) {
68
- $ this ->processableException = $ this ->getMockBuilder (
69
- \Magento \Paypal \Model \Api \ProcessableException::class
71
+ ->will (
72
+ $ this ->returnCallback (
73
+ function ($ arguments ) {
74
+ $ this ->processableException = $ this ->getMockBuilder (
75
+ \Magento \Paypal \Model \Api \ProcessableException::class
76
+ )->setConstructorArgs ([$ arguments ['phrase ' ], null , $ arguments ['code ' ]])->getMock ();
77
+ return $ this ->processableException ;
78
+ }
70
79
)
71
- ->setConstructorArgs ([$ arguments ['phrase ' ], null , $ arguments ['code ' ]])
72
- ->getMock ();
73
- return $ this ->processableException ;
74
- }));
80
+ );
75
81
$ exceptionFactory = $ this ->createPartialMock (
76
82
\Magento \Framework \Exception \LocalizedExceptionFactory::class,
77
83
['create ' ]
78
84
);
79
85
$ exceptionFactory ->expects ($ this ->any ())
80
86
->method ('create ' )
81
- ->will ($ this ->returnCallback (function ($ arguments ) {
82
- $ this ->exception = $ this ->getMockBuilder (\Magento \Framework \Exception \LocalizedException::class)
83
- ->setConstructorArgs ([$ arguments ['phrase ' ]])
84
- ->getMock ();
85
- return $ this ->exception ;
86
- }));
87
+ ->will (
88
+ $ this ->returnCallback (
89
+ function ($ arguments ) {
90
+ $ this ->exception = $ this ->getMockBuilder (LocalizedException::class)
91
+ ->setConstructorArgs ([$ arguments ['phrase ' ]])
92
+ ->getMock ();
93
+ return $ this ->exception ;
94
+ }
95
+ )
96
+ );
87
97
$ this ->curl = $ this ->createMock (\Magento \Framework \HTTP \Adapter \Curl::class);
88
98
$ curlFactory = $ this ->createPartialMock (\Magento \Framework \HTTP \Adapter \CurlFactory::class, ['create ' ]);
89
99
$ curlFactory ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ this ->curl ));
@@ -155,7 +165,7 @@ public function callDataProvider()
155
165
[
156
166
"\r\n" . 'ACK=Failure&L_ERRORCODE0=10417&L_SHORTMESSAGE0=Message.&L_LONGMESSAGE0=Long%20Message. ' ,
157
167
[],
158
- \ Magento \ Framework \ Exception \ LocalizedException::class,
168
+ LocalizedException::class,
159
169
'PayPal gateway has rejected request. Long Message (#10417: Message). ' ,
160
170
0
161
171
],
@@ -184,27 +194,56 @@ public function callDataProvider()
184
194
];
185
195
}
186
196
187
- public function testCallGetExpressCheckoutDetails ()
197
+ /**
198
+ * Test getting of the ExpressCheckout details
199
+ *
200
+ * @param $input
201
+ * @param $expected
202
+ * @dataProvider callGetExpressCheckoutDetailsDataProvider
203
+ */
204
+ public function testCallGetExpressCheckoutDetails ($ input , $ expected )
188
205
{
189
206
$ this ->curl ->expects ($ this ->once ())
190
207
->method ('read ' )
191
- ->will ($ this ->returnValue (
192
- "\r\n" . 'ACK=Success&SHIPTONAME=Ship%20To%20Name '
208
+ ->will ($ this ->returnValue ($ input ));
209
+ $ this ->model ->callGetExpressCheckoutDetails ();
210
+ $ address = $ this ->model ->getExportedShippingAddress ();
211
+ $ this ->assertEquals ($ expected ['firstName ' ], $ address ->getData ('firstname ' ));
212
+ $ this ->assertEquals ($ expected ['lastName ' ], $ address ->getData ('lastname ' ));
213
+ $ this ->assertEquals ($ expected ['street ' ], $ address ->getStreet ());
214
+ $ this ->assertEquals ($ expected ['company ' ], $ address ->getCompany ());
215
+ $ this ->assertEquals ($ expected ['city ' ], $ address ->getCity ());
216
+ $ this ->assertEquals ($ expected ['telephone ' ], $ address ->getTelephone ());
217
+ $ this ->assertEquals ($ expected ['region ' ], $ address ->getRegion ());
218
+ }
219
+
220
+ /**
221
+ * Data Provider
222
+ *
223
+ * @return array
224
+ */
225
+ public function callGetExpressCheckoutDetailsDataProvider ()
226
+ {
227
+ return [
228
+ [
229
+ "\r\n" . 'ACK=Success&SHIPTONAME=Jane%20Doe '
193
230
. '&SHIPTOSTREET=testStreet '
194
231
. '&SHIPTOSTREET2=testApartment '
195
232
. '&BUSINESS=testCompany '
196
233
. '&SHIPTOCITY=testCity '
197
234
. '&PHONENUM=223322 '
198
- . '&STATE=testSTATE '
199
- ));
200
- $ this ->model ->callGetExpressCheckoutDetails ();
201
- $ address = $ this ->model ->getExportedShippingAddress ();
202
- $ this ->assertEquals ('Ship To Name ' , $ address ->getData ('firstname ' ));
203
- $ this ->assertEquals (implode ("\n" , ['testStreet ' ,'testApartment ' ]), $ address ->getStreet ());
204
- $ this ->assertEquals ('testCompany ' , $ address ->getCompany ());
205
- $ this ->assertEquals ('testCity ' , $ address ->getCity ());
206
- $ this ->assertEquals ('223322 ' , $ address ->getTelephone ());
207
- $ this ->assertEquals ('testSTATE ' , $ address ->getRegion ());
235
+ . '&STATE=testSTATE ' ,
236
+ [
237
+ 'firstName ' => 'Jane ' ,
238
+ 'lastName ' => 'Doe ' ,
239
+ 'street ' => 'testStreet ' . "\n" . 'testApartment ' ,
240
+ 'company ' => 'testCompany ' ,
241
+ 'city ' => 'testCity ' ,
242
+ 'telephone ' => '223322 ' ,
243
+ 'region ' => 'testSTATE ' ,
244
+ ]
245
+ ]
246
+ ];
208
247
}
209
248
210
249
/**
@@ -243,6 +282,9 @@ public function testCallDoReauthorization()
243
282
$ this ->assertEquals ($ expectedImportedData , $ this ->model ->getData ());
244
283
}
245
284
285
+ /**
286
+ * Test replace keys for debug data
287
+ */
246
288
public function testGetDebugReplacePrivateDataKeys ()
247
289
{
248
290
$ debugReplacePrivateDataKeys = $ this ->_invokeNvpProperty ($ this ->model , '_debugReplacePrivateDataKeys ' );
0 commit comments