-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - #13688: #13685 Upgrade jquery.mobile.custom.js to be compatible with jQuery 3.x (by @kirmorozov) - #13527: Removing deprecated dependencies from Braintree module (by @joni-jones) - #13655: [Port 2.3-develop] Update Store getConfig() to respect valid false return value (by @JeroenVanLeusden) Fixed GitHub Issues: - #13685: Incompatibilies with jQuery 3 (reported by @kirmorozov) has been fixed in #13688 by @kirmorozov in 2.3-develop branch Related commits: 1. c36fb76 2. b21f2a6
- Loading branch information
Showing
10 changed files
with
1,225 additions
and
1,052 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
*/ | ||
namespace Magento\Braintree\Test\Unit\Gateway\Response\PayPal; | ||
|
||
use Braintree\Result\Successful; | ||
use Braintree\Transaction; | ||
use Braintree\Transaction\PayPalDetails; | ||
use Magento\Braintree\Gateway\Helper\SubjectReader; | ||
|
@@ -15,24 +16,23 @@ | |
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface; | ||
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory; | ||
use Magento\Sales\Model\Order\Payment; | ||
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface; | ||
use Magento\Vault\Api\Data\PaymentTokenInterface; | ||
use Magento\Vault\Api\Data\PaymentTokenInterfaceFactory; | ||
use Magento\Vault\Model\AccountPaymentTokenFactory; | ||
use Magento\Vault\Model\PaymentToken; | ||
use PHPUnit\Framework\TestCase; | ||
use PHPUnit_Framework_MockObject_MockObject as MockObject; | ||
|
||
/** | ||
* Class VaultDetailsHandlerTest | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class VaultDetailsHandlerTest extends \PHPUnit\Framework\TestCase | ||
class VaultDetailsHandlerTest extends TestCase | ||
{ | ||
private static $transactionId = '1n2suy'; | ||
|
||
/** | ||
* @var SubjectReader|MockObject | ||
*/ | ||
private $subjectReader; | ||
private static $token = 'rc39al'; | ||
|
||
private static $payerEmail = '[email protected]'; | ||
|
||
/** | ||
* @var PaymentDataObjectInterface|MockObject | ||
|
@@ -45,7 +45,7 @@ class VaultDetailsHandlerTest extends \PHPUnit\Framework\TestCase | |
private $paymentInfo; | ||
|
||
/** | ||
* @var AccountPaymentTokenFactory|MockObject | ||
* @var PaymentTokenFactoryInterface|MockObject | ||
*/ | ||
private $paymentTokenFactory; | ||
|
||
|
@@ -92,7 +92,7 @@ protected function setUp() | |
|
||
$this->paymentToken = $objectManager->getObject(PaymentToken::class); | ||
|
||
$this->paymentTokenFactory = $this->getMockBuilder(AccountPaymentTokenFactory::class) | ||
$this->paymentTokenFactory = $this->getMockBuilder(PaymentTokenFactoryInterface::class) | ||
->setMethods(['create']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
@@ -109,14 +109,6 @@ protected function setUp() | |
$this->subject = [ | ||
'payment' => $this->paymentDataObject, | ||
]; | ||
$this->subjectReader = $this->getMockBuilder(SubjectReader::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['readPayment', 'readTransaction']) | ||
->getMock(); | ||
$this->subjectReader->expects(static::once()) | ||
->method('readPayment') | ||
->with($this->subject) | ||
->willReturn($this->paymentDataObject); | ||
|
||
$this->dateTimeFactory = $this->getMockBuilder(DateTimeFactory::class) | ||
->disableOriginalConstructor() | ||
|
@@ -126,123 +118,102 @@ protected function setUp() | |
$this->handler = new VaultDetailsHandler( | ||
$this->paymentTokenFactory, | ||
$this->paymentExtensionFactory, | ||
$this->subjectReader, | ||
new SubjectReader(), | ||
$this->dateTimeFactory | ||
); | ||
} | ||
|
||
/** | ||
* @covers \Magento\Braintree\Gateway\Response\PayPal\VaultDetailsHandler::handle | ||
*/ | ||
public function testHandle() | ||
{ | ||
/** @var Transaction $transaction */ | ||
$transaction = $this->getTransaction(); | ||
$response = [ | ||
'object' => $transaction | ||
]; | ||
|
||
$this->paymentExtension->expects(static::once()) | ||
->method('setVaultPaymentToken') | ||
$this->paymentExtension->method('setVaultPaymentToken') | ||
->with($this->paymentToken); | ||
$this->paymentExtension->expects(static::once()) | ||
->method('getVaultPaymentToken') | ||
$this->paymentExtension->method('getVaultPaymentToken') | ||
->willReturn($this->paymentToken); | ||
|
||
$this->subjectReader->expects(static::once()) | ||
->method('readTransaction') | ||
->with($response) | ||
->willReturn($transaction); | ||
|
||
$this->paymentDataObject->expects(static::once()) | ||
->method('getPayment') | ||
$this->paymentDataObject->method('getPayment') | ||
->willReturn($this->paymentInfo); | ||
|
||
$this->paymentTokenFactory->expects(static::once()) | ||
->method('create') | ||
$this->paymentTokenFactory->method('create') | ||
->with(PaymentTokenFactoryInterface::TOKEN_TYPE_ACCOUNT) | ||
->willReturn($this->paymentToken); | ||
|
||
$this->paymentExtensionFactory->expects(static::once()) | ||
->method('create') | ||
$this->paymentExtensionFactory->method('create') | ||
->willReturn($this->paymentExtension); | ||
|
||
$dateTime = new \DateTime('2016-07-05 00:00:00', new \DateTimeZone('UTC')); | ||
$expirationDate = '2017-07-05 00:00:00'; | ||
$this->dateTimeFactory->expects(static::once()) | ||
->method('create') | ||
$this->dateTimeFactory->method('create') | ||
->willReturn($dateTime); | ||
|
||
$this->handler->handle($this->subject, $response); | ||
|
||
$extensionAttributes = $this->paymentInfo->getExtensionAttributes(); | ||
/** @var PaymentTokenInterface $paymentToken */ | ||
$paymentToken = $extensionAttributes->getVaultPaymentToken(); | ||
static::assertNotNull($paymentToken); | ||
self::assertNotNull($paymentToken); | ||
|
||
$tokenDetails = json_decode($paymentToken->getTokenDetails(), true); | ||
|
||
static::assertSame($this->paymentToken, $paymentToken); | ||
static::assertEquals($transaction->paypalDetails->token, $paymentToken->getGatewayToken()); | ||
static::assertEquals($transaction->paypalDetails->payerEmail, $tokenDetails['payerEmail']); | ||
static::assertEquals($expirationDate, $paymentToken->getExpiresAt()); | ||
self::assertSame($this->paymentToken, $paymentToken); | ||
self::assertEquals(self::$token, $paymentToken->getGatewayToken()); | ||
self::assertEquals(self::$payerEmail, $tokenDetails['payerEmail']); | ||
self::assertEquals($expirationDate, $paymentToken->getExpiresAt()); | ||
} | ||
|
||
/** | ||
* @covers \Magento\Braintree\Gateway\Response\PayPal\VaultDetailsHandler::handle | ||
*/ | ||
public function testHandleWithoutToken() | ||
{ | ||
$transaction = $this->getTransaction(); | ||
$transaction->paypalDetails->token = null; | ||
$transaction->transaction->paypalDetails->token = null; | ||
|
||
$response = [ | ||
'object' => $transaction | ||
]; | ||
|
||
$this->subjectReader->expects(static::once()) | ||
->method('readTransaction') | ||
->with($response) | ||
->willReturn($transaction); | ||
|
||
$this->paymentDataObject->expects(static::once()) | ||
->method('getPayment') | ||
$this->paymentDataObject->method('getPayment') | ||
->willReturn($this->paymentInfo); | ||
|
||
$this->paymentTokenFactory->expects(static::never()) | ||
$this->paymentTokenFactory->expects(self::never()) | ||
->method('create'); | ||
|
||
$this->dateTimeFactory->expects(static::never()) | ||
$this->dateTimeFactory->expects(self::never()) | ||
->method('create'); | ||
|
||
$this->handler->handle($this->subject, $response); | ||
static::assertNull($this->paymentInfo->getExtensionAttributes()); | ||
self::assertNull($this->paymentInfo->getExtensionAttributes()); | ||
} | ||
|
||
/** | ||
* Create Braintree transaction | ||
* @return Transaction | ||
* Creates Braintree transaction. | ||
* | ||
* @return Successful | ||
*/ | ||
private function getTransaction() | ||
private function getTransaction(): Successful | ||
{ | ||
$attributes = [ | ||
'id' => self::$transactionId, | ||
'paypalDetails' => $this->getPayPalDetails() | ||
]; | ||
|
||
$transaction = Transaction::factory($attributes); | ||
$result = new Successful(['transaction' => $transaction]); | ||
|
||
return $transaction; | ||
return $result; | ||
} | ||
|
||
/** | ||
* Get PayPal transaction details | ||
* Gets PayPal transaction details. | ||
* | ||
* @return PayPalDetails | ||
*/ | ||
private function getPayPalDetails() | ||
private function getPayPalDetails(): PayPalDetails | ||
{ | ||
$attributes = [ | ||
'token' => 'rc39al', | ||
'payerEmail' => '[email protected]' | ||
'token' => self::$token, | ||
'payerEmail' => self::$payerEmail | ||
]; | ||
|
||
$details = new PayPalDetails($attributes); | ||
|
Oops, something went wrong.