66
77namespace Magento \Paypal \Test \Unit \Model \Api ;
88
9+ use Magento \Framework \Exception \LocalizedException ;
910use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
1011use Magento \Paypal \Model \Info ;
1112
@@ -35,7 +36,7 @@ class NvpTest extends \PHPUnit\Framework\TestCase
3536 /** @var \Magento\Paypal\Model\Api\ProcessableException|\PHPUnit_Framework_MockObject_MockObject */
3637 protected $ processableException ;
3738
38- /** @var \Magento\Framework\Exception\ LocalizedException|\PHPUnit_Framework_MockObject_MockObject */
39+ /** @var LocalizedException|\PHPUnit_Framework_MockObject_MockObject */
3940 protected $ exception ;
4041
4142 /** @var \Magento\Framework\HTTP\Adapter\Curl|\PHPUnit_Framework_MockObject_MockObject */
@@ -47,6 +48,9 @@ class NvpTest extends \PHPUnit\Framework\TestCase
4748 /** @var \Magento\Payment\Model\Method\Logger|\PHPUnit_Framework_MockObject_MockObject */
4849 protected $ customLoggerMock ;
4950
51+ /**
52+ * {@inheritDoc}
53+ */
5054 protected function setUp ()
5155 {
5256 $ this ->customerAddressHelper = $ this ->createMock (\Magento \Customer \Helper \Address::class);
@@ -64,26 +68,32 @@ protected function setUp()
6468 );
6569 $ processableExceptionFactory ->expects ($ this ->any ())
6670 ->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+ }
7079 )
71- ->setConstructorArgs ([$ arguments ['phrase ' ], null , $ arguments ['code ' ]])
72- ->getMock ();
73- return $ this ->processableException ;
74- }));
80+ );
7581 $ exceptionFactory = $ this ->createPartialMock (
7682 \Magento \Framework \Exception \LocalizedExceptionFactory::class,
7783 ['create ' ]
7884 );
7985 $ exceptionFactory ->expects ($ this ->any ())
8086 ->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+ );
8797 $ this ->curl = $ this ->createMock (\Magento \Framework \HTTP \Adapter \Curl::class);
8898 $ curlFactory = $ this ->createPartialMock (\Magento \Framework \HTTP \Adapter \CurlFactory::class, ['create ' ]);
8999 $ curlFactory ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ this ->curl ));
@@ -155,7 +165,7 @@ public function callDataProvider()
155165 [
156166 "\r\n" . 'ACK=Failure&L_ERRORCODE0=10417&L_SHORTMESSAGE0=Message.&L_LONGMESSAGE0=Long%20Message. ' ,
157167 [],
158- \ Magento \ Framework \ Exception \ LocalizedException::class,
168+ LocalizedException::class,
159169 'PayPal gateway has rejected request. Long Message (#10417: Message). ' ,
160170 0
161171 ],
@@ -184,27 +194,56 @@ public function callDataProvider()
184194 ];
185195 }
186196
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 )
188205 {
189206 $ this ->curl ->expects ($ this ->once ())
190207 ->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 '
193230 . '&SHIPTOSTREET=testStreet '
194231 . '&SHIPTOSTREET2=testApartment '
195232 . '&BUSINESS=testCompany '
196233 . '&SHIPTOCITY=testCity '
197234 . '&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+ ];
208247 }
209248
210249 /**
@@ -243,6 +282,9 @@ public function testCallDoReauthorization()
243282 $ this ->assertEquals ($ expectedImportedData , $ this ->model ->getData ());
244283 }
245284
285+ /**
286+ * Test replace keys for debug data
287+ */
246288 public function testGetDebugReplacePrivateDataKeys ()
247289 {
248290 $ debugReplacePrivateDataKeys = $ this ->_invokeNvpProperty ($ this ->model , '_debugReplacePrivateDataKeys ' );
0 commit comments