ConfigTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\AuthorizenetAcceptjs\Test\Unit\Gateway;
  8. use Magento\AuthorizenetAcceptjs\Gateway\Config;
  9. use Magento\Framework\App\Config\ScopeConfigInterface;
  10. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  11. use Magento\Store\Model\ScopeInterface;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. use PHPUnit\Framework\TestCase;
  14. class ConfigTest extends TestCase
  15. {
  16. /**
  17. * @var Config
  18. */
  19. private $model;
  20. /**
  21. * @var ScopeConfigInterface|MockObject
  22. */
  23. private $scopeConfigMock;
  24. protected function setUp()
  25. {
  26. $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
  27. $objectManager = new ObjectManager($this);
  28. $this->model = $objectManager->getObject(
  29. Config::class,
  30. [
  31. 'scopeConfig' => $this->scopeConfigMock,
  32. 'methodCode' => Config::METHOD,
  33. ]
  34. );
  35. }
  36. /**
  37. * @param $getterName
  38. * @param $configField
  39. * @param $configValue
  40. * @param $expectedValue
  41. * @dataProvider configMapProvider
  42. */
  43. public function testConfigGetters($getterName, $configField, $configValue, $expectedValue)
  44. {
  45. $this->scopeConfigMock->method('getValue')
  46. ->with($this->getPath($configField), ScopeInterface::SCOPE_STORE, 123)
  47. ->willReturn($configValue);
  48. $this->assertEquals($expectedValue, $this->model->{$getterName}(123));
  49. }
  50. /**
  51. * @dataProvider environmentUrlProvider
  52. * @param $environment
  53. * @param $expectedUrl
  54. */
  55. public function testGetApiUrl($environment, $expectedUrl)
  56. {
  57. $this->scopeConfigMock->method('getValue')
  58. ->with($this->getPath('environment'), ScopeInterface::SCOPE_STORE, 123)
  59. ->willReturn($environment);
  60. $this->assertEquals($expectedUrl, $this->model->getApiUrl(123));
  61. }
  62. /**
  63. * @dataProvider environmentSolutionProvider
  64. * @param $environment
  65. * @param $expectedSolution
  66. */
  67. public function testGetSolutionIdSandbox($environment, $expectedSolution)
  68. {
  69. $this->scopeConfigMock->method('getValue')
  70. ->with($this->getPath('environment'), ScopeInterface::SCOPE_STORE, 123)
  71. ->willReturn($environment);
  72. $this->assertEquals($expectedSolution, $this->model->getSolutionId(123));
  73. }
  74. public function configMapProvider()
  75. {
  76. return [
  77. ['getLoginId', 'login', 'username', 'username'],
  78. ['getEnvironment', 'environment', 'production', 'production'],
  79. ['getClientKey', 'public_client_key', 'abc', 'abc'],
  80. ['getTransactionKey', 'trans_key', 'password', 'password'],
  81. ['getLegacyTransactionHash', 'trans_md5', 'abc123', 'abc123'],
  82. ['getTransactionSignatureKey', 'trans_signature_key', 'abc123', 'abc123'],
  83. ['getPaymentAction', 'payment_action', 'authorize', 'authorize'],
  84. ['shouldEmailCustomer', 'email_customer', true, true],
  85. ['isCvvEnabled', 'cvv_enabled', true, true],
  86. ['getAdditionalInfoKeys', 'paymentInfoKeys', 'a,b,c', ['a', 'b', 'c']],
  87. ['getTransactionInfoSyncKeys', 'transactionSyncKeys', 'a,b,c', ['a', 'b', 'c']],
  88. ];
  89. }
  90. public function environmentUrlProvider()
  91. {
  92. return [
  93. ['sandbox', 'https://apitest.authorize.net/xml/v1/request.api'],
  94. ['production', 'https://api.authorize.net/xml/v1/request.api'],
  95. ];
  96. }
  97. public function environmentSolutionProvider()
  98. {
  99. return [
  100. ['sandbox', 'AAA102993'],
  101. ['production', 'AAA175350'],
  102. ];
  103. }
  104. /**
  105. * Return config path
  106. *
  107. * @param string $field
  108. * @return string
  109. */
  110. private function getPath($field)
  111. {
  112. return sprintf(Config::DEFAULT_PATH_PATTERN, Config::METHOD, $field);
  113. }
  114. }