Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into jsunit
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirZaets committed Oct 18, 2016
2 parents 4c2e0a9 + fc7ad0d commit 7ca957f
Show file tree
Hide file tree
Showing 74 changed files with 2,372 additions and 717 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Model\Ui\Adminhtml\PayPal;

use Magento\Braintree\Gateway\Config\PayPal\Config;
use Magento\Braintree\Model\Ui\ConfigProvider;
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider as PayPalConfigProvider;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\Template;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory;
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface;

/**
* Gets Ui component configuration for Braintree PayPal Vault
*/
class TokenUiComponentProvider implements TokenUiComponentProviderInterface
{

/**
* @var TokenUiComponentInterfaceFactory
*/
private $componentFactory;

/**
* @var UrlInterface
*/
private $urlBuilder;

/**
* @var Config
*/
private $config;

/**
* @param TokenUiComponentInterfaceFactory $componentFactory
* @param UrlInterface $urlBuilder
* @param Config $config
*/
public function __construct(
TokenUiComponentInterfaceFactory $componentFactory,
UrlInterface $urlBuilder,
Config $config
) {
$this->componentFactory = $componentFactory;
$this->urlBuilder = $urlBuilder;
$this->config = $config;
}

/**
* @inheritdoc
*/
public function getComponentForToken(PaymentTokenInterface $paymentToken)
{
$data = json_decode($paymentToken->getTokenDetails() ?: '{}', true);
$data['icon'] = $this->config->getPayPalIcon();
$component = $this->componentFactory->create(
[
'config' => [
'code' => PayPalConfigProvider::PAYPAL_VAULT_CODE,
'nonceUrl' => $this->getNonceRetrieveUrl(),
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $data,
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash(),
'template' => 'Magento_Braintree::form/paypal/vault.phtml'
],
'name' => Template::class
]
);

return $component;
}

/**
* Get url to retrieve payment method nonce
* @return string
*/
private function getNonceRetrieveUrl()
{
return $this->urlBuilder->getUrl(ConfigProvider::CODE . '/payment/getnonce', ['_secure' => true]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function getComponentForToken(PaymentTokenInterface $paymentToken)
$component = $this->componentFactory->create(
[
'config' => [
'code' => ConfigProvider::CC_VAULT_CODE,
'nonceUrl' => $this->getNonceRetrieveUrl(),
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $data,
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Test\Unit\Model\Ui\Adminhtml\PayPal;

use Magento\Braintree\Gateway\Config\PayPal\Config;
use Magento\Braintree\Model\Ui\Adminhtml\PayPal\TokenUiComponentProvider;
use Magento\Framework\UrlInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Model\Ui\TokenUiComponentInterface;
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Contains methods to test PayPal token Ui component provider
*/
class TokenUiComponentProviderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var TokenUiComponentInterfaceFactory|MockObject
*/
private $componentFactory;

/**
* @var UrlInterface|MockObject
*/
private $urlBuilder;

/**
* @var Config|MockObject
*/
private $config;

/**
* @var TokenUiComponentProvider
*/
private $tokenUiComponentProvider;

protected function setUp()
{
$this->componentFactory = $this->getMockBuilder(TokenUiComponentInterfaceFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$this->urlBuilder = $this->getMock(UrlInterface::class);

$this->config = $this->getMockBuilder(Config::class)
->disableOriginalConstructor()
->setMethods(['getPayPalIcon'])
->getMock();

$this->tokenUiComponentProvider = new TokenUiComponentProvider(
$this->componentFactory,
$this->urlBuilder,
$this->config
);
}

/**
* @covers \Magento\Braintree\Model\Ui\Adminhtml\PayPal\TokenUiComponentProvider::getComponentForToken
*/
public function testGetComponentForToken()
{
$nonceUrl = 'https://payment/adminhtml/nonce/url';
$payerEmail = 'john.doe@test.com';
$icon = [
'url' => 'https://payment/adminhtml/icon.png',
'width' => 48,
'height' => 32
];

$expected = [
'code' => 'vault',
'nonceUrl' => $nonceUrl,
'details' => [
'payerEmail' => $payerEmail,
'icon' => $icon
],
'template' => 'vault.phtml'
];

$this->config->expects(static::once())
->method('getPayPalIcon')
->willReturn($icon);

$paymentToken = $this->getMock(PaymentTokenInterface::class);
$paymentToken->expects(static::once())
->method('getTokenDetails')
->willReturn('{"payerEmail":" ' . $payerEmail . '"}');
$paymentToken->expects(static::once())
->method('getPublicHash')
->willReturn('cmk32dl21l');

$this->urlBuilder->expects(static::once())
->method('getUrl')
->willReturn($nonceUrl);

$tokenComponent = $this->getMock(TokenUiComponentInterface::class);
$tokenComponent->expects(static::once())
->method('getConfig')
->willReturn($expected);

$this->componentFactory->expects(static::once())
->method('create')
->willReturn($tokenComponent);

$component = $this->tokenUiComponentProvider->getComponentForToken($paymentToken);
static::assertEquals($tokenComponent, $component);
static::assertEquals($expected, $component->getConfig());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

use Magento\Braintree\Model\Ui\Adminhtml\TokenUiComponentProvider;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\Template;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Model\Ui\TokenUiComponentInterface;
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class TokenUiComponentProviderTest
Expand All @@ -19,12 +19,12 @@ class TokenUiComponentProviderTest extends \PHPUnit_Framework_TestCase
{

/**
* @var TokenUiComponentInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
* @var TokenUiComponentInterfaceFactory|MockObject
*/
private $componentFactory;

/**
* @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject
* @var UrlInterface|MockObject
*/
private $urlBuilder;

Expand Down Expand Up @@ -59,6 +59,7 @@ public function testGetComponentForToken()
$expirationDate = '12/2015';

$expected = [
'code' => 'vault',
'nonceUrl' => $nonceUrl,
'details' => [
'type' => $type,
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Braintree/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<arguments>
<argument name="tokenUiComponentProviders" xsi:type="array">
<item name="braintree" xsi:type="object">Magento\Braintree\Model\Ui\Adminhtml\TokenUiComponentProvider</item>
<item name="braintree_paypal" xsi:type="object">Magento\Braintree\Model\Ui\Adminhtml\PayPal\TokenUiComponentProvider</item>
</argument>
</arguments>
</type>
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Braintree/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
</braintree_cc_vault>
<braintree_paypal_vault>
<model>BraintreePayPalVaultFacade</model>
<title>Vault Token (Braintree PayPal)</title>
<title>Stored Accounts (Braintree PayPal)</title>
<can_use_internal>1</can_use_internal>
</braintree_paypal_vault>
</payment>
</default>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<argument name="method" xsi:type="string">braintree_cc_vault</argument>
<argument name="template" xsi:type="string">Magento_Vault::form/vault.phtml</argument>
</action>
<action method="setMethodFormTemplate">
<argument name="method" xsi:type="string">braintree_paypal_vault</argument>
<argument name="template" xsi:type="string">Magento_Vault::form/vault.phtml</argument>
</action>
</referenceBlock>
<referenceBlock name="content">
<block name="braintree_payment_script"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<argument name="method" xsi:type="string">braintree_cc_vault</argument>
<argument name="template" xsi:type="string">Magento_Vault::form/vault.phtml</argument>
</action>
<action method="setMethodFormTemplate">
<argument name="method" xsi:type="string">braintree_paypal_vault</argument>
<argument name="template" xsi:type="string">Magento_Vault::form/vault.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface;
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile

/** @var \Magento\Framework\View\Element\Template $block */
$details = $block->getData(TokenUiComponentProviderInterface::COMPONENT_DETAILS);
$icon = $details['icon'];
$id = $block->escapeHtml($block->getData('id'));
?>
<div data-mage-init='{
"Magento_Braintree/js/vault": {
"container": "payment_<?php /* @noEscape */ echo $id; ?>",
"publicHash": "<?php echo $block->escapeHtml($block->getData(TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH)); ?>",
"code": "<?php echo $block->escapeHtml($block->getData('code')); ?>",
"nonceUrl": "<?php echo $block->escapeUrl($block->getData('nonceUrl')); ?>"
}
}' id="payment_<?php /* @noEscape */ echo $id;?>" class="admin__field">
<div class="admin__field-control control">
<input type="radio" id="token_switcher_<?php /* @noEscape */ echo $id; ?>" name="payment[token_switcher]"/>
<img src="<?php echo $block->escapeUrl($icon['url']); ?>"
width="<?php echo $block->escapeHtml($icon['width']); ?>"
height="<?php echo $block->escapeHtml($icon['height']); ?>"
class="payment-icon" >
<span><?php echo $block->escapeHtml($details['payerEmail']); ?></span>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface;
// @codingStandardsIgnoreFile

/** @var \Magento\Framework\View\Element\Template $block */
$details = $block->getData('details');
$details = $block->getData(TokenUiComponentProviderInterface::COMPONENT_DETAILS);
$icon = $block->getData('icons')[$details['type']];
$id = $block->escapeHtml($block->getData('id'));
?>
<div data-mage-init='{
"Magento_Braintree/js/vault": {
"container": "payment_<?php /* @noEscape */ echo $id; ?>",
"publicHash": "<?php echo $block->escapeHtml($block->getData(TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH)); ?>",
"code": "<?php echo $block->escapeHtml($block->getData('code')); ?>",
"nonceUrl": "<?php echo $block->escapeUrl($block->getData('nonceUrl')); ?>"
}
}' id="payment_<?php /* @noEscape */ echo $id;?>" class="admin__field">
Expand Down
Loading

0 comments on commit 7ca957f

Please sign in to comment.