Skip to content

Commit dbe547a

Browse files
MAGETWO-94402: [2.3.0] PayPal Billing Address for Registered Customers
- add and fix integration tests for PayPal Express Checkout
1 parent 0d70a50 commit dbe547a

File tree

1 file changed

+131
-24
lines changed

1 file changed

+131
-24
lines changed

dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php

Lines changed: 131 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ public function testReturnFromPaypal()
293293
/**
294294
* The case when handling address data from Paypal button.
295295
* System's address fields are replacing from export Paypal data.
296+
* Billing and Shipping address are the same
296297
*
297298
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
298299
* @magentoAppIsolation enabled
@@ -307,39 +308,131 @@ public function testReturnFromPaypalButton()
307308
$this->checkoutModel->returnFromPaypal('token');
308309

309310
$shippingAddress = $quote->getShippingAddress();
311+
$billingAddress = $quote->getBillingAddress();
312+
$prefix = '';
313+
314+
$this->assertEquals([$prefix . $this->getExportedData()['shipping']['street']], $shippingAddress->getStreet());
315+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['firstname'], $shippingAddress->getFirstname());
316+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['city'], $shippingAddress->getCity());
317+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['telephone'], $shippingAddress->getTelephone());
318+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['email'], $shippingAddress->getEmail());
319+
320+
$this->assertEquals([$prefix . $this->getExportedData()['shipping']['street']], $billingAddress->getStreet());
321+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['firstname'], $billingAddress->getFirstname());
322+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['city'], $billingAddress->getCity());
323+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['telephone'], $billingAddress->getTelephone());
324+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['email'], $billingAddress->getEmail());
325+
}
326+
327+
/**
328+
* The case when handling address data from Paypal button.
329+
* System's address fields are replacing from export Paypal data.
330+
* Billing and Shipping address are different
331+
*
332+
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
333+
* @magentoAppIsolation enabled
334+
* @magentoDbIsolation enabled
335+
*/
336+
public function testReturnFromPaypalButtonWithReturnBillingAddress()
337+
{
338+
$quote = $this->getFixtureQuote();
339+
$this->paypalConfig->expects($this->exactly(2))
340+
->method('getValue')
341+
->with('requireBillingAddress')
342+
->willReturn(1);
343+
$this->prepareCheckoutModel($quote);
344+
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 1);
345+
346+
$this->checkoutModel->returnFromPaypal('token');
347+
348+
$shippingAddress = $quote->getShippingAddress();
349+
$billingAddress = $quote->getBillingAddress();
310350
$prefix = '';
311351

312-
$this->assertEquals([$prefix . $this->getExportedData()['street']], $shippingAddress->getStreet());
313-
$this->assertEquals($prefix . $this->getExportedData()['firstname'], $shippingAddress->getFirstname());
314-
$this->assertEquals($prefix . $this->getExportedData()['city'], $shippingAddress->getCity());
315-
$this->assertEquals($prefix . $this->getExportedData()['telephone'], $shippingAddress->getTelephone());
316-
$this->assertEquals($prefix . $this->getExportedData()['email'], $shippingAddress->getEmail());
352+
$this->assertEquals([$prefix . $this->getExportedData()['shipping']['street']], $shippingAddress->getStreet());
353+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['firstname'], $shippingAddress->getFirstname());
354+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['city'], $shippingAddress->getCity());
355+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['telephone'], $shippingAddress->getTelephone());
356+
$this->assertEquals($prefix . $this->getExportedData()['shipping']['email'], $shippingAddress->getEmail());
357+
358+
$this->assertEquals([$prefix . $this->getExportedData()['billing']['street']], $billingAddress->getStreet());
359+
$this->assertEquals($prefix . $this->getExportedData()['billing']['firstname'], $billingAddress->getFirstname());
360+
$this->assertEquals($prefix . $this->getExportedData()['billing']['city'], $billingAddress->getCity());
361+
$this->assertEquals($prefix . $this->getExportedData()['billing']['telephone'], $billingAddress->getTelephone());
362+
$this->assertEquals($prefix . $this->getExportedData()['billing']['email'], $billingAddress->getEmail());
317363
}
318364

319365
/**
320366
* The case when handling address data from the checkout.
321367
* System's address fields are not replacing from export PayPal data.
368+
* Billing and Shipping address are the same
322369
*
323370
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
324371
* @magentoAppIsolation enabled
325372
* @magentoDbIsolation enabled
326373
*/
327374
public function testReturnFromPaypalIfCheckout()
328375
{
376+
$prefix = 'exported';
329377
$quote = $this->getFixtureQuote();
330-
$this->prepareCheckoutModel($quote);
378+
$this->prepareCheckoutModel($quote, $prefix);
331379
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 0);
332380

381+
$originalShippingAddress = $quote->getShippingAddress();
382+
$originalBillingAddress = $quote->getBillingAddress();
383+
333384
$this->checkoutModel->returnFromPaypal('token');
334385

335386
$shippingAddress = $quote->getShippingAddress();
387+
$billingAddress = $quote->getBillingAddress();
388+
389+
$this->assertEquals($originalShippingAddress->getStreet(), $shippingAddress->getStreet());
390+
$this->assertEquals($originalShippingAddress->getFirstname(), $shippingAddress->getFirstname());
391+
$this->assertEquals($originalShippingAddress->getCity(), $shippingAddress->getCity());
392+
$this->assertEquals($originalShippingAddress->getTelephone(), $shippingAddress->getTelephone());
336393

394+
$this->assertEquals($originalBillingAddress->getStreet(), $billingAddress->getStreet());
395+
$this->assertEquals($originalBillingAddress->getFirstname(), $billingAddress->getFirstname());
396+
$this->assertEquals($originalBillingAddress->getCity(), $billingAddress->getCity());
397+
$this->assertEquals($originalBillingAddress->getTelephone(), $billingAddress->getTelephone());
398+
}
399+
400+
/**
401+
* The case when handling address data from the checkout.
402+
* System's address fields are replacing billing address from export PayPal data.
403+
* Billing and Shipping address are different
404+
*
405+
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
406+
* @magentoAppIsolation enabled
407+
* @magentoDbIsolation enabled
408+
*/
409+
public function testReturnFromPaypalIfCheckoutWithReturnBillingAddress()
410+
{
337411
$prefix = 'exported';
412+
$quote = $this->getFixtureQuote();
413+
$this->paypalConfig->expects($this->exactly(2))
414+
->method('getValue')
415+
->with('requireBillingAddress')
416+
->willReturn(1);
417+
$this->prepareCheckoutModel($quote, $prefix);
418+
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 0);
419+
420+
$originalShippingAddress = $quote->getShippingAddress();
421+
422+
$this->checkoutModel->returnFromPaypal('token');
338423

339-
$this->assertNotEquals([$prefix . $this->getExportedData()['street']], $shippingAddress->getStreet());
340-
$this->assertNotEquals($prefix . $this->getExportedData()['firstname'], $shippingAddress->getFirstname());
341-
$this->assertNotEquals($prefix . $this->getExportedData()['city'], $shippingAddress->getCity());
342-
$this->assertNotEquals($prefix . $this->getExportedData()['telephone'], $shippingAddress->getTelephone());
424+
$shippingAddress = $quote->getShippingAddress();
425+
$billingAddress = $quote->getBillingAddress();
426+
427+
$this->assertEquals($originalShippingAddress->getStreet(), $shippingAddress->getStreet());
428+
$this->assertEquals($originalShippingAddress->getFirstname(), $shippingAddress->getFirstname());
429+
$this->assertEquals($originalShippingAddress->getCity(), $shippingAddress->getCity());
430+
$this->assertEquals($originalShippingAddress->getTelephone(), $shippingAddress->getTelephone());
431+
432+
$this->assertEquals([$prefix . $this->getExportedData()['billing']['street']], $billingAddress->getStreet());
433+
$this->assertEquals($prefix . $this->getExportedData()['billing']['firstname'], $billingAddress->getFirstname());
434+
$this->assertEquals($prefix . $this->getExportedData()['billing']['city'], $billingAddress->getCity());
435+
$this->assertEquals($prefix . $this->getExportedData()['billing']['telephone'], $billingAddress->getTelephone());
343436
}
344437

345438
/**
@@ -363,7 +456,7 @@ public function testReturnFromPayPalForCustomerWithEmptyAddresses(): void
363456

364457
$billingAddress = $quote->getBillingAddress();
365458

366-
$this->performQuoteAddressAssertions($billingAddress, $this->getExportedData());
459+
$this->performQuoteAddressAssertions($billingAddress, $this->getExportedData()['billing']);
367460
}
368461

369462
/**
@@ -437,7 +530,7 @@ private function performQuoteAddressAssertions(Address $address, array $expected
437530
*
438531
* @param Quote $quote
439532
*/
440-
private function prepareCheckoutModel(Quote $quote)
533+
private function prepareCheckoutModel(Quote $quote, $prefix = '')
441534
{
442535
$this->checkoutModel = $this->objectManager->create(
443536
Checkout::class,
@@ -448,11 +541,11 @@ private function prepareCheckoutModel(Quote $quote)
448541
]
449542
);
450543

451-
$exportedBillingAddress = $this->getExportedAddressFixture($this->getExportedData());
544+
$exportedBillingAddress = $this->getExportedAddressFixture($this->getExportedData()['billing'], $prefix);
452545
$this->api->method('getExportedBillingAddress')
453546
->willReturn($exportedBillingAddress);
454547

455-
$exportedShippingAddress = $this->getExportedAddressFixture($this->getExportedData());
548+
$exportedShippingAddress = $this->getExportedAddressFixture($this->getExportedData()['shipping'], $prefix);
456549
$this->api->method('getExportedShippingAddress')
457550
->willReturn($exportedShippingAddress);
458551

@@ -468,16 +561,30 @@ private function prepareCheckoutModel(Quote $quote)
468561
private function getExportedData(): array
469562
{
470563
return [
471-
'email' => 'customer@example.com',
472-
'firstname' => 'John',
473-
'lastname' => 'Doe',
474-
'country' => 'US',
475-
'region' => 'Colorado',
476-
'region_id' => '13',
477-
'city' => 'Denver',
478-
'street' => '66 Pearl St',
479-
'postcode' => '80203',
480-
'telephone' => '555-555-555',
564+
'shipping' => [
565+
'email' => 'customer@example.com',
566+
'firstname' => 'John',
567+
'lastname' => 'Doe',
568+
'country' => 'US',
569+
'region' => 'Colorado',
570+
'region_id' => '13',
571+
'city' => 'Denver',
572+
'street' => '66 Pearl St',
573+
'postcode' => '80203',
574+
'telephone' => '555-555-555'
575+
],
576+
'billing' => [
577+
'email' => 'customer@example.com',
578+
'firstname' => 'Jane',
579+
'lastname' => 'Doe',
580+
'country' => 'US',
581+
'region' => 'Texas',
582+
'region_id' => '13',
583+
'city' => 'Austin',
584+
'street' => '1100 Congress Ave',
585+
'postcode' => '78701',
586+
'telephone' => '555-555-555'
587+
]
481588
];
482589
}
483590

0 commit comments

Comments
 (0)