VaultConfigProviderTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Vault\Test\Unit\Model\Ui;
  7. use Magento\Customer\Model\Session;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. use Magento\Store\Api\Data\StoreInterface;
  10. use Magento\Store\Model\StoreManagerInterface;
  11. use Magento\Vault\Api\PaymentMethodListInterface;
  12. use Magento\Vault\Model\Ui\VaultConfigProvider;
  13. use Magento\Vault\Model\VaultPaymentInterface;
  14. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  15. /**
  16. * Class VaultConfigProviderTest
  17. */
  18. class VaultConfigProviderTest extends \PHPUnit\Framework\TestCase
  19. {
  20. /**
  21. * @var VaultPaymentInterface|MockObject
  22. */
  23. private $vaultPayment;
  24. /**
  25. * @var Session|MockObject
  26. */
  27. private $session;
  28. /**
  29. * @var StoreInterface|MockObject
  30. */
  31. private $store;
  32. /**
  33. * @var StoreManagerInterface|MockObject
  34. */
  35. private $storeManager;
  36. /**
  37. * @var PaymentMethodListInterface|MockObject
  38. */
  39. private $vaultPaymentList;
  40. /**
  41. * @var VaultConfigProvider
  42. */
  43. private $vaultConfigProvider;
  44. protected function setUp()
  45. {
  46. $this->vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class);
  47. $this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
  48. $this->store = $this->getMockForAbstractClass(StoreInterface::class);
  49. $this->session = $this->getMockBuilder(Session::class)
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $this->vaultPaymentList = $this->createMock(PaymentMethodListInterface::class);
  53. $objectManager = new ObjectManager($this);
  54. $this->vaultConfigProvider = new VaultConfigProvider($this->storeManager, $this->session);
  55. $objectManager->setBackwardCompatibleProperty(
  56. $this->vaultConfigProvider,
  57. 'vaultPaymentList',
  58. $this->vaultPaymentList
  59. );
  60. }
  61. /**
  62. * @param int $customerId
  63. * @param bool $vaultEnabled
  64. * @dataProvider customerIdProvider
  65. */
  66. public function testGetConfig($customerId, $vaultEnabled)
  67. {
  68. $storeId = 1;
  69. $vaultPaymentCode = 'vault_payment';
  70. $expectedConfiguration = [
  71. 'vault' => [
  72. $vaultPaymentCode => [
  73. 'is_enabled' => $vaultEnabled
  74. ],
  75. ]
  76. ];
  77. $this->session->expects(static::once())
  78. ->method('getCustomerId')
  79. ->willReturn($customerId);
  80. $this->storeManager->expects(static::once())
  81. ->method('getStore')
  82. ->willReturn($this->store);
  83. $this->store->expects(static::once())
  84. ->method('getId')
  85. ->willReturn($storeId);
  86. $this->vaultPaymentList->expects(static::once())
  87. ->method('getActiveList')
  88. ->willReturn([$this->vaultPayment]);
  89. $this->vaultPayment->expects(static::once())
  90. ->method('getCode')
  91. ->willReturn($vaultPaymentCode);
  92. $this->vaultPayment->expects($customerId !== null ? static::once() : static::never())
  93. ->method('isActive')
  94. ->with($storeId)
  95. ->willReturn($vaultEnabled);
  96. static::assertEquals($expectedConfiguration, $this->vaultConfigProvider->getConfig());
  97. }
  98. /**
  99. * @return array
  100. */
  101. public function customerIdProvider()
  102. {
  103. return [
  104. [
  105. 'id' => 1,
  106. 'vault_enabled' => true
  107. ],
  108. [
  109. 'id' => null,
  110. 'vault_enabled' => false
  111. ]
  112. ];
  113. }
  114. }