Skip to content

Commit

Permalink
Merge pull request #59 from magento-epam/2.3-develop
Browse files Browse the repository at this point in the history
Merge 2.3-develop to EPAM-PR-3
  • Loading branch information
nikshostko authored Aug 17, 2018
2 parents 5ab1fa5 + 9b01481 commit 51e3616
Show file tree
Hide file tree
Showing 58 changed files with 817 additions and 191 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Test\Unit\Model\InstantPurchase\CreditCard;

use Magento\Braintree\Gateway\Config\Config;
use Magento\Braintree\Model\InstantPurchase\CreditCard\AvailabilityChecker;

/**
* @covers \Magento\Braintree\Model\InstantPurchase\CreditCard\AvailabilityChecker
*/
class AvailabilityCheckerTest extends \PHPUnit\Framework\TestCase
{
/**
* Testable Object
*
* @var AvailabilityChecker
*/
private $availabilityChecker;

/**
* @var Config|\PHPUnit_Framework_MockObject_MockObject
*/
private $configMock;

/**
* Set Up
*
* @return void
*/
protected function setUp()
{
$this->configMock = $this->createMock(Config::class);
$this->availabilityChecker = new AvailabilityChecker($this->configMock);
}

/**
* Test isAvailable method
*
* @dataProvider isAvailableDataProvider
*
* @param bool $isVerify3DSecure
* @param bool $expected
*
* @return void
*/
public function testIsAvailable(bool $isVerify3DSecure, bool $expected)
{
$this->configMock->expects($this->once())->method('isVerify3DSecure')->willReturn($isVerify3DSecure);
$actual = $this->availabilityChecker->isAvailable();
self::assertEquals($expected, $actual);
}

/**
* Data provider for isAvailable method test
*
* @return array
*/
public function isAvailableDataProvider()
{
return [
[true, false],
[false, true],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Test\Unit\Model\InstantPurchase\CreditCard;

use Magento\Braintree\Model\InstantPurchase\CreditCard\TokenFormatter as CreditCardTokenFormatter;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject;

class TokenFormatterTest extends TestCase
{
/**
* @var PaymentTokenInterface|PHPUnit_Framework_MockObject_MockObject
*/
private $paymentTokenMock;

/**
* @var CreditCardTokenFormatter
*/
private $creditCardTokenFormatter;

/**
* @var array
*/
private $tokenDetails = [
'type' => 'visa',
'maskedCC' => '1111************9999',
'expirationDate' => '01-01-2020'
];

/**
* Set Up
*
* @return void
*/
protected function setUp()
{
$this->paymentTokenMock = $this->getMockBuilder(PaymentTokenInterface::class)
->getMockForAbstractClass();

$this->creditCardTokenFormatter = new CreditCardTokenFormatter();
}

/**
* Testing the payment format with a known credit card type
*
* @return void
*/
public function testFormatPaymentTokenWithKnownCardType()
{
$this->tokenDetails['type'] = key(CreditCardTokenFormatter::$baseCardTypes);
$this->paymentTokenMock->expects($this->once())
->method('getTokenDetails')
->willReturn(json_encode($this->tokenDetails));

$formattedString = sprintf(
'%s: %s, %s: %s (%s: %s)',
__('Credit Card'),
reset(CreditCardTokenFormatter::$baseCardTypes),
__('ending'),
$this->tokenDetails['maskedCC'],
__('expires'),
$this->tokenDetails['expirationDate']
);

self::assertEquals(
$formattedString,
$this->creditCardTokenFormatter->formatPaymentToken($this->paymentTokenMock)
);
}

/**
* Testing the payment format with a unknown credit card type
*
* @return void
*/
public function testFormatPaymentTokenWithUnknownCardType()
{
$this->paymentTokenMock->expects($this->once())
->method('getTokenDetails')
->willReturn(json_encode($this->tokenDetails));

$formattedString = sprintf(
'%s: %s, %s: %s (%s: %s)',
__('Credit Card'),
$this->tokenDetails['type'],
__('ending'),
$this->tokenDetails['maskedCC'],
__('expires'),
$this->tokenDetails['expirationDate']
);

self::assertEquals(
$formattedString,
$this->creditCardTokenFormatter->formatPaymentToken($this->paymentTokenMock)
);
}

/**
* Testing the payment format with wrong card data
*
* @return void
*/
public function testFormatPaymentTokenWithWrongData()
{
unset($this->tokenDetails['type']);
$this->paymentTokenMock->expects($this->once())
->method('getTokenDetails')
->willReturn(json_encode($this->tokenDetails));
self::expectException('\InvalidArgumentException');

$this->creditCardTokenFormatter->formatPaymentToken($this->paymentTokenMock);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Test\Unit\Model\InstantPurchase;

use Magento\Braintree\Gateway\Command\GetPaymentNonceCommand;
use Magento\Braintree\Model\InstantPurchase\PaymentAdditionalInformationProvider;
use Magento\Payment\Gateway\Command\Result\ArrayResult;
use Magento\Vault\Api\Data\PaymentTokenInterface;

/**
* @covers \Magento\Braintree\Model\InstantPurchase\PaymentAdditionalInformationProvider
*/
class PaymentAdditionalInformationProviderTest extends \PHPUnit\Framework\TestCase
{
/**
* Testable Object
*
* @var PaymentAdditionalInformationProvider
*/
private $paymentAdditionalInformationProvider;

/**
* @var GetPaymentNonceCommand|\PHPUnit_Framework_MockObject_MockObject
*/
private $getPaymentNonceCommandMock;

/**
* @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $paymentTokenMock;

/**
* @var ArrayResult|\PHPUnit_Framework_MockObject_MockObject
*/
private $arrayResultMock;

/**
* Set Up
*
* @return void
*/
protected function setUp()
{
$this->getPaymentNonceCommandMock = $this->createMock(GetPaymentNonceCommand::class);
$this->paymentTokenMock = $this->createMock(PaymentTokenInterface::class);
$this->arrayResultMock = $this->createMock(ArrayResult::class);
$this->paymentAdditionalInformationProvider = new PaymentAdditionalInformationProvider(
$this->getPaymentNonceCommandMock
);
}

/**
* Test getAdditionalInformation method
*
* @return void
*/
public function testGetAdditionalInformation()
{
$customerId = 15;
$publicHash = '3n4b7sn48g';
$paymentMethodNonce = 'test';

$this->paymentTokenMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->paymentTokenMock->expects($this->once())->method('getPublicHash')->willReturn($publicHash);
$this->getPaymentNonceCommandMock->expects($this->once())->method('execute')->with([
PaymentTokenInterface::CUSTOMER_ID => $customerId,
PaymentTokenInterface::PUBLIC_HASH => $publicHash,
])->willReturn($this->arrayResultMock);
$this->arrayResultMock->expects($this->once())->method('get')
->willReturn(['paymentMethodNonce' => $paymentMethodNonce]);

$expected = [
'payment_method_nonce' => $paymentMethodNonce,
];
$actual = $this->paymentAdditionalInformationProvider->getAdditionalInformation($this->paymentTokenMock);
self::assertEquals($expected, $actual);
}
}
Loading

0 comments on commit 51e3616

Please sign in to comment.