SmartButtonConfigTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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\Paypal\Test\Unit\Model;
  8. use Magento\Paypal\Model\SmartButtonConfig;
  9. use Magento\Framework\Locale\ResolverInterface;
  10. use Magento\Paypal\Model\ConfigFactory;
  11. class SmartButtonConfigTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Paypal\Model\SmartButtonConfig
  15. */
  16. private $model;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $localeResolverMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $configMock;
  25. protected function setUp()
  26. {
  27. $this->localeResolverMock = $this->getMockForAbstractClass(ResolverInterface::class);
  28. $this->configMock = $this->getMockBuilder(\Magento\Paypal\Model\Config::class)
  29. ->disableOriginalConstructor()
  30. ->getMock();
  31. /** @var \PHPUnit_Framework_MockObject_MockObject $configFactoryMock */
  32. $configFactoryMock = $this->getMockBuilder(ConfigFactory::class)
  33. ->disableOriginalConstructor()
  34. ->setMethods(['create'])
  35. ->getMock();
  36. $configFactoryMock->expects($this->once())->method('create')->willReturn($this->configMock);
  37. $this->model = new SmartButtonConfig(
  38. $this->localeResolverMock,
  39. $configFactoryMock,
  40. $this->getDefaultStyles(),
  41. $this->getAllowedFundings()
  42. );
  43. }
  44. /**
  45. * @param string $page
  46. * @param string $locale
  47. * @param string $disallowedFundings
  48. * @param string $layout
  49. * @param string $size
  50. * @param string $shape
  51. * @param string $label
  52. * @param string $color
  53. * @param string $installmentPeriodLabel
  54. * @param string $installmentPeriodLocale
  55. * @param array $expected
  56. * @dataProvider getConfigDataProvider
  57. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  58. */
  59. public function testGetConfig(
  60. string $page,
  61. string $locale,
  62. bool $isCustomize,
  63. ?string $disallowedFundings,
  64. string $layout,
  65. string $size,
  66. string $shape,
  67. string $label,
  68. string $color,
  69. string $installmentPeriodLabel,
  70. string $installmentPeriodLocale,
  71. array $expected = []
  72. ) {
  73. $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn($locale);
  74. $this->configMock->expects($this->any())->method('getValue')->will($this->returnValueMap([
  75. ['merchant_id', null, 'merchant'],
  76. ['sandbox_flag', null, true],
  77. ['disable_funding_options', null, $disallowedFundings],
  78. ["{$page}_page_button_customize", null, $isCustomize],
  79. ["{$page}_page_button_layout", null, $layout],
  80. ["{$page}_page_button_size", null, $size],
  81. ["{$page}_page_button_color", null, $color],
  82. ["{$page}_page_button_shape", null, $shape],
  83. ["{$page}_page_button_label", null, $label],
  84. [$page . '_page_button_' . $installmentPeriodLocale . '_installment_period', null, $installmentPeriodLabel]
  85. ]));
  86. self::assertEquals($expected, $this->model->getConfig($page));
  87. }
  88. public function getConfigDataProvider()
  89. {
  90. return include __DIR__ . '/_files/expected_config.php';
  91. }
  92. /**
  93. * @return array
  94. */
  95. private function getDefaultStyles()
  96. {
  97. return include __DIR__ . '/_files/default_styles.php';
  98. }
  99. /**
  100. * @return array
  101. */
  102. private function getAllowedFundings()
  103. {
  104. return include __DIR__ . '/_files/allowed_fundings.php';
  105. }
  106. }