ConfigTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Gateway\Config;
  7. use Magento\Config\Model\Config as SystemConfig;
  8. use Magento\TestFramework\Helper\Bootstrap;
  9. class ConfigTest extends \PHPUnit\Framework\TestCase
  10. {
  11. const METHOD_CODE = 'braintree';
  12. /** @var Config */
  13. private $config;
  14. /** @var SystemConfig */
  15. private $systemConfig;
  16. protected function setUp()
  17. {
  18. $objectManager = Bootstrap::getObjectManager();
  19. $this->config = $objectManager->create(Config::class, [
  20. 'methodCode' => self::METHOD_CODE
  21. ]);
  22. $this->systemConfig = $objectManager->create(SystemConfig::class);
  23. }
  24. /**
  25. * Test methods that load Braintree configuration, and verify that values were json decoded correctly
  26. * by the serializer dependency.
  27. *
  28. * @magentoDbIsolation enabled
  29. * @dataProvider countryCreditRetrievalProvider
  30. * @param string $value
  31. * @param array $expected
  32. */
  33. public function testCountryCreditRetrieval($value, array $expected)
  34. {
  35. $this->systemConfig->setDataByPath('payment/' . self::METHOD_CODE . '/countrycreditcard', $value);
  36. $this->systemConfig->save();
  37. $countrySpecificCardTypeConfig = $this->config->getCountrySpecificCardTypeConfig();
  38. $this->assertEquals($expected, $countrySpecificCardTypeConfig);
  39. foreach ($expected as $country => $expectedCreditCardTypes) {
  40. $countryAvailableCardTypes = $this->config->getCountryAvailableCardTypes($country);
  41. $this->assertEquals($expectedCreditCardTypes, $countryAvailableCardTypes);
  42. }
  43. }
  44. public function countryCreditRetrievalProvider()
  45. {
  46. return [
  47. 'empty_array' => [
  48. 'value' => '[]',
  49. 'expected' => []
  50. ],
  51. 'valid_data' => [
  52. 'value' => '{"AF":["AE","VI"],"US":["AE","VI","MA"]}',
  53. 'expected' => [
  54. 'AF' => ['AE', 'VI'],
  55. 'US' => ['AE', 'VI', 'MA']
  56. ]
  57. ]
  58. ];
  59. }
  60. }