public function testBuildWithSwitchedOffVault()
 {
     $expectedResult = [];
     $buildSubject = [];
     $this->vaultPaymentMock->expects(self::once())->method('isActiveForPayment')->willReturn(false);
     static::assertEquals($expectedResult, $this->builder->build($buildSubject));
 }
 /**
  * @param int $customerId
  * @param bool $vaultEnabled
  * @dataProvider customerIdProvider
  */
 public function testGetConfig($customerId, $vaultEnabled)
 {
     $storeId = 1;
     $vaultPaymentCode = 'vault_payment';
     $expectedConfiguration = ['vault' => [$vaultPaymentCode => ['is_enabled' => $vaultEnabled]]];
     $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId);
     $this->storeManager->expects(static::exactly(2))->method('getStore')->willReturn($this->store);
     $this->store->expects(static::exactly(2))->method('getId')->willReturn($storeId);
     $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);
     static::assertEquals($expectedConfiguration, $this->vaultConfigProvider->getConfig());
 }
 public function testGetCustomerSessionTokens()
 {
     $customerId = 1;
     $providerCode = 'vault_provider';
     $storeId = 1;
     $token = $this->getMock(PaymentTokenInterface::class);
     $expectation = [$token];
     $this->customerSessionMock->expects(self::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())->method('getVisibleAvailableTokens')->with($customerId, $providerCode)->willReturn($expectation);
     static::assertEquals($expectation, $this->tokenManagement->getCustomerSessionTokens());
 }
 public function testGetConfig()
 {
     $storeId = 1;
     $vaultProviderCode = 'vault_provider_code';
     $expectedConfig = ['payment' => [VaultPaymentInterface::CODE => [VaultPaymentInterface::CODE . '_item_' . '0' => ['config' => ['token_code' => 'code'], 'component' => 'Vendor_Module/js/vault_component']]]];
     $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);
     $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->customerTokenManagement->expects(self::once())->method('getCustomerSessionTokens')->willReturn([$tokenMock]);
     $tokenUiComponentProvider->expects(static::once())->method('getComponentForToken')->with($tokenMock)->willReturn($tokenUiComponent);
     $tokenUiComponent->expects(static::once())->method('getConfig')->willReturn(['token_code' => 'code']);
     $tokenUiComponent->expects(static::once())->method('getName')->willReturn('Vendor_Module/js/vault_component');
     $configProvider = new TokensConfigProvider($this->storeManager, $this->vaultPayment, $this->customerTokenManagement, [$vaultProviderCode => $tokenUiComponentProvider]);
     static::assertEquals($expectedConfig, $configProvider->getConfig());
 }
 public function testGetConfigNoActiveVaultProvider()
 {
     $customerId = 1;
     $storeId = 1;
     $this->customerSessionMock->expects(self::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(false);
     $this->paymentTokenRepositoryMock->expects(self::never())->method('getList');
     $configProvider = new TokensConfigProvider($this->customerSessionMock, $this->paymentTokenRepositoryMock, $this->filterBuilderMock, $this->searchCriteriaBuilderMock, $this->storeManager, $this->vaultPayment);
     $config = $configProvider->getConfig();
     self::assertEmpty($config);
 }
 /**
  * @covers \Magento\Vault\Model\Ui\Adminhtml\TokensConfigProvider::getTokensComponents
  */
 public function testGetTokensComponentsEmptyComponentProvider()
 {
     $storeId = 1;
     $customerId = 2;
     $code = 'vault_payment';
     $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId);
     $this->initStoreMock();
     $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true);
     $this->vaultPayment->expects(static::once())->method('getProviderCode')->with($storeId)->willReturn($code);
     $this->paymentTokenRepository->expects(static::never())->method('getList');
     $configProvider = new TokensConfigProvider($this->session, $this->paymentTokenRepository, $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, $this->vaultPayment, $this->dateTimeFactory);
     static::assertEmpty($configProvider->getTokensComponents());
 }
 public function testGetConfig()
 {
     $storeId = 1;
     $vaultProviderCode = 'vault_provider_code';
     $expectedConfig = ['payment' => ['vault' => [$vaultProviderCode . '_item_' . '0' => ['config' => ['token_code' => 'code'], 'component' => 'Vendor_Module/js/vault_component']]]];
     $token = $this->getMockForAbstractClass(PaymentTokenInterface::class);
     $tokenUiComponentProvider = $this->getMockForAbstractClass(TokenUiComponentProviderInterface::class);
     $tokenUiComponent = $this->getMockForAbstractClass(TokenUiComponentInterface::class);
     $this->storeManager->expects(static::once())->method('getStore')->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(static::once())->method('getCustomerSessionTokens')->willReturn([$token]);
     $token->expects(static::once())->method('getPaymentMethodCode')->willReturn($vaultProviderCode);
     $tokenUiComponentProvider->expects(static::once())->method('getComponentForToken')->with($token)->willReturn($tokenUiComponent);
     $tokenUiComponent->expects(static::once())->method('getConfig')->willReturn(['token_code' => 'code']);
     $tokenUiComponent->expects(static::once())->method('getName')->willReturn('Vendor_Module/js/vault_component');
     $configProvider = new TokensConfigProvider($this->storeManager, $this->customerTokenManagement, [$vaultProviderCode => $tokenUiComponentProvider]);
     $this->objectManager->setBackwardCompatibleProperty($configProvider, 'paymentDataHelper', $this->paymentDataHelper);
     static::assertEquals($expectedConfig, $configProvider->getConfig());
 }
 /**
  * Run test for proxy methods
  */
 public function testProxyCall()
 {
     /** @var SearchCriteria|\PHPUnit_Framework_MockObject_MockObject $searchCriteriaMock */
     $searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)->getMockForAbstractClass();
     /** @var PaymentTokenSearchResultsInterface|\PHPUnit_Framework_MockObject_MockObject $searchResultMock */
     $searchResultMock = $this->getMockBuilder(PaymentTokenSearchResultsInterface::class)->getMockForAbstractClass();
     /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */
     $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass();
     /** @var PaymentTokenRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject $proxyCallsMock */
     $proxyCallsMock = $this->getMockBuilder(PaymentTokenRepositoryInterface::class)->getMockForAbstractClass();
     $this->vaultPaymentMock->expects(self::once())->method('isActive')->willReturn(1);
     $this->configMock->expects(self::once())->method('getValue')->with(VaultProvidersMap::VALUE_CODE)->willReturn('code');
     $this->objectManagerMock->expects(self::once())->method('get')->with(get_class($proxyCallsMock))->willReturn($proxyCallsMock);
     $proxy = new PaymentTokenRepositoryProxy($this->nullRepositoryMock, $this->vaultPaymentMock, $this->configMock, $this->objectManagerMock, ['code' => get_class($proxyCallsMock)]);
     $proxyCallsMock->expects(self::once())->method('delete')->with($tokenMock)->willReturn(self::DELETE_RESULT);
     $proxyCallsMock->expects(self::once())->method('getById')->with(1)->willReturn($tokenMock);
     $proxyCallsMock->expects(self::once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultMock);
     $proxyCallsMock->expects(self::once())->method('save')->with($tokenMock)->willReturn(self::SAVE_RESULT);
     self::assertEquals(self::DELETE_RESULT, $proxy->delete($tokenMock));
     self::assertEquals($tokenMock, $proxy->getById(1));
     self::assertEquals($searchResultMock, $proxy->getList($searchCriteriaMock));
     self::assertEquals(self::SAVE_RESULT, $proxy->save($tokenMock));
 }
 /**
  * @covers \Magento\Vault\Model\Ui\Adminhtml\TokensConfigProvider::getTokensComponents
  */
 public function testGetTokensComponentsEmptyComponentProvider()
 {
     $storeId = 1;
     $customerId = 2;
     $vaultPaymentCode = 'vault_payment';
     $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId);
     $this->initStoreMock();
     $this->paymentDataHelper->expects(static::once())->method('getMethodInstance')->with($vaultPaymentCode)->willReturn($this->vaultPayment);
     $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(false);
     $this->paymentTokenRepository->expects(static::never())->method('getList');
     $configProvider = new TokensConfigProvider($this->session, $this->paymentTokenRepository, $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, $this->dateTimeFactory);
     $this->objectManager->setBackwardCompatibleProperty($configProvider, 'paymentDataHelper', $this->paymentDataHelper);
     static::assertEmpty($configProvider->getTokensComponents($vaultPaymentCode));
 }
Exemplo n.º 10
0
 /**
  * @covers \Magento\BraintreeTwo\Gateway\Response\VaultDetailsHandler::handle
  */
 public function testHandle()
 {
     $this->vaultPayment->expects(self::once())->method('isActiveForPayment')->willReturn(true);
     $this->paymentExtension->expects(self::once())->method('setVaultPaymentToken')->with($this->paymentToken);
     $this->paymentExtension->expects(self::once())->method('getVaultPaymentToken')->willReturn($this->paymentToken);
     $paymentData = $this->getPaymentDataObjectMock();
     $transaction = $this->getBraintreeTransaction();
     $subject = ['payment' => $paymentData];
     $response = ['object' => $transaction];
     $this->subjectReader->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData);
     $this->subjectReader->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction);
     $this->paymentToken->expects(static::once())->method('setGatewayToken')->with('rh3gd4');
     $this->paymentHandler->handle($subject, $response);
     $this->assertSame($this->paymentToken, $this->payment->getExtensionAttributes()->getVaultPaymentToken());
 }
Exemplo n.º 11
0
 public function testIsVaultEnabled()
 {
     $this->vaultService->expects(static::once())->method('isActiveForPayment')->with(ConfigProvider::CODE)->willReturn(true);
     static::assertTrue($this->block->isVaultEnabled());
 }