From fd7f15a22e8214eea469af0434bcfef7fbb66cb6 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Thu, 2 Jun 2016 17:07:57 +0300 Subject: [PATCH 01/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Added ability to use several Vault payments at the same time --- app/code/Magento/Braintree/Block/Form.php | 44 ++++- .../Braintree/Model/Ui/ConfigProvider.php | 3 + .../Model/Ui/TokenUiComponentProvider.php | 1 + .../Braintree/Test/Unit/Block/FormTest.php | 57 +++++-- .../Test/Unit/Model/Ui/ConfigProviderTest.php | 5 +- .../Magento/Braintree/etc/adminhtml/di.xml | 7 - .../Braintree/etc/adminhtml/system.xml | 12 ++ app/code/Magento/Braintree/etc/config.xml | 4 + app/code/Magento/Braintree/etc/di.xml | 26 +++ .../layout/sales_order_create_index.xml | 6 + ...order_create_load_block_billing_method.xml | 6 + .../payment/method-renderer/hosted-fields.js | 13 +- .../js/view/payment/method-renderer/vault.js | 10 +- .../Block/Adminhtml/Payflowpro/CcForm.php | 47 +++++- .../Paypal/Model/Payflow/Transparent.php | 2 + .../Payflow/Ui/TokenUiComponentProvider.php | 2 + app/code/Magento/Paypal/etc/adminhtml/di.xml | 8 - .../adminhtml/system/paypal_payflowpro.xml | 12 ++ app/code/Magento/Paypal/etc/config.xml | 4 + app/code/Magento/Paypal/etc/di.xml | 26 +++ .../layout/sales_order_create_index.xml | 6 + ...order_create_load_block_billing_method.xml | 6 + .../method-renderer/payflowpro-method.js | 13 +- app/code/Magento/Vault/Block/Form.php | 4 +- .../System/Config/EmptyFieldsetDecorator.php | 26 --- .../System/Config/EmptySelectDecorator.php | 29 ---- .../Vault/Controller/Cards/DeleteAction.php | 8 +- .../Vault/Gateway/Config/ActiveHandler.php | 41 ----- .../Adminhtml/Source/VaultProvidersMap.php | 64 ------- .../Vault/Model/CustomerTokenManagement.php | 28 +--- app/code/Magento/Vault/Model/Method/Vault.php | 64 +++---- .../Vault/Model/PaymentTokenManagement.php | 6 +- .../Model/PaymentTokenRepositoryProxy.php | 120 -------------- .../Ui/Adminhtml/TokensConfigProvider.php | 77 +++++---- .../Vault/Model/Ui/TokensConfigProvider.php | 75 +++++++-- .../Vault/Model/Ui/VaultConfigProvider.php | 67 ++++++-- .../Vault/Model/VaultPaymentInterface.php | 14 +- .../Vault/Observer/VaultEnableAssigner.php | 11 +- .../Config/EmptyFieldsetDecoratorTest.php | 69 -------- .../Config/EmptySelectDecoratorTest.php | 37 ----- .../Unit/Gateway/Config/ActiveHandlerTest.php | 90 ---------- .../Source/VaultProvidersMapTest.php | 60 ------- .../Model/PaymentTokenRepositoryProxyTest.php | 156 ------------------ app/code/Magento/Vault/etc/adminhtml/di.xml | 1 - .../Magento/Vault/etc/adminhtml/system.xml | 23 --- app/code/Magento/Vault/etc/di.xml | 28 +--- .../js/view/payment/method-renderer/vault.js | 2 +- .../web/js/view/payment/vault-enabler.js | 4 +- 48 files changed, 468 insertions(+), 956 deletions(-) delete mode 100644 app/code/Magento/Vault/Block/System/Config/EmptyFieldsetDecorator.php delete mode 100644 app/code/Magento/Vault/Block/System/Config/EmptySelectDecorator.php delete mode 100644 app/code/Magento/Vault/Gateway/Config/ActiveHandler.php delete mode 100644 app/code/Magento/Vault/Model/Adminhtml/Source/VaultProvidersMap.php delete mode 100644 app/code/Magento/Vault/Model/PaymentTokenRepositoryProxy.php delete mode 100644 app/code/Magento/Vault/Test/Unit/Block/System/Config/EmptyFieldsetDecoratorTest.php delete mode 100644 app/code/Magento/Vault/Test/Unit/Block/System/Config/EmptySelectDecoratorTest.php delete mode 100644 app/code/Magento/Vault/Test/Unit/Gateway/Config/ActiveHandlerTest.php delete mode 100644 app/code/Magento/Vault/Test/Unit/Model/Adminhtml/Source/VaultProvidersMapTest.php delete mode 100644 app/code/Magento/Vault/Test/Unit/Model/PaymentTokenRepositoryProxyTest.php delete mode 100644 app/code/Magento/Vault/etc/adminhtml/system.xml diff --git a/app/code/Magento/Braintree/Block/Form.php b/app/code/Magento/Braintree/Block/Form.php index dc0071f175fb1..bd4efdc993f8f 100644 --- a/app/code/Magento/Braintree/Block/Form.php +++ b/app/code/Magento/Braintree/Block/Form.php @@ -9,9 +9,12 @@ use Magento\Braintree\Gateway\Config\Config as GatewayConfig; use Magento\Braintree\Model\Adminhtml\Source\CcType; use Magento\Braintree\Model\Ui\ConfigProvider; +use Magento\Framework\App\ObjectManager; use Magento\Framework\View\Element\Template\Context; use Magento\Payment\Block\Form\Cc; +use Magento\Payment\Helper\Data; use Magento\Payment\Model\Config; +use Magento\Store\Model\StoreManagerInterface; use Magento\Vault\Model\VaultPaymentInterface; /** @@ -36,9 +39,14 @@ class Form extends Cc protected $ccType; /** - * @var VaultPaymentInterface + * @var Data */ - protected $vaultService; + private $paymentDataHelper; + + /** + * @var StoreManagerInterface + */ + private $storeManager; /** * @param Context $context @@ -46,7 +54,7 @@ class Form extends Cc * @param Quote $sessionQuote * @param GatewayConfig $gatewayConfig * @param CcType $ccType - * @param VaultPaymentInterface $vaultService + * @param StoreManagerInterface $storeManager * @param array $data */ public function __construct( @@ -55,14 +63,14 @@ public function __construct( Quote $sessionQuote, GatewayConfig $gatewayConfig, CcType $ccType, - VaultPaymentInterface $vaultService, + StoreManagerInterface $storeManager, array $data = [] ) { parent::__construct($context, $paymentConfig, $data); $this->sessionQuote = $sessionQuote; $this->gatewayConfig = $gatewayConfig; $this->ccType = $ccType; - $this->vaultService = $vaultService; + $this->storeManager = $storeManager; } /** @@ -91,7 +99,9 @@ public function useCvv() */ public function isVaultEnabled() { - return $this->vaultService->isActiveForPayment(ConfigProvider::CODE); + $storeId = $this->storeManager->getStore()->getId(); + $vaultPayment = $this->getVaultPayment(); + return $vaultPayment->isActive($storeId); } /** @@ -123,4 +133,26 @@ private function filterCardTypesForCountry(array $configCardTypes, $countryId) } return $filtered; } + + /** + * Get configured vault payment for Braintree + * @return VaultPaymentInterface + */ + private function getVaultPayment() + { + return $this->getPaymentDataHelper()->getMethodInstance(ConfigProvider::CC_VAULT_CODE); + } + + /** + * Get payment data helper instance + * @return Data + * @deprecated + */ + private function getPaymentDataHelper() + { + if ($this->paymentDataHelper === null) { + $this->paymentDataHelper = ObjectManager::getInstance()->get(Data::class); + } + return $this->paymentDataHelper; + } } diff --git a/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php b/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php index bba77b0fe9682..d720b748ba819 100644 --- a/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php +++ b/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php @@ -20,6 +20,8 @@ final class ConfigProvider implements ConfigProviderInterface const PAYPAL_CODE = 'braintree_paypal'; + const CC_VAULT_CODE = 'braintree_cc_vault'; + /** * @var ResolverInterface */ @@ -88,6 +90,7 @@ public function getConfig() 'kountMerchantId' => $this->config->getKountMerchantId(), 'hasFraudProtection' => $this->config->hasFraudProtection(), 'merchantId' => $this->config->getMerchantId(), + 'ccVaultCode' => static::CC_VAULT_CODE ], Config::CODE_3DSECURE => [ 'enabled' => $this->config->isVerify3DSecure(), diff --git a/app/code/Magento/Braintree/Model/Ui/TokenUiComponentProvider.php b/app/code/Magento/Braintree/Model/Ui/TokenUiComponentProvider.php index 5f511ebbf4e3d..1fe3fb24db8d8 100644 --- a/app/code/Magento/Braintree/Model/Ui/TokenUiComponentProvider.php +++ b/app/code/Magento/Braintree/Model/Ui/TokenUiComponentProvider.php @@ -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 => $jsonDetails, TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash() diff --git a/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php b/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php index 6c07d2401d56c..5a598c730d7ec 100644 --- a/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php +++ b/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php @@ -14,6 +14,11 @@ use Magento\Payment\Model\Config; use Magento\Vault\Model\Ui\VaultConfigProvider; use Magento\Vault\Model\VaultPaymentInterface; +use OAuthTest\Mocks\Common\Service\Mock; +use PHPUnit_Framework_MockObject_MockObject as MockObject; +use Magento\Store\Model\StoreManagerInterface; +use Magento\Store\Api\Data\StoreInterface; +use Magento\Payment\Helper\Data; /** * Class FormTest @@ -40,32 +45,41 @@ class FormTest extends \PHPUnit_Framework_TestCase private $block; /** - * @var Quote|\PHPUnit_Framework_MockObject_MockObject + * @var Quote|MockObject */ private $sessionQuote; /** - * @var Config|\PHPUnit_Framework_MockObject_MockObject + * @var Config|MockObject */ private $gatewayConfig; /** - * @var CcType|\PHPUnit_Framework_MockObject_MockObject + * @var CcType|MockObject */ private $ccType; /** - * @var VaultPaymentInterface|\PHPUnit_Framework_MockObject_MockObject + * @var StoreManagerInterface|MockObject */ - private $vaultService; + private $storeManager; + + /** + * @var Data|MockObject + */ + private $paymentDataHelper; protected function setUp() { $this->initCcTypeMock(); $this->initSessionQuoteMock(); $this->initGatewayConfigMock(); - - $this->vaultService = $this->getMock(VaultPaymentInterface::class); + + $this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class); + $this->paymentDataHelper = $this->getMockBuilder(Data::class) + ->disableOriginalConstructor() + ->setMethods(['getMethodInstance']) + ->getMock(); $managerHelper = new ObjectManager($this); $this->block = $managerHelper->getObject(Form::class, [ @@ -73,8 +87,10 @@ protected function setUp() 'sessionQuote' => $this->sessionQuote, 'gatewayConfig' => $this->gatewayConfig, 'ccType' => $this->ccType, - 'vaultService' => $this->vaultService + 'storeManager' => $this->storeManager ]); + + $managerHelper->setBackwardCompatibleProperty($this->block, 'paymentDataHelper', $this->paymentDataHelper); } /** @@ -117,11 +133,30 @@ public function countryCardTypesDataProvider() ]; } + /** + * @covers \Magento\Braintree\Block\Form::isVaultEnabled + */ public function testIsVaultEnabled() { - $this->vaultService->expects(static::once()) - ->method('isActiveForPayment') - ->with(ConfigProvider::CODE) + $storeId = 1; + $store = $this->getMockForAbstractClass(StoreInterface::class); + $this->storeManager->expects(static::once()) + ->method('getStore') + ->willReturn($store); + + $store->expects(static::once()) + ->method('getId') + ->willReturn($storeId); + + $vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class); + $this->paymentDataHelper->expects(static::once()) + ->method('getMethodInstance') + ->with(ConfigProvider::CC_VAULT_CODE) + ->willReturn($vaultPayment); + + $vaultPayment->expects(static::once()) + ->method('isActive') + ->with($storeId) ->willReturn(true); static::assertTrue($this->block->isVaultEnabled()); diff --git a/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php b/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php index 71f87f1ec398d..a787111fa93aa 100644 --- a/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php +++ b/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php @@ -148,7 +148,7 @@ public function getConfigDataProvider() 'getEnvironment' => 'test-environment', 'getKountMerchantId' => 'test-kount-merchant-id', 'getMerchantId' => 'test-merchant-id', - 'hasFraudProtection' => true + 'hasFraudProtection' => true, ], 'expected' => [ 'payment' => [ @@ -167,7 +167,8 @@ public function getConfigDataProvider() 'environment' => 'test-environment', 'kountMerchantId' => 'test-kount-merchant-id', 'merchantId' => 'test-merchant-id', - 'hasFraudProtection' => true + 'hasFraudProtection' => true, + 'ccVaultCode' => ConfigProvider::CC_VAULT_CODE ], Config::CODE_3DSECURE => [ 'enabled' => true, diff --git a/app/code/Magento/Braintree/etc/adminhtml/di.xml b/app/code/Magento/Braintree/etc/adminhtml/di.xml index 3a3f372b905a6..48ee8260ce848 100644 --- a/app/code/Magento/Braintree/etc/adminhtml/di.xml +++ b/app/code/Magento/Braintree/etc/adminhtml/di.xml @@ -19,13 +19,6 @@ - - - - BraintreeFacade - - - diff --git a/app/code/Magento/Braintree/etc/adminhtml/system.xml b/app/code/Magento/Braintree/etc/adminhtml/system.xml index a3752db022111..3668cd7779fda 100644 --- a/app/code/Magento/Braintree/etc/adminhtml/system.xml +++ b/app/code/Magento/Braintree/etc/adminhtml/system.xml @@ -34,6 +34,14 @@ + + + Magento\Config\Model\Config\Source\Yesno + payment/braintree_cc_vault/active + + + + Click here to login to your existing Braintree account. Or to setup a new account and accept payments on your website, click here to signup for a Braintree account.]]> @@ -71,6 +79,10 @@ Magento\Config\Block\System\Config\Form\Fieldset + + + payment/braintree_cc_vault/title + If you don't specify the merchant account to use to process a transaction, Braintree will process it using your default merchant account. diff --git a/app/code/Magento/Braintree/etc/config.xml b/app/code/Magento/Braintree/etc/config.xml index 5a1076eabf071..7511ec2ca1563 100644 --- a/app/code/Magento/Braintree/etc/config.xml +++ b/app/code/Magento/Braintree/etc/config.xml @@ -60,6 +60,10 @@ processorResponseCode,processorResponseText,paymentId processorResponseCode,processorResponseText,paymentId,payerEmail + + BraintreeCreditCardVaultFacade + Stored Cards (Braintree) + diff --git a/app/code/Magento/Braintree/etc/di.xml b/app/code/Magento/Braintree/etc/di.xml index e3fee681cc1c1..6e3cb05423929 100644 --- a/app/code/Magento/Braintree/etc/di.xml +++ b/app/code/Magento/Braintree/etc/di.xml @@ -25,6 +25,32 @@ BraintreePayPalCommandPool + + + + Magento\Braintree\Model\Ui\ConfigProvider::CC_VAULT_CODE + + + + + BraintreeVaultPaymentConfig + + + + + + BraintreeVaultPaymentValueHandler + + + + + + BraintreeVaultPaymentConfig + BraintreeVaultPaymentValueHandlerPool + BraintreeFacade + Magento\Braintree\Model\Ui\ConfigProvider::CC_VAULT_CODE + + diff --git a/app/code/Magento/Braintree/view/adminhtml/layout/sales_order_create_index.xml b/app/code/Magento/Braintree/view/adminhtml/layout/sales_order_create_index.xml index c881e008dc24f..76f6b5a4d616c 100644 --- a/app/code/Magento/Braintree/view/adminhtml/layout/sales_order_create_index.xml +++ b/app/code/Magento/Braintree/view/adminhtml/layout/sales_order_create_index.xml @@ -13,6 +13,12 @@ Magento_Braintree::form/cc.phtml + + + braintree_cc_vault + Magento_Vault::form/vault.phtml + + Magento_Braintree::form/cc.phtml + + + braintree_cc_vault + Magento_Vault::form/vault.phtml + + \ No newline at end of file diff --git a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js index bb7697b22da12..ef57428acaa3c 100644 --- a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js +++ b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js @@ -11,7 +11,7 @@ define([ 'Magento_Braintree/js/validator', 'Magento_Vault/js/view/payment/vault-enabler', 'mage/translate' -], function ($, Component, validator, vaultEnabler, $t) { +], function ($, Component, validator, VaultEnabler, $t) { 'use strict'; return Component.extend({ @@ -33,8 +33,8 @@ define([ */ initialize: function () { this._super(); - this.vaultEnabler = vaultEnabler(); - this.vaultEnabler.setPaymentCode(this.getCode()); + this.vaultEnabler = new VaultEnabler(); + this.vaultEnabler.setPaymentCode(this.getVaultCode()); return this; }, @@ -150,6 +150,13 @@ define([ if (this.validateCardType()) { $(this.getSelector('submit')).trigger('click'); } + }, + + /** + * @returns {String} + */ + getVaultCode: function () { + return window.checkoutConfig.payment[this.getCode()].ccVaultCode; } }); }); diff --git a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/vault.js b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/vault.js index 3a96c938603dd..b1b13e9c13ac0 100644 --- a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/vault.js +++ b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/vault.js @@ -21,14 +21,6 @@ define([ } }, - /** - * Get current Braintree vault id - * @returns {String} - */ - getId: function () { - return 'braintree_' + this.index; - }, - /** * Get last 4 digits of card * @returns {String} @@ -75,7 +67,7 @@ define([ self.hostedFields(function (formComponent) { formComponent.setPaymentMethodNonce(response.paymentMethodNonce); formComponent.additionalData['public_hash'] = self.publicHash; - formComponent.code = 'vault'; + formComponent.code = self.code; formComponent.placeOrder(); }); }) diff --git a/app/code/Magento/Paypal/Block/Adminhtml/Payflowpro/CcForm.php b/app/code/Magento/Paypal/Block/Adminhtml/Payflowpro/CcForm.php index 0fb21769a686d..9dfe2ea7effc0 100644 --- a/app/code/Magento/Paypal/Block/Adminhtml/Payflowpro/CcForm.php +++ b/app/code/Magento/Paypal/Block/Adminhtml/Payflowpro/CcForm.php @@ -6,8 +6,12 @@ namespace Magento\Paypal\Block\Adminhtml\Payflowpro; use Magento\Checkout\Model\Session; +use Magento\Framework\App\ObjectManager; use Magento\Framework\View\Element\Template\Context; +use Magento\Payment\Helper\Data; use Magento\Payment\Model\Config; +use Magento\Paypal\Model\Payflow\Transparent; +use Magento\Store\Model\StoreManagerInterface; use Magento\Vault\Model\VaultPaymentInterface; class CcForm extends \Magento\Payment\Block\Transparent\Form @@ -18,26 +22,31 @@ class CcForm extends \Magento\Payment\Block\Transparent\Form protected $_template = 'Magento_Paypal::transparent/form.phtml'; /** - * @var VaultPaymentInterface + * @var Data */ - private $vaultService; + private $paymentDataHelper; + + /** + * @var StoreManagerInterface + */ + private $storeManager; /** * @param Context $context * @param Config $paymentConfig * @param Session $checkoutSession - * @param VaultPaymentInterface $vaultService + * @param StoreManagerInterface $storeManager * @param array $data */ public function __construct( Context $context, Config $paymentConfig, Session $checkoutSession, - VaultPaymentInterface $vaultService, + StoreManagerInterface $storeManager, array $data = [] ) { parent::__construct($context, $paymentConfig, $checkoutSession, $data); - $this->vaultService = $vaultService; + $this->storeManager = $storeManager; } /** @@ -46,9 +55,9 @@ public function __construct( */ public function isVaultEnabled() { - return $this->vaultService->isActiveForPayment( - \Magento\Paypal\Model\Config::METHOD_PAYFLOWPRO - ); + $storeId = $this->storeManager->getStore()->getId(); + $vaultPayment = $this->getVaultPayment(); + return $vaultPayment->isActive($storeId); } /** @@ -68,4 +77,26 @@ protected function initializeMethod() { return; } + + /** + * Get configured vault payment for PayflowPro + * @return VaultPaymentInterface + */ + private function getVaultPayment() + { + return $this->getPaymentDataHelper()->getMethodInstance(Transparent::CC_VAULT_CODE); + } + + /** + * Get payment data helper instance + * @return Data + * @deprecated + */ + private function getPaymentDataHelper() + { + if ($this->paymentDataHelper === null) { + $this->paymentDataHelper = ObjectManager::getInstance()->get(Data::class); + } + return $this->paymentDataHelper; + } } diff --git a/app/code/Magento/Paypal/Model/Payflow/Transparent.php b/app/code/Magento/Paypal/Model/Payflow/Transparent.php index 2c8d43d30b26b..05609ee5ee88f 100644 --- a/app/code/Magento/Paypal/Model/Payflow/Transparent.php +++ b/app/code/Magento/Paypal/Model/Payflow/Transparent.php @@ -32,6 +32,8 @@ class Transparent extends Payflowpro implements TransparentInterface const CC_DETAILS = 'cc_details'; + const CC_VAULT_CODE = 'payflowpro_cc_vault'; + /** * @var string */ diff --git a/app/code/Magento/Paypal/Model/Payflow/Ui/TokenUiComponentProvider.php b/app/code/Magento/Paypal/Model/Payflow/Ui/TokenUiComponentProvider.php index 7957033e546fb..4048d712ea57b 100644 --- a/app/code/Magento/Paypal/Model/Payflow/Ui/TokenUiComponentProvider.php +++ b/app/code/Magento/Paypal/Model/Payflow/Ui/TokenUiComponentProvider.php @@ -5,6 +5,7 @@ */ namespace Magento\Paypal\Model\Payflow\Ui; +use Magento\Paypal\Model\Payflow\Transparent; use Magento\Vault\Api\Data\PaymentTokenInterface; use Magento\Vault\Model\Ui\TokenUiComponentInterface; use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface; @@ -40,6 +41,7 @@ public function getComponentForToken(PaymentTokenInterface $paymentToken) $component = $this->componentFactory->create( [ 'config' => [ + 'code' => Transparent::CC_VAULT_CODE, TokenUiComponentProviderInterface::COMPONENT_DETAILS => $jsonDetails, TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash() ], diff --git a/app/code/Magento/Paypal/etc/adminhtml/di.xml b/app/code/Magento/Paypal/etc/adminhtml/di.xml index 3ba0c2b6164e7..0ae9d9569969d 100644 --- a/app/code/Magento/Paypal/etc/adminhtml/di.xml +++ b/app/code/Magento/Paypal/etc/adminhtml/di.xml @@ -61,14 +61,6 @@ - - - - Magento\Paypal\Model\Payflow\Transparent - - - - diff --git a/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml b/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml index b4a610d31c2aa..2d5fe942d5b40 100644 --- a/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml +++ b/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml @@ -80,6 +80,14 @@ + + + Magento\Config\Model\Config\Source\Yesno + payment/payflowpro_cc_vault/active + + + + @@ -90,6 +98,10 @@ payment/payflowpro/title 1 + + + payment/payflowpro_cc_vault/title + payment/payflowpro/sort_order diff --git a/app/code/Magento/Paypal/etc/config.xml b/app/code/Magento/Paypal/etc/config.xml index 4d8a534db548e..58fff7ea00d4d 100644 --- a/app/code/Magento/Paypal/etc/config.xml +++ b/app/code/Magento/Paypal/etc/config.xml @@ -93,6 +93,10 @@ 1 1 + + PayflowProCreditCardVaultFacade + Stored Cards (Payflow Pro) + 1 1 diff --git a/app/code/Magento/Paypal/etc/di.xml b/app/code/Magento/Paypal/etc/di.xml index 38a3ee049c139..8b287d08e77a4 100644 --- a/app/code/Magento/Paypal/etc/di.xml +++ b/app/code/Magento/Paypal/etc/di.xml @@ -90,6 +90,32 @@ payflowproConfigFactory + + + + Magento\Paypal\Model\Payflow\Transparent::CC_VAULT_CODE + + + + + PayflowProVaultPaymentConfig + + + + + + PayflowProVaultPaymentValueHandler + + + + + + PayflowProVaultPaymentConfig + PayflowProVaultPaymentValueHandlerPool + Magento\Paypal\Model\Payflow\Transparent + Magento\Paypal\Model\Payflow\Transparent::CC_VAULT_CODE + + payflowlinkConfigFactory diff --git a/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_create_index.xml b/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_create_index.xml index 37eded79dc02b..c858a29e9a1de 100644 --- a/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_create_index.xml +++ b/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_create_index.xml @@ -13,5 +13,11 @@ Magento_Paypal::transparent/form.phtml + + + payflowpro_cc_vault + Magento_Vault::form/vault.phtml + + \ No newline at end of file diff --git a/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_create_load_block_billing_method.xml b/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_create_load_block_billing_method.xml index f6d8643aa35e8..ffd0d656ba550 100644 --- a/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_create_load_block_billing_method.xml +++ b/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_create_load_block_billing_method.xml @@ -13,5 +13,11 @@ Magento_Paypal::transparent/form.phtml + + + payflowpro_cc_vault + Magento_Vault::form/vault.phtml + + \ No newline at end of file diff --git a/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/payflowpro-method.js b/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/payflowpro-method.js index cbb0a8085dad2..f8f19818c3fc2 100644 --- a/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/payflowpro-method.js +++ b/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/payflowpro-method.js @@ -12,7 +12,7 @@ define( 'Magento_Checkout/js/model/full-screen-loader', 'Magento_Vault/js/view/payment/vault-enabler' ], - function ($, Component, additionalValidators, setPaymentInformationAction, fullScreenLoader, vaultEnabler) { + function ($, Component, additionalValidators, setPaymentInformationAction, fullScreenLoader, VaultEnabler) { 'use strict'; return Component.extend({ @@ -27,8 +27,8 @@ define( */ initialize: function () { this._super(); - this.vaultEnabler = vaultEnabler(); - this.vaultEnabler.setPaymentCode(this.getCode()); + this.vaultEnabler = new VaultEnabler(); + this.vaultEnabler.setPaymentCode(this.getVaultCode()); return this; }, @@ -127,6 +127,13 @@ define( */ isVaultEnabled: function () { return this.vaultEnabler.isVaultEnabled(); + }, + + /** + * @returns {String} + */ + getVaultCode: function () { + return 'payflowpro_cc_vault'; } }); } diff --git a/app/code/Magento/Vault/Block/Form.php b/app/code/Magento/Vault/Block/Form.php index 7dcb4bf76d13d..fbf62a7d8f7a6 100644 --- a/app/code/Magento/Vault/Block/Form.php +++ b/app/code/Magento/Vault/Block/Form.php @@ -59,13 +59,13 @@ protected function _prepareLayout() protected function createVaultBlocks() { $icons = $this->cardConfigProvider->getIcons(); - $payments = $this->tokensProvider->getTokensComponents(); + $payments = $this->tokensProvider->getTokensComponents($this->_nameInLayout); foreach ($payments as $key => $payment) { $this->addChild( $key, $payment->getName(), array_merge( - ['id' => $key, 'icons' => $icons], + ['id' => $this->_nameInLayout . $key, 'icons' => $icons], $payment->getConfig() ) ); diff --git a/app/code/Magento/Vault/Block/System/Config/EmptyFieldsetDecorator.php b/app/code/Magento/Vault/Block/System/Config/EmptyFieldsetDecorator.php deleted file mode 100644 index a1a9590d2dfec..0000000000000 --- a/app/code/Magento/Vault/Block/System/Config/EmptyFieldsetDecorator.php +++ /dev/null @@ -1,26 +0,0 @@ -_getChildrenElementsHtml($element); - if (empty($childrenHtml)) { - return ''; - } - - return parent::render($element); - } -} diff --git a/app/code/Magento/Vault/Block/System/Config/EmptySelectDecorator.php b/app/code/Magento/Vault/Block/System/Config/EmptySelectDecorator.php deleted file mode 100644 index 302e1fc849ade..0000000000000 --- a/app/code/Magento/Vault/Block/System/Config/EmptySelectDecorator.php +++ /dev/null @@ -1,29 +0,0 @@ -getData('values'))) { - return ''; - } - - return parent::render($element); - } -} diff --git a/app/code/Magento/Vault/Controller/Cards/DeleteAction.php b/app/code/Magento/Vault/Controller/Cards/DeleteAction.php index 56832d0054396..d1d12e541a09d 100644 --- a/app/code/Magento/Vault/Controller/Cards/DeleteAction.php +++ b/app/code/Magento/Vault/Controller/Cards/DeleteAction.php @@ -14,9 +14,9 @@ use Magento\Framework\Data\Form\FormKey\Validator; use Magento\Framework\Exception\NotFoundException; use Magento\Vault\Api\Data\PaymentTokenInterface; +use Magento\Vault\Api\PaymentTokenRepositoryInterface; use Magento\Vault\Controller\CardsManagement; use Magento\Vault\Model\PaymentTokenManagement; -use Magento\Vault\Model\PaymentTokenRepositoryProxy; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -45,7 +45,7 @@ class DeleteAction extends CardsManagement private $fkValidator; /** - * @var PaymentTokenRepositoryProxy + * @var PaymentTokenRepositoryInterface */ private $tokenRepository; @@ -59,7 +59,7 @@ class DeleteAction extends CardsManagement * @param Session $customerSession * @param JsonFactory $jsonFactory * @param Validator $fkValidator - * @param PaymentTokenRepositoryProxy $tokenRepository + * @param PaymentTokenRepositoryInterface $tokenRepository * @param PaymentTokenManagement $paymentTokenManagement */ public function __construct( @@ -67,7 +67,7 @@ public function __construct( Session $customerSession, JsonFactory $jsonFactory, Validator $fkValidator, - PaymentTokenRepositoryProxy $tokenRepository, + PaymentTokenRepositoryInterface $tokenRepository, PaymentTokenManagement $paymentTokenManagement ) { parent::__construct($context, $customerSession); diff --git a/app/code/Magento/Vault/Gateway/Config/ActiveHandler.php b/app/code/Magento/Vault/Gateway/Config/ActiveHandler.php deleted file mode 100644 index e063aa9fd24e5..0000000000000 --- a/app/code/Magento/Vault/Gateway/Config/ActiveHandler.php +++ /dev/null @@ -1,41 +0,0 @@ -config = $config; - } - - /** - * @inheritdoc - */ - public function handle(array $subject, $storeId = null) - { - $vaultPaymentCode = $this->config->getValue(VaultProvidersMap::VALUE_CODE, $storeId); - - return (int) ((int)$this->config->getValue('active', $storeId) === 1 - && $vaultPaymentCode - && $vaultPaymentCode !== VaultProvidersMap::EMPTY_VALUE); - } -} diff --git a/app/code/Magento/Vault/Model/Adminhtml/Source/VaultProvidersMap.php b/app/code/Magento/Vault/Model/Adminhtml/Source/VaultProvidersMap.php deleted file mode 100644 index 2d2ab8eafd2e7..0000000000000 --- a/app/code/Magento/Vault/Model/Adminhtml/Source/VaultProvidersMap.php +++ /dev/null @@ -1,64 +0,0 @@ - $paymentMethod->getCode(), - 'label' => __($paymentMethod->getCode()) - ]; - }, - $options - ); - - if (!empty($configuredMethods)) { - $this->options = array_merge( - [ - [ - 'value' => self::EMPTY_VALUE, - 'label' => __('Select vault provider') - ] - ], - $configuredMethods - ); - } - } - - /** - * Return array of options as value-label pairs - * - * @return array Format: array(array('value' => '', 'label' => ' - - - - Magento\Vault\Model\VaultPaymentInterface::CODE - - - - VaultPaymentConfig + Magento\Payment\Gateway\Config\Config VaultPaymentValueHandlerPool Magento\Vault\Model\Method\NullPaymentProvider - - - - - - Magento\Vault\Model\PaymentTokenRepository - VaultPaymentConfig - + vault - VaultPaymentConfig + Magento\Payment\Gateway\Config\Config - - - VaultPaymentConfig - - VaultPaymentDefaultValueHandler - Magento\Vault\Gateway\Config\ActiveHandler diff --git a/app/code/Magento/Vault/view/frontend/web/js/view/payment/method-renderer/vault.js b/app/code/Magento/Vault/view/frontend/web/js/view/payment/method-renderer/vault.js index 35b48d9cf011d..a225997a74f98 100644 --- a/app/code/Magento/Vault/view/frontend/web/js/view/payment/method-renderer/vault.js +++ b/app/code/Magento/Vault/view/frontend/web/js/view/payment/method-renderer/vault.js @@ -67,7 +67,7 @@ define( * @returns {String} */ getCode: function () { - return 'vault'; + return this.code; }, /** diff --git a/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault-enabler.js b/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault-enabler.js index f928e14fdb539..9ffdb519292a4 100644 --- a/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault-enabler.js +++ b/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault-enabler.js @@ -56,8 +56,8 @@ define( * @returns {Boolean} */ isVaultEnabled: function () { - return window.checkoutConfig.vault['is_enabled'] === true && - window.checkoutConfig.vault['vault_provider_code'] === this.paymentCode; + return typeof window.checkoutConfig.vault[this.paymentCode] !== 'undefined' && + window.checkoutConfig.vault[this.paymentCode]['is_enabled'] === true; } }); } From e8b29c754740be7b4f45d8149aab57691936e1dc Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Fri, 3 Jun 2016 11:44:28 +0300 Subject: [PATCH 02/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Fixed failed unit tests --- .../Braintree/Test/Unit/Block/FormTest.php | 7 +- .../Vault/Model/Ui/TokensConfigProvider.php | 8 - .../Model/CustomerTokenManagementTest.php | 90 ++-------- .../Unit/Model/PaymentTokenManagementTest.php | 166 +++++++++--------- .../Ui/Adminhtml/TokensConfigProviderTest.php | 98 +++++++---- .../Model/Ui/TokensConfigProviderTest.php | 75 +++++--- .../Unit/Model/Ui/VaultConfigProviderTest.php | 113 ++++++++---- .../Integrity/Magento/Payment/MethodsTest.php | 3 - 8 files changed, 300 insertions(+), 260 deletions(-) diff --git a/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php b/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php index 5a598c730d7ec..f056ba0cefd36 100644 --- a/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php +++ b/app/code/Magento/Braintree/Test/Unit/Block/FormTest.php @@ -11,14 +11,13 @@ use Magento\Braintree\Model\Adminhtml\Source\CcType; use Magento\Braintree\Model\Ui\ConfigProvider; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Payment\Helper\Data; use Magento\Payment\Model\Config; -use Magento\Vault\Model\Ui\VaultConfigProvider; +use Magento\Store\Api\Data\StoreInterface; +use Magento\Store\Model\StoreManagerInterface; use Magento\Vault\Model\VaultPaymentInterface; use OAuthTest\Mocks\Common\Service\Mock; use PHPUnit_Framework_MockObject_MockObject as MockObject; -use Magento\Store\Model\StoreManagerInterface; -use Magento\Store\Api\Data\StoreInterface; -use Magento\Payment\Helper\Data; /** * Class FormTest diff --git a/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php b/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php index 8868c6d027b03..434a5875b5bb1 100644 --- a/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php +++ b/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php @@ -23,11 +23,6 @@ final class TokensConfigProvider implements ConfigProviderInterface */ private static $vaultCode = 'vault'; - /** - * @var VaultPaymentInterface - */ - private $vaultPayment; - /** * @var StoreManagerInterface */ @@ -52,17 +47,14 @@ final class TokensConfigProvider implements ConfigProviderInterface * Constructor * * @param StoreManagerInterface $storeManager - * @param VaultPaymentInterface $vaultPayment * @param CustomerTokenManagement $customerTokenManagement * @param TokenUiComponentProviderInterface[] $tokenUiComponentProviders */ public function __construct( StoreManagerInterface $storeManager, - VaultPaymentInterface $vaultPayment, CustomerTokenManagement $customerTokenManagement, array $tokenUiComponentProviders = [] ) { - $this->vaultPayment = $vaultPayment; $this->storeManager = $storeManager; $this->tokenUiComponentProviders = $tokenUiComponentProviders; $this->customerTokenManagement = $customerTokenManagement; diff --git a/app/code/Magento/Vault/Test/Unit/Model/CustomerTokenManagementTest.php b/app/code/Magento/Vault/Test/Unit/Model/CustomerTokenManagementTest.php index 4c3727b6a6ccf..b97355845b744 100644 --- a/app/code/Magento/Vault/Test/Unit/Model/CustomerTokenManagementTest.php +++ b/app/code/Magento/Vault/Test/Unit/Model/CustomerTokenManagementTest.php @@ -6,39 +6,22 @@ namespace Magento\Vault\Test\Unit\Model; use Magento\Customer\Model\Session; -use Magento\Store\Api\Data\StoreInterface; -use Magento\Store\Model\StoreManagerInterface; use Magento\Vault\Api\Data\PaymentTokenInterface; use Magento\Vault\Model\CustomerTokenManagement; use Magento\Vault\Model\PaymentTokenManagement; -use Magento\Vault\Model\VaultPaymentInterface; +use PHPUnit_Framework_MockObject_MockObject as MockObject; class CustomerTokenManagementTest extends \PHPUnit_Framework_TestCase { /** - * @var PaymentTokenManagement|\PHPUnit_Framework_MockObject_MockObject + * @var PaymentTokenManagement|MockObject */ - private $paymentTokenManagementMock; + private $paymentTokenManagement; /** - * @var Session|\PHPUnit_Framework_MockObject_MockObject + * @var Session|MockObject */ - private $customerSessionMock; - - /** - * @var VaultPaymentInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $vaultPayment; - - /** - * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $storeManager; - - /** - * @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $store; + private $customerSession; /** * @var CustomerTokenManagement @@ -47,57 +30,38 @@ class CustomerTokenManagementTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->paymentTokenManagementMock = $this->getMockBuilder(PaymentTokenManagement::class) + $this->paymentTokenManagement = $this->getMockBuilder(PaymentTokenManagement::class) ->disableOriginalConstructor() ->getMock(); - $this->customerSessionMock = $this->getMockBuilder(Session::class) + $this->customerSession = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() ->getMock(); - $this->vaultPayment = $this->getMock(VaultPaymentInterface::class); - $this->storeManager = $this->getMock(StoreManagerInterface::class); - $this->store = $this->getMock(StoreInterface::class); $this->tokenManagement = new CustomerTokenManagement( - $this->vaultPayment, - $this->paymentTokenManagementMock, - $this->customerSessionMock, - $this->storeManager + $this->paymentTokenManagement, + $this->customerSession ); } public function testGetCustomerSessionTokensNonRegisteredCustomer() { - $this->customerSessionMock->expects(self::once()) + $this->customerSession->expects(self::once()) ->method('getCustomerId') ->willReturn(null); - $this->paymentTokenManagementMock->expects(static::never()) + $this->paymentTokenManagement->expects(static::never()) ->method('getVisibleAvailableTokens'); $this->tokenManagement->getCustomerSessionTokens(); } - public function testGetCustomerSessionTokensNoActiveVaultProvider() + public function testGetCustomerSessionTokensForNotExistsCustomer() { - $customerId = 1; - $storeId = 1; - $this->customerSessionMock->expects(self::once()) + $this->customerSession->expects(static::once()) ->method('getCustomerId') - ->willReturn($customerId); + ->willReturn(null); - $this->storeManager->expects(static::once()) - ->method('getStore') - ->with(null) - ->willReturn($this->store); - $this->store->expects(static::once()) - ->method('getId') - ->willReturn($storeId); - $this->vaultPayment->expects(static::once()) - ->method('isActive') - ->with($storeId) - ->willReturn(false); - - $this->paymentTokenManagementMock->expects(static::never()) + $this->paymentTokenManagement->expects(static::never()) ->method('getVisibleAvailableTokens'); $this->tokenManagement->getCustomerSessionTokens(); @@ -106,34 +70,16 @@ public function testGetCustomerSessionTokensNoActiveVaultProvider() public function testGetCustomerSessionTokens() { $customerId = 1; - $providerCode = 'vault_provider'; - $storeId = 1; $token = $this->getMock(PaymentTokenInterface::class); $expectation = [$token]; - $this->customerSessionMock->expects(self::once()) + $this->customerSession->expects(static::once()) ->method('getCustomerId') ->willReturn($customerId); - $this->storeManager->expects(static::once()) - ->method('getStore') - ->with(null) - ->willReturn($this->store); - $this->store->expects(static::once()) - ->method('getId') - ->willReturn($storeId); - $this->vaultPayment->expects(static::once()) - ->method('isActive') - ->with($storeId) - ->willReturn(true); - $this->vaultPayment->expects(static::once()) - ->method('getProviderCode') - ->with($storeId) - ->willReturn($providerCode); - - $this->paymentTokenManagementMock->expects(static::once()) + $this->paymentTokenManagement->expects(static::once()) ->method('getVisibleAvailableTokens') - ->with($customerId, $providerCode) + ->with($customerId) ->willReturn($expectation); static::assertEquals( diff --git a/app/code/Magento/Vault/Test/Unit/Model/PaymentTokenManagementTest.php b/app/code/Magento/Vault/Test/Unit/Model/PaymentTokenManagementTest.php index ad6af8e4a1191..8c8486407b04d 100644 --- a/app/code/Magento/Vault/Test/Unit/Model/PaymentTokenManagementTest.php +++ b/app/code/Magento/Vault/Test/Unit/Model/PaymentTokenManagementTest.php @@ -6,22 +6,22 @@ namespace Magento\Vault\Test\Unit\Model; use Magento\Framework\Api\Filter; +use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\Api\SearchCriteria; +use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Encryption\EncryptorInterface; use Magento\Framework\Intl\DateTimeFactory; +use Magento\Framework\TestFramework\Unit\Matcher\MethodInvokedAtIndex; use Magento\Sales\Api\Data\OrderPaymentInterface; use Magento\Sales\Model\Order\Payment; -use Magento\Framework\Api\FilterBuilder; -use Magento\Framework\Api\SearchCriteria; -use Magento\Vault\Model\PaymentTokenFactory; -use Magento\Vault\Model\PaymentTokenManagement; -use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Vault\Api\Data\PaymentTokenInterface; -use Magento\Vault\Model\ResourceModel\PaymentToken; -use Magento\Vault\Api\PaymentTokenRepositoryInterface; use Magento\Vault\Api\Data\PaymentTokenSearchResultsInterface; use Magento\Vault\Api\Data\PaymentTokenSearchResultsInterfaceFactory; +use Magento\Vault\Api\PaymentTokenRepositoryInterface; +use Magento\Vault\Model\PaymentTokenFactory; +use Magento\Vault\Model\PaymentTokenManagement; +use Magento\Vault\Model\ResourceModel\PaymentToken; use Magento\Vault\Model\ResourceModel\PaymentToken as PaymentTokenResourceModel; -use Magento\Framework\TestFramework\Unit\Matcher\MethodInvokedAtIndex; /** * Class PaymentTokenManagementTest @@ -39,42 +39,42 @@ class PaymentTokenManagementTest extends \PHPUnit_Framework_TestCase /** * @var PaymentTokenRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $paymentTokenRepositoryMock; + private $paymentTokenRepository; /** * @var PaymentTokenResourceModel|\PHPUnit_Framework_MockObject_MockObject */ - protected $paymentTokenResourceModelMock; + private $paymentTokenResourceModel; /** * @var PaymentTokenResourceModel|\PHPUnit_Framework_MockObject_MockObject */ - protected $resourceModelMock; + private $resourceModel; /** * @var PaymentTokenFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $paymentTokenFactoryMock; + private $paymentTokenFactory; /** * @var PaymentTokenSearchResultsInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $searchResultsFactoryMock; + private $searchResultsFactory; /** * @var FilterBuilder|\PHPUnit_Framework_MockObject_MockObject */ - protected $filterBuilderMock; + private $filterBuilder; /** * @var SearchCriteriaBuilder|\PHPUnit_Framework_MockObject_MockObject */ - protected $searchCriteriaBuilderMock; + private $searchCriteriaBuilder; /** * @var EncryptorInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $encryptorMock; + private $encryptor; /** * @var DateTimeFactory|\PHPUnit_Framework_MockObject_MockObject @@ -86,41 +86,41 @@ class PaymentTokenManagementTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->paymentTokenRepositoryMock = $this->getMockBuilder(PaymentTokenRepositoryInterface::class) + $this->paymentTokenRepository = $this->getMockBuilder(PaymentTokenRepositoryInterface::class) ->getMockForAbstractClass(); - $this->paymentTokenResourceModelMock = $this->getMockBuilder(PaymentTokenResourceModel::class) + $this->paymentTokenResourceModel = $this->getMockBuilder(PaymentTokenResourceModel::class) ->disableOriginalConstructor() ->getMock(); - $this->resourceModelMock = $this->getMockBuilder(PaymentTokenResourceModel::class) + $this->resourceModel = $this->getMockBuilder(PaymentTokenResourceModel::class) ->disableOriginalConstructor() ->getMock(); - $this->paymentTokenFactoryMock = $this->getMockBuilder(PaymentTokenFactory::class) + $this->paymentTokenFactory = $this->getMockBuilder(PaymentTokenFactory::class) ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); - $this->searchResultsFactoryMock = $this->getMockBuilder(PaymentTokenSearchResultsInterfaceFactory::class) + $this->searchResultsFactory = $this->getMockBuilder(PaymentTokenSearchResultsInterfaceFactory::class) ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); - $this->filterBuilderMock = $this->getMockBuilder(FilterBuilder::class) + $this->filterBuilder = $this->getMockBuilder(FilterBuilder::class) ->disableOriginalConstructor() ->getMock(); - $this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class) + $this->searchCriteriaBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class) ->disableOriginalConstructor() ->getMock(); - $this->encryptorMock = $this->getMock(EncryptorInterface::class); + $this->encryptor = $this->getMock(EncryptorInterface::class); $this->dateTimeFactory = $this->getMockBuilder(DateTimeFactory::class) ->disableOriginalConstructor() ->getMock(); $this->paymentTokenManagement = new PaymentTokenManagement( - $this->paymentTokenRepositoryMock, - $this->paymentTokenResourceModelMock, - $this->paymentTokenFactoryMock, - $this->filterBuilderMock, - $this->searchCriteriaBuilderMock, - $this->searchResultsFactoryMock, - $this->encryptorMock, + $this->paymentTokenRepository, + $this->paymentTokenResourceModel, + $this->paymentTokenFactory, + $this->filterBuilder, + $this->searchCriteriaBuilder, + $this->searchResultsFactory, + $this->encryptor, $this->dateTimeFactory ); } @@ -143,27 +143,27 @@ public function testGetListByCustomerId() $searchResult = $this->getMockBuilder(PaymentTokenSearchResultsInterface::class) ->getMockForAbstractClass(); - $this->filterBuilderMock->expects(self::once()) + $this->filterBuilder->expects(self::once()) ->method('setField') ->with(PaymentTokenInterface::CUSTOMER_ID) ->willReturnSelf(); - $this->filterBuilderMock->expects(self::once()) + $this->filterBuilder->expects(self::once()) ->method('setValue') ->with(1) ->willReturnSelf(); - $this->filterBuilderMock->expects(self::once()) + $this->filterBuilder->expects(self::once()) ->method('create') ->willReturn($filterMock); - $this->searchCriteriaBuilderMock->expects(self::once()) + $this->searchCriteriaBuilder->expects(self::once()) ->method('addFilters') ->with([$filterMock]) ->willReturnSelf(); - $this->searchCriteriaBuilderMock->expects(self::once()) + $this->searchCriteriaBuilder->expects(self::once()) ->method('create') ->willReturn($searchCriteria); - $this->paymentTokenRepositoryMock->expects(self::once()) + $this->paymentTokenRepository->expects(self::once()) ->method('getList') ->with($searchCriteria) ->willReturn($searchResult); @@ -184,12 +184,12 @@ public function testGetByPaymentId() $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class) ->getMockForAbstractClass(); - $this->paymentTokenResourceModelMock->expects(self::once()) + $this->paymentTokenResourceModel->expects(self::once()) ->method('getByOrderPaymentId') ->with(1) ->willReturn(['token-data']); - $this->paymentTokenFactoryMock->expects(self::once()) + $this->paymentTokenFactory->expects(self::once()) ->method('create') ->with(['data' => ['token-data']]) ->willReturn($tokenMock); @@ -202,12 +202,12 @@ public function testGetByPaymentId() */ public function testGetByPaymentIdNull() { - $this->paymentTokenResourceModelMock->expects(self::once()) + $this->paymentTokenResourceModel->expects(self::once()) ->method('getByOrderPaymentId') ->with(1) ->willReturn([]); - $this->paymentTokenFactoryMock->expects(self::never()) + $this->paymentTokenFactory->expects(self::never()) ->method('create'); self::assertEquals(null, $this->paymentTokenManagement->getByPaymentId(1)); @@ -222,12 +222,12 @@ public function testGetByGatewayToken() $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class) ->getMockForAbstractClass(); - $this->paymentTokenResourceModelMock->expects(self::once()) + $this->paymentTokenResourceModel->expects(self::once()) ->method('getByGatewayToken') ->with('token', 1, 1) ->willReturn(['token-data']); - $this->paymentTokenFactoryMock->expects(self::once()) + $this->paymentTokenFactory->expects(self::once()) ->method('create') ->with(['data' => ['token-data']]) ->willReturn($tokenMock); @@ -240,12 +240,12 @@ public function testGetByGatewayToken() */ public function testGetByGatewayTokenNull() { - $this->paymentTokenResourceModelMock->expects(self::once()) + $this->paymentTokenResourceModel->expects(self::once()) ->method('getByGatewayToken') ->with('some-not-exists-token', 1, 1) ->willReturn([]); - $this->paymentTokenFactoryMock->expects(self::never()) + $this->paymentTokenFactory->expects(self::never()) ->method('create'); self::assertEquals(null, $this->paymentTokenManagement->getByGatewayToken('some-not-exists-token', 1, 1)); @@ -256,12 +256,12 @@ public function testGetByGatewayTokenNull() */ public function testGetByPublicHash() { - $this->paymentTokenResourceModelMock->expects(self::once()) + $this->paymentTokenResourceModel->expects(self::once()) ->method('getByPublicHash') ->with('some-not-exists-token', 1) ->willReturn([]); - $this->paymentTokenFactoryMock->expects(self::never()) + $this->paymentTokenFactory->expects(self::never()) ->method('create'); self::assertEquals(null, $this->paymentTokenManagement->getByPublicHash('some-not-exists-token', 1)); @@ -289,18 +289,18 @@ public function testSaveTokenWithPaymentLinkNoDuplicate() ->method('getCustomerId') ->willReturn($customerId); - $this->paymentTokenResourceModelMock->expects(self::once()) + $this->paymentTokenResourceModel->expects(self::once()) ->method('getByPublicHash') ->with($publicHash, 1) ->willReturn([]); - $this->paymentTokenFactoryMock->expects(self::never()) + $this->paymentTokenFactory->expects(self::never()) ->method('create'); $tokenMock->expects(self::once()) ->method('getEntityId') ->willReturn($entityId); - $this->paymentTokenRepositoryMock->expects(self::once()) + $this->paymentTokenRepository->expects(self::once()) ->method('save') ->with($tokenMock); @@ -308,7 +308,7 @@ public function testSaveTokenWithPaymentLinkNoDuplicate() ->method('getEntityId') ->willReturn($paymentId); - $this->paymentTokenResourceModelMock->expects(static::once()) + $this->paymentTokenResourceModel->expects(static::once()) ->method('addLinkToOrderPayment') ->with($entityId, $paymentId); @@ -342,12 +342,12 @@ public function testSaveTokenWithPaymentLinkWithDuplicateTokenVisible() ->method('getCustomerId') ->willReturn($customerId); - $this->paymentTokenResourceModelMock->expects(self::once()) + $this->paymentTokenResourceModel->expects(self::once()) ->method('getByPublicHash') ->with($publicHash, $customerId) ->willReturn($duplicateTokenData); - $this->paymentTokenFactoryMock->expects(self::once()) + $this->paymentTokenFactory->expects(self::once()) ->method('create') ->with(['data' => $duplicateTokenData]) ->willReturn($duplicateToken); @@ -360,7 +360,7 @@ public function testSaveTokenWithPaymentLinkWithDuplicateTokenVisible() $tokenMock->expects(self::once()) ->method('getEntityId') ->willReturn($entityId); - $this->paymentTokenRepositoryMock->expects(self::once()) + $this->paymentTokenRepository->expects(self::once()) ->method('save') ->with($tokenMock); @@ -368,7 +368,7 @@ public function testSaveTokenWithPaymentLinkWithDuplicateTokenVisible() ->method('getEntityId') ->willReturn($paymentId); - $this->paymentTokenResourceModelMock->expects(static::once()) + $this->paymentTokenResourceModel->expects(static::once()) ->method('addLinkToOrderPayment') ->with($entityId, $paymentId); @@ -405,12 +405,12 @@ public function testSaveTokenWithPaymentLinkWithDuplicateTokenNotVisible() ->method('getCustomerId') ->willReturn($customerId); - $this->paymentTokenResourceModelMock->expects(self::once()) + $this->paymentTokenResourceModel->expects(self::once()) ->method('getByPublicHash') ->with($publicHash, $customerId) ->willReturn($duplicateTokenData); - $this->paymentTokenFactoryMock->expects(self::once()) + $this->paymentTokenFactory->expects(self::once()) ->method('create') ->with(['data' => $duplicateTokenData]) ->willReturn($duplicateToken); @@ -424,7 +424,7 @@ public function testSaveTokenWithPaymentLinkWithDuplicateTokenNotVisible() ->method('getGatewayToken') ->willReturn($gatewayToken); - $this->encryptorMock->expects(static::once()) + $this->encryptor->expects(static::once()) ->method('getHash') ->with($publicHash . $gatewayToken) ->willReturn($newHash); @@ -432,7 +432,7 @@ public function testSaveTokenWithPaymentLinkWithDuplicateTokenNotVisible() ->method('setPublicHash') ->with($newHash); - $this->paymentTokenRepositoryMock->expects(self::once()) + $this->paymentTokenRepository->expects(self::once()) ->method('save') ->with($tokenMock); $tokenMock->expects(static::atLeastOnce()) @@ -442,7 +442,7 @@ public function testSaveTokenWithPaymentLinkWithDuplicateTokenNotVisible() $paymentMock->expects(self::atLeastOnce()) ->method('getEntityId') ->willReturn($paymentId); - $this->paymentTokenResourceModelMock->expects(static::once()) + $this->paymentTokenResourceModel->expects(static::once()) ->method('addLinkToOrderPayment') ->with($newEntityId, $paymentId); @@ -452,32 +452,24 @@ public function testSaveTokenWithPaymentLinkWithDuplicateTokenNotVisible() public function testGetVisibleAvailableTokens() { $customerId = 1; - $vaultProviderCode = 'vault_provider_code'; - $searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class) + $searchCriteria = $this->getMockBuilder(SearchCriteria::class) ->disableOriginalConstructor() ->getMock(); - $searchResultMock = $this->getMockBuilder(PaymentTokenSearchResultsInterface::class) - ->getMockForAbstractClass(); - $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class) - ->getMockForAbstractClass(); + $searchResult = $this->getMockForAbstractClass(PaymentTokenSearchResultsInterface::class); + $token = $this->getMockForAbstractClass(PaymentTokenInterface::class); $customerFilter = $this->createExpectedFilter(PaymentTokenInterface::CUSTOMER_ID, $customerId, 0); $visibilityFilter = $this->createExpectedFilter(PaymentTokenInterface::IS_VISIBLE, true, 1); $isActiveFilter = $this->createExpectedFilter(PaymentTokenInterface::IS_ACTIVE, true, 2); - $providerFilter = $this->createExpectedFilter( - PaymentTokenInterface::PAYMENT_METHOD_CODE, - $vaultProviderCode, - 3 - ); // express at expectations $expiresAtFilter = $this->createExpectedFilter( PaymentTokenInterface::EXPIRES_AT, '2015-01-01 00:00:00', - 4 + 3 ); - $this->filterBuilderMock->expects(static::once()) + $this->filterBuilder->expects(static::once()) ->method('setConditionType') ->with('gt') ->willReturnSelf(); @@ -494,27 +486,27 @@ public function testGetVisibleAvailableTokens() ->with('Y-m-d 00:00:00') ->willReturn('2015-01-01 00:00:00'); - $this->searchCriteriaBuilderMock->expects(self::once()) + $this->searchCriteriaBuilder->expects(self::once()) ->method('addFilters') - ->with([$customerFilter, $visibilityFilter, $providerFilter, $isActiveFilter, $expiresAtFilter]) + ->with([$customerFilter, $visibilityFilter, $isActiveFilter, $expiresAtFilter]) ->willReturnSelf(); - $this->searchCriteriaBuilderMock->expects(self::once()) + $this->searchCriteriaBuilder->expects(self::once()) ->method('create') - ->willReturn($searchCriteriaMock); + ->willReturn($searchCriteria); - $this->paymentTokenRepositoryMock->expects(self::once()) + $this->paymentTokenRepository->expects(self::once()) ->method('getList') - ->with($searchCriteriaMock) - ->willReturn($searchResultMock); + ->with($searchCriteria) + ->willReturn($searchResult); - $searchResultMock->expects(self::once()) + $searchResult->expects(self::once()) ->method('getItems') - ->willReturn([$tokenMock]); + ->willReturn([$token]); static::assertEquals( - [$tokenMock], - $this->paymentTokenManagement->getVisibleAvailableTokens($customerId, $vaultProviderCode) + [$token], + $this->paymentTokenManagement->getVisibleAvailableTokens($customerId) ); } @@ -531,15 +523,15 @@ private function createExpectedFilter($field, $value, $atIndex) $filterObject = $this->getMockBuilder(Filter::class) ->disableOriginalConstructor() ->getMock(); - $this->filterBuilderMock->expects(new MethodInvokedAtIndex($atIndex)) + $this->filterBuilder->expects(new MethodInvokedAtIndex($atIndex)) ->method('setField') ->with($field) ->willReturnSelf(); - $this->filterBuilderMock->expects(new MethodInvokedAtIndex($atIndex)) + $this->filterBuilder->expects(new MethodInvokedAtIndex($atIndex)) ->method('setValue') ->with($value) ->willReturnSelf(); - $this->filterBuilderMock->expects(new MethodInvokedAtIndex($atIndex)) + $this->filterBuilder->expects(new MethodInvokedAtIndex($atIndex)) ->method('create') ->willReturn($filterObject); diff --git a/app/code/Magento/Vault/Test/Unit/Model/Ui/Adminhtml/TokensConfigProviderTest.php b/app/code/Magento/Vault/Test/Unit/Model/Ui/Adminhtml/TokensConfigProviderTest.php index e9e06b592807f..e54f9cc9c979b 100644 --- a/app/code/Magento/Vault/Test/Unit/Model/Ui/Adminhtml/TokensConfigProviderTest.php +++ b/app/code/Magento/Vault/Test/Unit/Model/Ui/Adminhtml/TokensConfigProviderTest.php @@ -12,6 +12,7 @@ use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Intl\DateTimeFactory; use Magento\Framework\TestFramework\Unit\Matcher\MethodInvokedAtIndex; +use Magento\Payment\Helper\Data; use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Vault\Api\Data\PaymentTokenInterface; @@ -21,6 +22,8 @@ use Magento\Vault\Model\Ui\TokenUiComponentInterface; use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface; use Magento\Vault\Model\VaultPaymentInterface; +use PHPUnit_Framework_MockObject_MockObject as MockObject; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; /** * Class TokensConfigProviderTest @@ -30,44 +33,54 @@ class TokensConfigProviderTest extends \PHPUnit_Framework_TestCase { /** - * @var PaymentTokenRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + * @var PaymentTokenRepositoryInterface|MockObject */ private $paymentTokenRepository; /** - * @var FilterBuilder|\PHPUnit_Framework_MockObject_MockObject + * @var FilterBuilder|MockObject */ private $filterBuilder; /** - * @var SearchCriteriaBuilder|\PHPUnit_Framework_MockObject_MockObject + * @var SearchCriteriaBuilder|MockObject */ private $searchCriteriaBuilder; /** - * @var Quote|\PHPUnit_Framework_MockObject_MockObject + * @var Quote|MockObject */ private $session; /** - * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var StoreManagerInterface|MockObject */ private $storeManager; /** - * @var VaultPaymentInterface|\PHPUnit_Framework_MockObject_MockObject + * @var StoreInterface|MockObject */ - private $vaultPayment; + private $store; /** - * @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject + * @var DateTimeFactory|MockObject */ - private $store; + private $dateTimeFactory; /** - * @var DateTimeFactory|\PHPUnit_Framework_MockObject_MockObject + * @var Data|MockObject */ - private $dateTimeFactory; + private $paymentDataHelper; + + /** + * @var VaultPaymentInterface|MockObject + */ + private $vaultPayment; + + /** + * @var ObjectManager + */ + private $objectManager; protected function setUp() { @@ -86,7 +99,14 @@ protected function setUp() $this->dateTimeFactory = $this->getMockBuilder(DateTimeFactory::class) ->disableOriginalConstructor() ->getMock(); - $this->vaultPayment = $this->getMock(VaultPaymentInterface::class); + $this->paymentDataHelper = $this->getMockBuilder(Data::class) + ->disableOriginalConstructor() + ->setMethods(['getMethodInstance']) + ->getMock(); + + $this->vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class); + + $this->objectManager = new ObjectManager($this); } /** @@ -96,29 +116,35 @@ public function testGetTokensComponents() { $storeId = 1; $customerId = 2; - $paymentCode = 'vault_payment'; + $vaultPaymentCode = 'vault_payment'; + $vaultProviderCode = 'payment'; $this->initStoreMock(); - $this->session->expects(self::once()) + $this->session->expects(static::once()) ->method('getCustomerId') ->willReturn($customerId); + $this->paymentDataHelper->expects(static::once()) + ->method('getMethodInstance') + ->with($vaultPaymentCode) + ->willReturn($this->vaultPayment); + $this->vaultPayment->expects(static::once()) ->method('isActive') ->with($storeId) ->willReturn(true); - $this->vaultPayment->expects(static::once()) ->method('getProviderCode') - ->willReturn($paymentCode); + ->willReturn($vaultProviderCode); + /** @var PaymentTokenInterface|MockObject $token */ $token = $this->getMockBuilder(PaymentTokenInterface::class) ->getMockForAbstractClass(); list($tokenUiComponent, $tokenUiComponentProvider) = $this->getTokenUiComponentProvider($token); - $searchCriteria = $this->getSearchCriteria($customerId, $paymentCode); + $searchCriteria = $this->getSearchCriteria($customerId, $vaultProviderCode); $date = $this->getMockBuilder('DateTime') ->disableOriginalConstructor() @@ -149,14 +175,19 @@ public function testGetTokensComponents() $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, - $this->vaultPayment, $this->dateTimeFactory, [ - $paymentCode => $tokenUiComponentProvider + $vaultProviderCode => $tokenUiComponentProvider ] ); + + $this->objectManager->setBackwardCompatibleProperty( + $configProvider, + 'paymentDataHelper', + $this->paymentDataHelper + ); - static::assertEquals([$tokenUiComponent], $configProvider->getTokensComponents()); + static::assertEquals([$tokenUiComponent], $configProvider->getTokensComponents($vaultPaymentCode)); } /** @@ -164,6 +195,7 @@ public function testGetTokensComponents() */ public function testGetTokensComponentsNotExistsCustomer() { + $vaultPaymentCode = 'vault_payment'; $this->store = $this->getMock(StoreInterface::class); $this->storeManager = $this->getMock(StoreManagerInterface::class); @@ -180,11 +212,10 @@ public function testGetTokensComponentsNotExistsCustomer() $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, - $this->vaultPayment, $this->dateTimeFactory ); - static::assertEmpty($configProvider->getTokensComponents()); + static::assertEmpty($configProvider->getTokensComponents($vaultPaymentCode)); } /** @@ -194,7 +225,7 @@ public function testGetTokensComponentsEmptyComponentProvider() { $storeId = 1; $customerId = 2; - $code = 'vault_payment'; + $vaultPaymentCode = 'vault_payment'; $this->session->expects(static::once()) ->method('getCustomerId') @@ -202,15 +233,15 @@ public function testGetTokensComponentsEmptyComponentProvider() $this->initStoreMock(); - $this->vaultPayment->expects(static::once()) - ->method('isActive') - ->with($storeId) - ->willReturn(true); + $this->paymentDataHelper->expects(static::once()) + ->method('getMethodInstance') + ->with($vaultPaymentCode) + ->willReturn($this->vaultPayment); $this->vaultPayment->expects(static::once()) - ->method('getProviderCode') + ->method('isActive') ->with($storeId) - ->willReturn($code); + ->willReturn(false); $this->paymentTokenRepository->expects(static::never()) ->method('getList'); @@ -221,11 +252,16 @@ public function testGetTokensComponentsEmptyComponentProvider() $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, - $this->vaultPayment, $this->dateTimeFactory ); - static::assertEmpty($configProvider->getTokensComponents()); + $this->objectManager->setBackwardCompatibleProperty( + $configProvider, + 'paymentDataHelper', + $this->paymentDataHelper + ); + + static::assertEmpty($configProvider->getTokensComponents($vaultPaymentCode)); } /** diff --git a/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php b/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php index 66adb87b76b56..e64fff27ff14c 100644 --- a/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php +++ b/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php @@ -6,14 +6,17 @@ namespace Magento\Vault\Test\Unit\Model\Ui; use Magento\Customer\Model\Session; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Payment\Helper\Data; use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Model\StoreManagerInterface; +use Magento\Vault\Api\Data\PaymentTokenInterface; use Magento\Vault\Model\CustomerTokenManagement; use Magento\Vault\Model\Ui\TokensConfigProvider; -use Magento\Vault\Api\Data\PaymentTokenInterface; use Magento\Vault\Model\Ui\TokenUiComponentInterface; use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface; use Magento\Vault\Model\VaultPaymentInterface; +use PHPUnit_Framework_MockObject_MockObject as MockObject; /** * Class ConfigProviderTest @@ -25,30 +28,46 @@ class TokensConfigProviderTest extends \PHPUnit_Framework_TestCase { /** - * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var StoreManagerInterface|MockObject */ private $storeManager; /** - * @var VaultPaymentInterface|\PHPUnit_Framework_MockObject_MockObject + * @var VaultPaymentInterface|MockObject */ private $vaultPayment; /** - * @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject + * @var StoreInterface|MockObject */ private $store; /** - * @var CustomerTokenManagement|\PHPUnit_Framework_MockObject_MockObject + * @var CustomerTokenManagement|MockObject */ private $customerTokenManagement; + /** + * @var Data|MockObject + */ + private $paymentDataHelper; + + /** + * @var ObjectManager + */ + private $objectManager; + protected function setUp() { $this->vaultPayment = $this->getMock(VaultPaymentInterface::class); $this->storeManager = $this->getMock(StoreManagerInterface::class); $this->store = $this->getMock(StoreInterface::class); + $this->paymentDataHelper = $this->getMockBuilder(Data::class) + ->disableOriginalConstructor() + ->setMethods(['getStoreMethods']) + ->getMock(); + + $this->objectManager = new ObjectManager($this); $this->customerTokenManagement = $this->getMockBuilder(CustomerTokenManagement::class) ->disableOriginalConstructor() ->getMock(); @@ -61,8 +80,8 @@ public function testGetConfig() $expectedConfig = [ 'payment' => [ - VaultPaymentInterface::CODE => [ - VaultPaymentInterface::CODE . '_item_' . '0' => [ + 'vault' => [ + $vaultProviderCode . '_item_' . '0' => [ 'config' => ['token_code' => 'code'], 'component' => 'Vendor_Module/js/vault_component' ] @@ -70,35 +89,41 @@ public function testGetConfig() ] ]; - $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class) - ->getMockForAbstractClass(); - $tokenUiComponentProvider = $this->getMock(TokenUiComponentProviderInterface::class); - $tokenUiComponent = $this->getMock(TokenUiComponentInterface::class); - - $this->vaultPayment->expects(static::once()) - ->method('getProviderCode') - ->with($storeId) - ->willReturn($vaultProviderCode); + $token = $this->getMockForAbstractClass(PaymentTokenInterface::class); + $tokenUiComponentProvider = $this->getMockForAbstractClass(TokenUiComponentProviderInterface::class); + $tokenUiComponent = $this->getMockForAbstractClass(TokenUiComponentInterface::class); $this->storeManager->expects(static::once()) ->method('getStore') - ->with(null) ->willReturn($this->store); $this->store->expects(static::once()) ->method('getId') ->willReturn($storeId); + + $this->paymentDataHelper->expects(static::once()) + ->method('getStoreMethods') + ->with($storeId) + ->willReturn([$this->vaultPayment]); + $this->vaultPayment->expects(static::once()) ->method('isActive') ->with($storeId) ->willReturn(true); + $this->vaultPayment->expects(static::once()) + ->method('getProviderCode') + ->willReturn($vaultProviderCode); - $this->customerTokenManagement->expects(self::once()) + $this->customerTokenManagement->expects(static::once()) ->method('getCustomerSessionTokens') - ->willReturn([$tokenMock]); + ->willReturn([$token]); + + $token->expects(static::once()) + ->method('getPaymentMethodCode') + ->willReturn($vaultProviderCode); $tokenUiComponentProvider->expects(static::once()) ->method('getComponentForToken') - ->with($tokenMock) + ->with($token) ->willReturn($tokenUiComponent); $tokenUiComponent->expects(static::once()) ->method('getConfig') @@ -109,16 +134,18 @@ public function testGetConfig() $configProvider = new TokensConfigProvider( $this->storeManager, - $this->vaultPayment, $this->customerTokenManagement, [ $vaultProviderCode => $tokenUiComponentProvider ] ); - static::assertEquals( - $expectedConfig, - $configProvider->getConfig() + $this->objectManager->setBackwardCompatibleProperty( + $configProvider, + 'paymentDataHelper', + $this->paymentDataHelper ); + + static::assertEquals($expectedConfig, $configProvider->getConfig()); } } diff --git a/app/code/Magento/Vault/Test/Unit/Model/Ui/VaultConfigProviderTest.php b/app/code/Magento/Vault/Test/Unit/Model/Ui/VaultConfigProviderTest.php index 4c7e413ec7c67..7d0d8339ab2b1 100644 --- a/app/code/Magento/Vault/Test/Unit/Model/Ui/VaultConfigProviderTest.php +++ b/app/code/Magento/Vault/Test/Unit/Model/Ui/VaultConfigProviderTest.php @@ -6,64 +6,115 @@ namespace Magento\Vault\Test\Unit\Model\Ui; use Magento\Customer\Model\Session; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Payment\Helper\Data; use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Vault\Model\Ui\VaultConfigProvider; use Magento\Vault\Model\VaultPaymentInterface; +use PHPUnit_Framework_MockObject_MockObject as MockObject; +/** + * Class VaultConfigProviderTest + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class VaultConfigProviderTest extends \PHPUnit_Framework_TestCase { /** - * @param int $id - * @param bool $isVaultEnabled - * + * @var Data|MockObject + */ + private $paymentDataHelper; + + /** + * @var VaultPaymentInterface|MockObject + */ + private $vaultPayment; + + /** + * @var Session|MockObject + */ + private $session; + + /** + * @var StoreInterface|MockObject + */ + private $store; + + /** + * @var StoreManagerInterface|MockObject + */ + private $storeManager; + + /** + * @var VaultConfigProvider + */ + private $vaultConfigProvider; + + protected function setUp() + { + $this->paymentDataHelper = $this->getMockBuilder(Data::class) + ->disableOriginalConstructor() + ->setMethods(['getStoreMethods']) + ->getMock(); + + $this->vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class); + $this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class); + $this->store = $this->getMockForAbstractClass(StoreInterface::class); + $this->session = $this->getMockBuilder(Session::class) + ->disableOriginalConstructor() + ->getMock(); + + $objectManager = new ObjectManager($this); + $this->vaultConfigProvider = new VaultConfigProvider($this->storeManager, $this->session); + $objectManager->setBackwardCompatibleProperty( + $this->vaultConfigProvider, + 'paymentDataHelper', + $this->paymentDataHelper + ); + } + + /** + * @param int $customerId + * @param bool $vaultEnabled * @dataProvider customerIdProvider */ public function testGetConfig($customerId, $vaultEnabled) { $storeId = 1; - $paymentProviderCode = 'concrete_vault_provider'; + $vaultPaymentCode = 'vault_payment'; $expectedConfiguration = [ - VaultPaymentInterface::CODE => [ - 'vault_provider_code' => $paymentProviderCode, - 'is_enabled' => $vaultEnabled + 'vault' => [ + $vaultPaymentCode => [ + 'is_enabled' => $vaultEnabled + ], ] ]; - $vaultMethod = $this->getMock(VaultPaymentInterface::class); - $storeManager = $this->getMock(StoreManagerInterface::class); - $store = $this->getMock(StoreInterface::class); - - $session = $this->getMockBuilder(Session::class) - ->disableOriginalConstructor() - ->getMock(); - - $session->expects(static::once()) + $this->session->expects(static::once()) ->method('getCustomerId') ->willReturn($customerId); - $storeManager->expects(static::once()) + $this->storeManager->expects(static::exactly(2)) ->method('getStore') - ->with(null) - ->willReturn($store); - $store->expects(static::once()) + ->willReturn($this->store); + $this->store->expects(static::exactly(2)) ->method('getId') ->willReturn($storeId); - $vaultMethod->expects($customerId !== null ? static::once() : static::never()) + + $this->paymentDataHelper->expects(static::once()) + ->method('getStoreMethods') + ->with($storeId) + ->willReturn([$this->vaultPayment]); + + $this->vaultPayment->expects(static::once()) + ->method('getCode') + ->willReturn($vaultPaymentCode); + $this->vaultPayment->expects($customerId !== null ? static::once() : static::never()) ->method('isActive') ->with($storeId) ->willReturn($vaultEnabled); - $vaultMethod->expects(static::once()) - ->method('getProviderCode') - ->with($storeId) - ->willReturn($paymentProviderCode); - $vaultCards = new VaultConfigProvider($storeManager, $vaultMethod, $session); - - static::assertEquals( - $expectedConfiguration, - $vaultCards->getConfig() - ); + static::assertEquals($expectedConfiguration, $this->vaultConfigProvider->getConfig()); } /** diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Magento/Payment/MethodsTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Magento/Payment/MethodsTest.php index 8d941daeba82b..1ea5649ef358e 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Magento/Payment/MethodsTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Magento/Payment/MethodsTest.php @@ -23,9 +23,6 @@ class MethodsTest extends \PHPUnit_Framework_TestCase */ public function testPaymentMethod($code, $methodClass) { - if ($code == \Magento\Vault\Model\VaultPaymentInterface::CODE) { - return; - } Bootstrap::getObjectManager()->configure($this->getTestConfiguration()); /** @var $blockFactory \Magento\Framework\View\Element\BlockFactory */ $blockFactory = Bootstrap::getObjectManager()->get( From 51d2a40b5ff4b51db6870a3d00d6a8f1cdd56f3e Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Fri, 3 Jun 2016 12:14:02 +0300 Subject: [PATCH 03/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Removed redundant dependency --- app/code/Magento/Braintree/Block/Form.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/app/code/Magento/Braintree/Block/Form.php b/app/code/Magento/Braintree/Block/Form.php index bd4efdc993f8f..cefc0a8418243 100644 --- a/app/code/Magento/Braintree/Block/Form.php +++ b/app/code/Magento/Braintree/Block/Form.php @@ -14,7 +14,6 @@ use Magento\Payment\Block\Form\Cc; use Magento\Payment\Helper\Data; use Magento\Payment\Model\Config; -use Magento\Store\Model\StoreManagerInterface; use Magento\Vault\Model\VaultPaymentInterface; /** @@ -43,18 +42,12 @@ class Form extends Cc */ private $paymentDataHelper; - /** - * @var StoreManagerInterface - */ - private $storeManager; - /** * @param Context $context * @param Config $paymentConfig * @param Quote $sessionQuote * @param GatewayConfig $gatewayConfig * @param CcType $ccType - * @param StoreManagerInterface $storeManager * @param array $data */ public function __construct( @@ -63,14 +56,12 @@ public function __construct( Quote $sessionQuote, GatewayConfig $gatewayConfig, CcType $ccType, - StoreManagerInterface $storeManager, array $data = [] ) { parent::__construct($context, $paymentConfig, $data); $this->sessionQuote = $sessionQuote; $this->gatewayConfig = $gatewayConfig; $this->ccType = $ccType; - $this->storeManager = $storeManager; } /** @@ -99,7 +90,7 @@ public function useCvv() */ public function isVaultEnabled() { - $storeId = $this->storeManager->getStore()->getId(); + $storeId = $this->_storeManager->getStore()->getId(); $vaultPayment = $this->getVaultPayment(); return $vaultPayment->isActive($storeId); } From 2ed5eb0069886d35ba037dd561b460d000f5e796 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Fri, 3 Jun 2016 13:46:12 +0300 Subject: [PATCH 04/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Removed redundant dependency for Payflow Pro block - Fixed failed integration tests --- .../Paypal/Block/Adminhtml/Payflowpro/CcForm.php | 10 +--------- .../Structure/Reader/_files/expected/config.xml | 12 ++++++++++++ .../Test/Integrity/Magento/Payment/MethodsTest.php | 3 +++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Paypal/Block/Adminhtml/Payflowpro/CcForm.php b/app/code/Magento/Paypal/Block/Adminhtml/Payflowpro/CcForm.php index 9dfe2ea7effc0..1fb0489de0f9e 100644 --- a/app/code/Magento/Paypal/Block/Adminhtml/Payflowpro/CcForm.php +++ b/app/code/Magento/Paypal/Block/Adminhtml/Payflowpro/CcForm.php @@ -26,27 +26,19 @@ class CcForm extends \Magento\Payment\Block\Transparent\Form */ private $paymentDataHelper; - /** - * @var StoreManagerInterface - */ - private $storeManager; - /** * @param Context $context * @param Config $paymentConfig * @param Session $checkoutSession - * @param StoreManagerInterface $storeManager * @param array $data */ public function __construct( Context $context, Config $paymentConfig, Session $checkoutSession, - StoreManagerInterface $storeManager, array $data = [] ) { parent::__construct($context, $paymentConfig, $checkoutSession, $data); - $this->storeManager = $storeManager; } /** @@ -55,7 +47,7 @@ public function __construct( */ public function isVaultEnabled() { - $storeId = $this->storeManager->getStore()->getId(); + $storeId = $this->_storeManager->getStore()->getId(); $vaultPayment = $this->getVaultPayment(); return $vaultPayment->isActive($storeId); } diff --git a/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml b/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml index 66b46a65bea81..0aef58de87818 100644 --- a/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml +++ b/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml @@ -100,6 +100,14 @@ + + + Magento\Config\Model\Config\Source\Yesno + payment/payflowpro_cc_vault/active + + + + @@ -110,6 +118,10 @@ payment/payflowpro/title 1 + + + payment/payflowpro_cc_vault/title + payment/payflowpro/sort_order diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Magento/Payment/MethodsTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Magento/Payment/MethodsTest.php index 1ea5649ef358e..ecbe322040bd8 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Magento/Payment/MethodsTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Magento/Payment/MethodsTest.php @@ -23,6 +23,9 @@ class MethodsTest extends \PHPUnit_Framework_TestCase */ public function testPaymentMethod($code, $methodClass) { + if ($code == 'vault') { + return; + } Bootstrap::getObjectManager()->configure($this->getTestConfiguration()); /** @var $blockFactory \Magento\Framework\View\Element\BlockFactory */ $blockFactory = Bootstrap::getObjectManager()->get( From b9ddbda7f15f80ea65cc863102062e4995a29dfe Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Fri, 3 Jun 2016 15:14:35 +0300 Subject: [PATCH 05/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Removed Config module dependency --- app/code/Magento/Vault/composer.json | 1 - app/code/Magento/Vault/etc/module.xml | 1 - 2 files changed, 2 deletions(-) diff --git a/app/code/Magento/Vault/composer.json b/app/code/Magento/Vault/composer.json index 3154832f55a8b..1c43e02d1148d 100644 --- a/app/code/Magento/Vault/composer.json +++ b/app/code/Magento/Vault/composer.json @@ -7,7 +7,6 @@ "magento/module-sales": "100.1.*", "magento/module-store": "100.1.*", "magento/module-checkout": "100.1.*", - "magento/module-config": "100.1.*", "magento/module-payment": "100.1.*", "magento/module-customer": "100.1.*", "magento/module-quote": "100.1.*", diff --git a/app/code/Magento/Vault/etc/module.xml b/app/code/Magento/Vault/etc/module.xml index 00290b817274e..cc654548a1bba 100644 --- a/app/code/Magento/Vault/etc/module.xml +++ b/app/code/Magento/Vault/etc/module.xml @@ -12,7 +12,6 @@ - From 8e0d2c7b7912f17837c3b78a605b5dc9f888cbfa Mon Sep 17 00:00:00 2001 From: Dmytro Kvashnin Date: Mon, 6 Jun 2016 16:43:02 +0300 Subject: [PATCH 06/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - reverted code back, fixed several minor defects --- .../adminhtml/system/paypal_payflowpro.xml | 2 +- .../web/template/payment/payflowpro-form.html | 2 +- .../Vault/Observer/VaultEnableAssigner.php | 11 +++++---- .../Unit/Observer/VaultEnableAssignerTest.php | 24 +++++++++++++++++++ 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml b/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml index 2d5fe942d5b40..52ae27d80d7a3 100644 --- a/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml +++ b/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml @@ -85,7 +85,7 @@ Magento\Config\Model\Config\Source\Yesno payment/payflowpro_cc_vault/active - + diff --git a/app/code/Magento/Paypal/view/frontend/web/template/payment/payflowpro-form.html b/app/code/Magento/Paypal/view/frontend/web/template/payment/payflowpro-form.html index 28f1ba5c55fd7..da1da321fe621 100644 --- a/app/code/Magento/Paypal/view/frontend/web/template/payment/payflowpro-form.html +++ b/app/code/Magento/Paypal/view/frontend/web/template/payment/payflowpro-form.html @@ -53,7 +53,7 @@ class="checkbox-inline" data-bind="attr: {'id': getCode() + '_vault_enabler'}, checked: vaultEnabler.isActivePaymentTokenEnabler"/> diff --git a/app/code/Magento/Vault/Observer/VaultEnableAssigner.php b/app/code/Magento/Vault/Observer/VaultEnableAssigner.php index 6c428271bee97..db112cf453912 100644 --- a/app/code/Magento/Vault/Observer/VaultEnableAssigner.php +++ b/app/code/Magento/Vault/Observer/VaultEnableAssigner.php @@ -26,9 +26,12 @@ public function execute(\Magento\Framework\Event\Observer $observer) return; } - $payment = $this->readPaymentModelArgument($observer); - $enableVault = isset($additionalData[VaultConfigProvider::IS_ACTIVE_CODE]) ? - filter_var($additionalData[VaultConfigProvider::IS_ACTIVE_CODE], FILTER_VALIDATE_BOOLEAN) : false; - $payment->setAdditionalInformation(VaultConfigProvider::IS_ACTIVE_CODE, $enableVault); + if (isset($additionalData[VaultConfigProvider::IS_ACTIVE_CODE])) { + $payment = $this->readPaymentModelArgument($observer); + $payment->setAdditionalInformation( + VaultConfigProvider::IS_ACTIVE_CODE, + filter_var($additionalData[VaultConfigProvider::IS_ACTIVE_CODE], FILTER_VALIDATE_BOOLEAN) + ); + } } } diff --git a/app/code/Magento/Vault/Test/Unit/Observer/VaultEnableAssignerTest.php b/app/code/Magento/Vault/Test/Unit/Observer/VaultEnableAssignerTest.php index 2d59188c232ee..63b381a744b9b 100644 --- a/app/code/Magento/Vault/Test/Unit/Observer/VaultEnableAssignerTest.php +++ b/app/code/Magento/Vault/Test/Unit/Observer/VaultEnableAssignerTest.php @@ -81,6 +81,30 @@ public function booleanDataProvider() ]; } + public function testExecuteNever() + { + $dataObject = new DataObject( + [ + PaymentInterface::KEY_ADDITIONAL_DATA => [] + ] + ); + $paymentModel = $this->getMock(InfoInterface::class); + + $paymentModel->expects(static::never()) + ->method('setAdditionalInformation'); + + $observer = $this->getPreparedObserverWithMap( + [ + [AbstractDataAssignObserver::DATA_CODE, $dataObject], + [AbstractDataAssignObserver::MODEL_CODE, $paymentModel] + ] + ); + + $vaultEnableAssigner = new VaultEnableAssigner(); + + $vaultEnableAssigner->execute($observer); + } + /** * @param array $returnMap * @return \PHPUnit_Framework_MockObject_MockObject|Observer From b5353a295cf365e6ce699be4717536c393b3f21d Mon Sep 17 00:00:00 2001 From: Dmytro Kvashnin Date: Mon, 6 Jun 2016 18:23:25 +0300 Subject: [PATCH 07/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - cleaned unused layouts --- .../layout/sales_order_create_index.xml | 17 ----------------- ...s_order_create_load_block_billing_method.xml | 17 ----------------- 2 files changed, 34 deletions(-) delete mode 100644 app/code/Magento/Vault/view/adminhtml/layout/sales_order_create_index.xml delete mode 100644 app/code/Magento/Vault/view/adminhtml/layout/sales_order_create_load_block_billing_method.xml diff --git a/app/code/Magento/Vault/view/adminhtml/layout/sales_order_create_index.xml b/app/code/Magento/Vault/view/adminhtml/layout/sales_order_create_index.xml deleted file mode 100644 index 472be65695503..0000000000000 --- a/app/code/Magento/Vault/view/adminhtml/layout/sales_order_create_index.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - vault - Magento_Vault::form/vault.phtml - - - - diff --git a/app/code/Magento/Vault/view/adminhtml/layout/sales_order_create_load_block_billing_method.xml b/app/code/Magento/Vault/view/adminhtml/layout/sales_order_create_load_block_billing_method.xml deleted file mode 100644 index 8b1e15107e16b..0000000000000 --- a/app/code/Magento/Vault/view/adminhtml/layout/sales_order_create_load_block_billing_method.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - vault - Magento_Vault::form/vault.phtml - - - - \ No newline at end of file From 501d46df1b7dfe16f349f8bb3fb2f2564a1a6a76 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Tue, 7 Jun 2016 16:53:36 +0300 Subject: [PATCH 08/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Removed payment details related to previous order from reordered quote --- app/code/Magento/Sales/Model/AdminOrder/Create.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index d8f65c0a28c37..e1dbd40d844c0 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -515,11 +515,6 @@ public function initFromOrder(\Magento\Sales\Model\Order $order) $this->setShippingMethod($order->getShippingMethod()); $quote->getShippingAddress()->setShippingDescription($order->getShippingDescription()); - $paymentData = $order->getPayment()->getData(); - unset($paymentData['cc_type'], $paymentData['cc_last_4']); - unset($paymentData['cc_exp_month'], $paymentData['cc_exp_year']); - $quote->getPayment()->addData($paymentData); - $orderCouponCode = $order->getCouponCode(); if ($orderCouponCode) { $quote->setCouponCode($orderCouponCode); From 281d0a8c0a830b16192d99a2cdfd31266380d0bc Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Tue, 7 Jun 2016 17:57:09 +0300 Subject: [PATCH 09/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Added integration test to cover case with removed payment details - Fixed failed PayflowPro integration test --- .../Reader/_files/expected/config.xml | 2 +- .../Sales/Model/AdminOrder/CreateTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml b/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml index 0aef58de87818..2e4c447ff83c1 100644 --- a/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml +++ b/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml @@ -105,7 +105,7 @@ Magento\Config\Model\Config\Source\Yesno payment/payflowpro_cc_vault/active - + diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php index e56e87b12176b..53339b6177e28 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php @@ -6,6 +6,8 @@ namespace Magento\Sales\Model\AdminOrder; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Sales\Model\Order; +use Magento\Framework\Registry; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -120,6 +122,29 @@ public function testInitFromOrderCcInformationDeleted() $this->assertNull($payment->getCcLast4()); } + /** + * @magentoDataFixture Magento/Sales/_files/order_paid_with_payflowpro.php + */ + public function testInitFromOrderWithEmptyPaymentDetails() + { + /** @var $objectManager \Magento\TestFramework\ObjectManager */ + $objectManager = Bootstrap::getObjectManager(); + /** @var $order \Magento\Sales\Model\Order */ + $order = $objectManager->create(Order::class); + $order->loadByIncrementId('100000001'); + + $objectManager->get(Registry::class) + ->unregister('rule_data'); + + $payment = $this->_model->initFromOrder($order) + ->getQuote() + ->getPayment(); + + static::assertEmpty($payment->getMethod()); + static::assertEmpty($payment->getAdditionalInformation()); + static::assertEmpty($payment->getAdditionalData()); + } + /** * @magentoAppIsolation enabled */ From 8bf55bcb0050c67e9f0037dc54f45dcb3088a07e Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Wed, 8 Jun 2016 12:52:19 +0300 Subject: [PATCH 10/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Updated integration test --- .../Magento/Sales/Model/AdminOrder/CreateTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php index 53339b6177e28..540d1de77a177 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php @@ -123,7 +123,7 @@ public function testInitFromOrderCcInformationDeleted() } /** - * @magentoDataFixture Magento/Sales/_files/order_paid_with_payflowpro.php + * @magentoDataFixture Magento/Sales/_files/order.php */ public function testInitFromOrderWithEmptyPaymentDetails() { @@ -136,13 +136,16 @@ public function testInitFromOrderWithEmptyPaymentDetails() $objectManager->get(Registry::class) ->unregister('rule_data'); - $payment = $this->_model->initFromOrder($order) - ->getQuote() - ->getPayment(); + $initOrder = $this->_model->initFromOrder($order); + $payment = $initOrder->getQuote()->getPayment(); + + static::assertEquals($initOrder->getQuote()->getId(), $payment->getData('quote_id')); + $payment->unsetData('quote_id'); static::assertEmpty($payment->getMethod()); static::assertEmpty($payment->getAdditionalInformation()); static::assertEmpty($payment->getAdditionalData()); + static::assertEmpty($payment->getData()); } /** From f0ade7cee4fcb4038b7457b721e18116cded4d1a Mon Sep 17 00:00:00 2001 From: Roman Liukshyn Date: Wed, 8 Jun 2016 14:47:41 +0300 Subject: [PATCH 11/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Fix functional tests for Vault --- .../Braintree/Test/Repository/ConfigData.xml | 12 ++++++------ .../Magento/Paypal/Test/Repository/ConfigData.xml | 12 ++++++------ .../Vault/Test/TestStep/UseSavedCreditCardStep.php | 2 +- .../Test/TestStep/UseVaultPaymentTokenStep.php | 14 +++++++++++--- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/Repository/ConfigData.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/Repository/ConfigData.xml index 479bf2f7e3580..cc1e9b714fbe3 100644 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/Repository/ConfigData.xml +++ b/dev/tests/functional/tests/app/Magento/Braintree/Test/Repository/ConfigData.xml @@ -191,19 +191,19 @@ - + payment 1 - Braintree - braintree + Yes + 1 - + payment 1 - Select vault provider - null + No + 0 diff --git a/dev/tests/functional/tests/app/Magento/Paypal/Test/Repository/ConfigData.xml b/dev/tests/functional/tests/app/Magento/Paypal/Test/Repository/ConfigData.xml index 790ab9cad5ae1..0706f45beeb4b 100644 --- a/dev/tests/functional/tests/app/Magento/Paypal/Test/Repository/ConfigData.xml +++ b/dev/tests/functional/tests/app/Magento/Paypal/Test/Repository/ConfigData.xml @@ -278,19 +278,19 @@ - + payment 1 - PayflowPro - payflowpro + Yes + 1 - + payment 1 - Select vault provider - null + No + 0 diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedCreditCardStep.php b/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedCreditCardStep.php index 1139913f3ef26..c3b4ac238610b 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedCreditCardStep.php +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedCreditCardStep.php @@ -46,7 +46,7 @@ public function __construct (CheckoutOnepage $checkoutOnepage, array $payment) */ public function run() { - $this->payment['method'] = 'vault_item_'; + $this->payment['method'] .= '_item_'; $this->checkoutOnepage->getPaymentBlock()->selectPaymentMethod($this->payment); } } diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseVaultPaymentTokenStep.php b/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseVaultPaymentTokenStep.php index 56f94252c8f23..ad693923955d4 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseVaultPaymentTokenStep.php +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseVaultPaymentTokenStep.php @@ -17,13 +17,20 @@ class UseVaultPaymentTokenStep implements TestStepInterface * @var OrderCreateIndex */ private $orderCreatePage; + + /** + * @var array + */ + private $payment; /** * @param OrderCreateIndex $orderCreateIndex + * @param array $payment */ - public function __construct(OrderCreateIndex $orderCreateIndex) + public function __construct(OrderCreateIndex $orderCreateIndex, array $payment) { $this->orderCreatePage = $orderCreateIndex; + $this->payment = $payment; } /** @@ -32,7 +39,8 @@ public function __construct(OrderCreateIndex $orderCreateIndex) public function run() { $block = $this->orderCreatePage->getCreateBlock(); - $block->selectPaymentMethod(['method' => 'vault']); - $block->selectVaultToken('token_switcher_'); + $this->payment['method'] .= '_cc_vault'; + $block->selectPaymentMethod($this->payment); + $block->selectVaultToken('token_switcher_' . $this->payment['method']); } } From 3dc1d396948b80c46316de9b568997a7d8ca25d6 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Thu, 9 Jun 2016 17:18:46 +0300 Subject: [PATCH 12/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Set vault enabled as shared option --- .../Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml | 1 + .../Model/Config/Structure/Reader/_files/expected/config.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml b/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml index 52ae27d80d7a3..2150d5dcb392b 100644 --- a/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml +++ b/app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml @@ -84,6 +84,7 @@ Magento\Config\Model\Config\Source\Yesno payment/payflowpro_cc_vault/active + 1 diff --git a/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml b/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml index 2e4c447ff83c1..61d9f6f2a475c 100644 --- a/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml +++ b/dev/tests/integration/testsuite/Magento/Paypal/Model/Config/Structure/Reader/_files/expected/config.xml @@ -104,6 +104,7 @@ Magento\Config\Model\Config\Source\Yesno payment/payflowpro_cc_vault/active + 1 From abd173ad41a4ae11750627593b6c341419a6affb Mon Sep 17 00:00:00 2001 From: Roman Liukshyn Date: Thu, 9 Jun 2016 19:12:09 +0300 Subject: [PATCH 13/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution --- .../Braintree/Test/Repository/ConfigData.xml | 4 +- .../TestCase/CreateVaultOrderBackendTest.xml | 2 +- .../TestCase/DeleteSavedCreditCardTest.xml | 26 -- .../Test/TestCase/UseVaultOnCheckoutTest.xml | 3 +- .../Payment/Test/Repository/CreditCard.xml | 7 + .../TestCase/DeleteSavedCreditCardTest.xml | 26 -- .../Test/TestCase/UseVaultOnCheckoutTest.xml | 2 +- .../TestCase/CreateVaultOrderBackendTest.php | 1 + .../TestCase/DeleteSavedCreditCardTest.php | 268 +++++++++++++++++- .../TestCase/DeleteSavedCreditCardTest.xml | 52 ++++ .../DeleteCreditCardFromMyAccountStep.php | 2 +- 11 files changed, 329 insertions(+), 64 deletions(-) delete mode 100644 dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/DeleteSavedCreditCardTest.xml delete mode 100644 dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/DeleteSavedCreditCardTest.xml create mode 100644 dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.xml diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/Repository/ConfigData.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/Repository/ConfigData.xml index cc1e9b714fbe3..916943e03af97 100644 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/Repository/ConfigData.xml +++ b/dev/tests/functional/tests/app/Magento/Braintree/Test/Repository/ConfigData.xml @@ -191,7 +191,7 @@ - + payment 1 Yes @@ -199,7 +199,7 @@ - + payment 1 No diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/CreateVaultOrderBackendTest.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/CreateVaultOrderBackendTest.xml index 84b0a58433ca0..0ae7da744c2f4 100644 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/CreateVaultOrderBackendTest.xml +++ b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/CreateVaultOrderBackendTest.xml @@ -7,7 +7,7 @@ --> - + test_type:3rd_party_test catalogProductSimple::product_10_dollar default diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/DeleteSavedCreditCardTest.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/DeleteSavedCreditCardTest.xml deleted file mode 100644 index 0a3a7206175e2..0000000000000 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/DeleteSavedCreditCardTest.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - catalogProductSimple::product_10_dollar - default - US_address_1_without_email - login - Flat Rate - Fixed - braintree - credit_card_braintree - visa_braintree - Yes - braintree, braintree_use_vault - test_type:3rd_party_test - - - - diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml index c9fc94be5ebae..cfe2e5f51b18e 100644 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml +++ b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml @@ -7,7 +7,7 @@ --> - + Use saved for Braintree credit card on checkout catalogProductSimple::product_10_dollar default @@ -22,7 +22,6 @@ braintree, braintree_use_vault Processing test_type:3rd_party_test - Processing Back, Cancel, Send Email, Hold, Invoice, Ship diff --git a/dev/tests/functional/tests/app/Magento/Payment/Test/Repository/CreditCard.xml b/dev/tests/functional/tests/app/Magento/Payment/Test/Repository/CreditCard.xml index b5d754d8e2174..f6c93407a0ccd 100644 --- a/dev/tests/functional/tests/app/Magento/Payment/Test/Repository/CreditCard.xml +++ b/dev/tests/functional/tests/app/Magento/Payment/Test/Repository/CreditCard.xml @@ -14,6 +14,13 @@ 123 + + 378282246310005 + 02 - February + 2021 + 1234 + + 4617747819866651 01 - January diff --git a/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/DeleteSavedCreditCardTest.xml b/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/DeleteSavedCreditCardTest.xml deleted file mode 100644 index 42afe4fbb58f0..0000000000000 --- a/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/DeleteSavedCreditCardTest.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - catalogProductSimple::product_10_dollar - default - US_address_1_without_email - login - Flat Rate - Fixed - payflowpro - credit_card - visa_default - Yes - payflowpro, payflowpro_use_vault - test_type:3rd_party_test - - - - diff --git a/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml b/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml index ef66a1b419f27..ff5f151580b11 100644 --- a/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml +++ b/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml @@ -7,7 +7,7 @@ --> - + catalogProductSimple::product_10_dollar default US_address_1_without_email diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/CreateVaultOrderBackendTest.php b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/CreateVaultOrderBackendTest.php index 57fb2a998909e..37d0fdc81c5aa 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/CreateVaultOrderBackendTest.php +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/CreateVaultOrderBackendTest.php @@ -31,6 +31,7 @@ * 16. Place order. * * @group Order_Management_(CS) + * @ZephyrId MAGETWO-48127, MAGETWO-48091 */ class CreateVaultOrderBackendTest extends Scenario { diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php index 6964feb2533ed..433000c4cdd04 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php @@ -5,7 +5,10 @@ */ namespace Magento\Vault\Test\TestCase; -use Magento\Mtf\TestCase\Scenario; +use Magento\Checkout\Test\Page\CheckoutOnepage; +use Magento\Mtf\ObjectManager; +use Magento\Mtf\TestCase\Injectable; +use Magento\Vault\Test\Constraint\AssertCreditCardNotPresentOnCheckout; /** * Preconditions: @@ -21,9 +24,9 @@ * 7. Perform assertions. * * @group Vault_(CS) - * @ZephyrId MAGETWO-48086 + * @ZephyrId MAGETWO-54059, MAGETWO-54072, MAGETWO-54068, MAGETWO-54015, MAGETWO-54011 */ -class DeleteSavedCreditCardTest extends Scenario +class DeleteSavedCreditCardTest extends Injectable { /* tags */ const MVP = 'yes'; @@ -34,10 +37,265 @@ class DeleteSavedCreditCardTest extends Scenario /** * Runs delete saved credit card test. * + * @param AssertCreditCardNotPresentOnCheckout $assertCreditCardNotPresentOnCheckout + * @param CheckoutOnepage $checkoutOnepage + * @param $products + * @param $configData + * @param $customer + * @param $checkoutMethod + * @param $shippingAddress + * @param $shipping + * @param array $payments + * @param $creditCardSave + */ + public function test( + AssertCreditCardNotPresentOnCheckout $assertCreditCardNotPresentOnCheckout, + CheckoutOnepage $checkoutOnepage, + $products, + $configData, + $customer, + $checkoutMethod, + $shippingAddress, + $shipping, + array $payments, + $creditCardSave + ) { + // Preconditions + $products = $this->prepareProducts($products); + $this->setupConfiguration($configData); + $customer = $this->createCustomer($customer); + + // Steps + foreach ($payments as $key => $payment) { + $this->addToCart($products); + $this->proceedToCheckout(); + if($key < 1) { // if this is the first order to be placed + $this->selectCheckoutMethod($checkoutMethod, $customer); + $this->fillShippingAddress($shippingAddress); + } + $this->fillShippingMethod($shipping); + if ($key >= 2) { // if this order will be placed via stored credit card + $this->useSavedCreditCard($payment); + } else { + $this->selectPaymentMethod($payment, $payment['creditCardClass'], $payment['creditCard']); + $this->saveCreditCard($payment, $creditCardSave); + } + $this->placeOrder(); + } + // Delete credit cards from My Account and verify they are not available on checkout + foreach($payments as $key => $payment) { + if ($key >= 2) { + $deletedCard = $this->deleteCreditCardFromMyAccount( + $customer, + $payment['creditCard'], + $payment['creditCardClass'] + ); + $this->addToCart($products); + $this->proceedToCheckout(); + $this->fillShippingMethod($shipping); + $assertCreditCardNotPresentOnCheckout->processAssert( + $checkoutOnepage, + $deletedCard['deletedCreditCard'] + ); + } + } + } + + /** + * @param $configData + */ + protected function setupConfiguration($configData) + { + $setupConfigurationStep = ObjectManager::getInstance()->create( + \Magento\Config\Test\TestStep\SetupConfigurationStep::class, + ['configData' => $configData] + ); + + $setupConfigurationStep->run(); + } + + /** + * Create products + * + * @param string $productList + * @return array + */ + protected function prepareProducts($productList) + { + $addToCartStep = ObjectManager::getInstance()->create( + \Magento\Catalog\Test\TestStep\CreateProductsStep::class, + ['products' => $productList] + ); + + $result = $addToCartStep->run(); + return $result['products']; + } + + /** + * @param array $products + * @return void + */ + protected function addToCart(array $products) + { + $addToCartStep = ObjectManager::getInstance()->create( + \Magento\Checkout\Test\TestStep\AddProductsToTheCartStep::class, + ['products' => $products] + ); + $addToCartStep->run(); + } + + /** + * @return void + */ + protected function proceedToCheckout() + { + $clickProceedToCheckoutStep = ObjectManager::getInstance()->create( + \Magento\Checkout\Test\TestStep\ProceedToCheckoutStep::class + ); + $clickProceedToCheckoutStep->run(); + } + + /** + * @param array $customer + */ + protected function createCustomer(array $customer) + { + $createCustomerStep = ObjectManager::getInstance()->create( + \Magento\Customer\Test\TestStep\CreateCustomerStep::class, + ['customer' => $customer] + ); + $result = $createCustomerStep->run(); + return $result['customer']; + } + + /** + * @param $checkoutMethod + * @param $customer + */ + protected function selectCheckoutMethod($checkoutMethod, $customer) + { + $selectCheckoutMethodStep = ObjectManager::getInstance()->create( + \Magento\Checkout\Test\TestStep\SelectCheckoutMethodStep::class, + [ + 'checkoutMethod' => $checkoutMethod, + 'customer' => $customer, + ] + ); + $selectCheckoutMethodStep->run(); + } + + /** + * @param array $shippingAddress + */ + protected function fillShippingAddress(array $shippingAddress) + { + $fillShippingAddressStep = ObjectManager::getInstance()->create( + \Magento\Checkout\Test\TestStep\FillShippingAddressStep::class, + ['shippingAddress' => $shippingAddress] + ); + $fillShippingAddressStep->run(); + } + + /** + * Add products to cart + * + * @param array $shipping + */ + protected function fillShippingMethod(array $shipping) + { + $fillShippingMethodStep = ObjectManager::getInstance()->create( + \Magento\Checkout\Test\TestStep\FillShippingMethodStep::class, + ['shipping' => $shipping] + ); + $fillShippingMethodStep->run(); + } + + /** + * @param array $payment + * @param $creditCardClass + * @param array $creditCard + */ + protected function selectPaymentMethod(array $payment, $creditCardClass, array $creditCard) + { + $selectPaymentMethodStep = ObjectManager::getInstance()->create( + \Magento\Checkout\Test\TestStep\SelectPaymentMethodStep::class, + [ + 'payment' => $payment, + 'creditCardClass' => $creditCardClass, + 'creditCard' => $creditCard, + ] + ); + $selectPaymentMethodStep->run(); + } + + /** + * Add products to cart + * + * @param $payment + * @param $creditCardSave + */ + protected function saveCreditCard($payment, $creditCardSave) + { + $saveCreditCardStep = ObjectManager::getInstance()->create( + \Magento\Vault\Test\TestStep\SaveCreditCardStep::class, + [ + 'creditCardSave' => $creditCardSave, + 'payment' => $payment + ] + ); + $saveCreditCardStep->run(); + } + + /** + * @return void + */ + protected function fillBillingInformation() + { + $fillBillingInformationStep = ObjectManager::getInstance()->create( + \Magento\Checkout\Test\TestStep\FillBillingInformationStep::class + ); + $fillBillingInformationStep->run(); + } + + /** * @return void */ - public function test() + protected function placeOrder() + { + $placeOrderStep = ObjectManager::getInstance()->create( + \Magento\Checkout\Test\TestStep\PlaceOrderStep::class + ); + $placeOrderStep->run(); + } + + /** + * @param $payment + */ + protected function useSavedCreditCard($payment) + { + $useSavedCreditCardStep = ObjectManager::getInstance()->create( + \Magento\Vault\Test\TestStep\UseSavedCreditCardStep::class, + ['payment' => $payment] + ); + $useSavedCreditCardStep->run(); + } + + /** + * @param $customer + * @param $creditCard + * @param $creditCardClass + */ + protected function deleteCreditCardFromMyAccount($customer, $creditCard, $creditCardClass) { - $this->executeScenario(); + $deleteCreditCardFromMyAccountStep = ObjectManager::getInstance()->create( + \Magento\Vault\Test\TestStep\DeleteCreditCardFromMyAccountStep::class, + [ + 'customer' => $customer, + 'creditCard' => $creditCard, + 'creditCardClass' => $creditCardClass + ] + ); + $deletedCard = $deleteCreditCardFromMyAccountStep->run(); + return $deletedCard; } } diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.xml b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.xml new file mode 100644 index 0000000000000..ecbed706005b4 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.xml @@ -0,0 +1,52 @@ + + + + + + catalogProductSimple::product_10_dollar + default + US_address_1_without_email + login + Flat Rate + Fixed + + + braintree + credit_card_braintree + + visa_braintree + + + + payflowpro + credit_card + + amex_default + + + + braintree + credit_card_braintree + + visa_braintree + + + + payflowpro + credit_card + + amex_default + + + + Yes + braintree, payflowpro, braintree_use_vault, payflowpro_use_vault + test_type:3rd_party_test + + + diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/DeleteCreditCardFromMyAccountStep.php b/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/DeleteCreditCardFromMyAccountStep.php index 85150d6c4798e..beb644a6ba224 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/DeleteCreditCardFromMyAccountStep.php +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/DeleteCreditCardFromMyAccountStep.php @@ -90,7 +90,7 @@ public function __construct( public function run() { $this->objectManager->create( - 'Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep', + \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class, ['customer' => $this->customer] )->run(); $this->customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Credit Cards'); From 6010651ef88b978bb993af69649210d4fbe8ae22 Mon Sep 17 00:00:00 2001 From: Roman Liukshyn Date: Fri, 10 Jun 2016 10:49:10 +0300 Subject: [PATCH 14/14] MAGETWO-53238: Vault Provider field contains Payflow Pro option in countries which don't have such solution - Fixed functional test --- .../TestCase/DeleteSavedCreditCardTest.php | 29 +++++++++---------- .../app/Magento/Vault/Test/etc/testcase.xml | 19 ------------ 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php index 433000c4cdd04..43497e821f6a9 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php @@ -83,21 +83,20 @@ public function test( $this->placeOrder(); } // Delete credit cards from My Account and verify they are not available on checkout - foreach($payments as $key => $payment) { - if ($key >= 2) { - $deletedCard = $this->deleteCreditCardFromMyAccount( - $customer, - $payment['creditCard'], - $payment['creditCardClass'] - ); - $this->addToCart($products); - $this->proceedToCheckout(); - $this->fillShippingMethod($shipping); - $assertCreditCardNotPresentOnCheckout->processAssert( - $checkoutOnepage, - $deletedCard['deletedCreditCard'] - ); - } + $paymentsCount = count($payments); + for($i = 2; $i < $paymentsCount; $i++) { + $deletedCard = $this->deleteCreditCardFromMyAccount( + $customer, + $payments[$i]['creditCard'], + $payments[$i]['creditCardClass'] + ); + $this->addToCart($products); + $this->proceedToCheckout(); + $this->fillShippingMethod($shipping); + $assertCreditCardNotPresentOnCheckout->processAssert( + $checkoutOnepage, + $deletedCard['deletedCreditCard'] + ); } } diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/Vault/Test/etc/testcase.xml index 3ffbabdec638b..a804e4ac34555 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/etc/testcase.xml +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/etc/testcase.xml @@ -6,25 +6,6 @@ */ --> - - - - - - - - - - - - - - - - - - -