/** * Run test for saveTokenWithPaymentLink method */ public function testSaveTokenWithPaymentLinkWithDuplicateTokenNotVisible() { /** @var OrderPaymentInterface|\PHPUnit_Framework_MockObject_MockObject $paymentMock */ $paymentMock = $this->getMock(OrderPaymentInterface::class); /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */ $tokenMock = $this->getMock(PaymentTokenInterface::class); /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $duplicateToken */ $duplicateToken = $this->getMock(PaymentTokenInterface::class); $entityId = 1; $newEntityId = 1; $paymentId = 1; $customerId = 1; $createdAt = '30-02-2017'; $publicHash = 'existing-token'; $duplicateTokenData = ['entity_id' => $entityId]; $newHash = 'new-token2'; $tokenMock->expects(static::atLeastOnce())->method('getPublicHash')->willReturn($publicHash); $tokenMock->expects(static::atLeastOnce())->method('getCustomerId')->willReturn($customerId); $this->paymentTokenResourceModelMock->expects(self::once())->method('getByPublicHash')->with($publicHash, $customerId)->willReturn($duplicateTokenData); $this->paymentTokenFactoryMock->expects(self::once())->method('create')->with(['data' => $duplicateTokenData])->willReturn($duplicateToken); $tokenMock->expects(static::once())->method('getIsVisible')->willReturn(false); $tokenMock->expects(static::once())->method('getCustomerId')->willReturn($customerId); $tokenMock->expects(static::once())->method('getCreatedAt')->willReturn($createdAt); $this->encryptorMock->expects(static::once())->method('getHash')->with($publicHash . $createdAt)->willReturn($newHash); $tokenMock->expects(static::once())->method('setPublicHash')->with($newHash); $this->paymentTokenRepositoryMock->expects(self::once())->method('save')->with($tokenMock); $tokenMock->expects(static::once())->method('getEntityId')->willReturn($newEntityId); $paymentMock->expects(self::once())->method('getEntityId')->willReturn($paymentId); $this->paymentTokenResourceModelMock->expects(static::once())->method('addLinkToOrderPayment')->with($newEntityId, $paymentId); $this->paymentTokenManagement->saveTokenWithPaymentLink($tokenMock, $paymentMock); }
/** * Run test for saveTokenWithPaymentLink method */ public function testSaveTokenWithPaymentLink() { /** @var OrderPaymentInterface|\PHPUnit_Framework_MockObject_MockObject $paymentMock */ $paymentMock = $this->getMock(OrderPaymentInterface::class); /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */ $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass(); $tokenMock->expects(self::once())->method('getEntityId')->willReturn(1); $this->paymentTokenRepositoryMock->expects(self::once())->method('save')->with($tokenMock); $paymentMock->expects(self::once())->method('getEntityId'); $this->paymentTokenManagement->saveTokenWithPaymentLink($tokenMock, $paymentMock); }
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()); }
/** * @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)); }
/** * Run test for default repository */ public function testDefaultRepository() { /** @var SearchCriteria|\PHPUnit_Framework_MockObject_MockObject $searchCriteriaMock */ $searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)->getMockForAbstractClass(); /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */ $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass(); /** @var PaymentTokenSearchResultsInterface|\PHPUnit_Framework_MockObject_MockObject $searchResultMock */ $searchResultMock = $this->getMockBuilder(PaymentTokenSearchResultsInterface::class)->getMockForAbstractClass(); $this->objectManagerMock->expects(self::never())->method('get'); $proxy = new PaymentTokenRepositoryProxy($this->defaultRepository, $this->configMock, $this->objectManagerMock, []); $this->defaultRepository->expects(self::once())->method('getById')->with(1)->willReturn($tokenMock); $this->defaultRepository->expects(self::once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultMock); self::assertEquals($tokenMock, $proxy->getById(1)); self::assertEquals($searchResultMock, $proxy->getList($searchCriteriaMock)); }
public function testGetVisibleAvailableTokens() { $customerId = 1; $searchCriteria = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->getMock(); $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); // express at expectations $expiresAtFilter = $this->createExpectedFilter(PaymentTokenInterface::EXPIRES_AT, '2015-01-01 00:00:00', 3); $this->filterBuilder->expects(static::once())->method('setConditionType')->with('gt')->willReturnSelf(); $date = $this->getMockBuilder('DateTime')->disableOriginalConstructor()->getMock(); $this->dateTimeFactory->expects(static::once())->method('create')->with("now", new \DateTimeZone('UTC'))->willReturn($date); $date->expects(static::once())->method('format')->with('Y-m-d 00:00:00')->willReturn('2015-01-01 00:00:00'); $this->searchCriteriaBuilder->expects(self::once())->method('addFilters')->with([$customerFilter, $visibilityFilter, $isActiveFilter, $expiresAtFilter])->willReturnSelf(); $this->searchCriteriaBuilder->expects(self::once())->method('create')->willReturn($searchCriteria); $this->paymentTokenRepository->expects(self::once())->method('getList')->with($searchCriteria)->willReturn($searchResult); $searchResult->expects(self::once())->method('getItems')->willReturn([$token]); static::assertEquals([$token], $this->paymentTokenManagement->getVisibleAvailableTokens($customerId)); }