Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigTest.php
Go to the documentation of this file.
1 <?php
8 
13 
17 class ConfigTest extends \PHPUnit\Framework\TestCase
18 {
20  protected $config;
21 
24 
26  protected $scopeConfig;
27 
30 
32  protected $localeResolver;
33 
35  protected $dataStorage;
36 
40  protected $date;
41 
47  private $paymentMethodsList = [
48  'not_active_method' => ['active' => 0],
49  'active_method_no_model' => ['active' => 1],
50  'active_method' => ['active' => 1, 'model' => 'model_name'],
51  ];
52 
58  protected $monthList = [
59  1 => 'January',
60  'February',
61  'March',
62  'April',
63  'May',
64  'June',
65  'July',
66  'August',
67  'September',
68  'October',
69  'November',
70  'December',
71  ];
72 
78  protected $expectedMonthList = [
79  1 => '01 - January',
80  '02 - February',
81  '03 - March',
82  '04 - April',
83  '05 - May',
84  '06 - June',
85  '07 - July',
86  '08 - August',
87  '09 - September',
88  '10 - October',
89  '11 - November',
90  '12 - December',
91  ];
92 
96  const CURRENT_YEAR = '2250';
97 
98  protected function setUp()
99  {
100  $this->scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
101  $this->paymentMethodFactory = $this->createMock(\Magento\Payment\Model\Method\Factory::class);
102  $this->localeResolver = $this->createMock(\Magento\Framework\Locale\ResolverInterface::class);
103  $this->dataStorage = $this->createMock(\Magento\Framework\Config\DataInterface::class);
104  $this->date = $this->createMock(\Magento\Framework\Stdlib\DateTime\DateTime::class);
105 
106  $this->objectManagerHelper = new ObjectManagerHelper($this);
107  $this->config = $this->objectManagerHelper->getObject(
108  \Magento\Payment\Model\Config::class,
109  [
110  'scopeConfig' => $this->scopeConfig,
111  'paymentMethodFactory' => $this->paymentMethodFactory,
112  'localeResolver' => $this->localeResolver,
113  'dataStorage' => $this->dataStorage,
114  'date' => $this->date
115  ]
116  );
117  }
118 
124  public function testGetActiveMethods($isActive)
125  {
126  $adapter = $this->createMock(MethodInterface::class);
127  $this->scopeConfig->expects(static::once())
128  ->method('getValue')
129  ->with('payment', ScopeInterface::SCOPE_STORE, null)
130  ->willReturn($this->paymentMethodsList);
131  $this->paymentMethodFactory->expects(static::once())
132  ->method('create')
133  ->with($this->paymentMethodsList['active_method']['model'])
134  ->willReturn($adapter);
135  $adapter->expects(static::once())
136  ->method('setStore')
137  ->with(null);
138  $adapter->expects(static::once())
139  ->method('getConfigData')
140  ->with('active', static::isNull())
141  ->willReturn($isActive);
142  static::assertEquals($isActive ? ['active_method' => $adapter] : [], $this->config->getActiveMethods());
143  }
144 
149  {
150  return [[true], [false]];
151  }
152 
153  public function testGetCcTypes()
154  {
155  $expected = [];
156  $this->dataStorage->expects($this->once())->method('get')->with('credit_cards')->will(
157  $this->returnValue($expected)
158  );
159  $this->assertEquals($expected, $this->config->getCcTypes());
160  }
161 
162  public function testGetMethodsInfo()
163  {
164  $expected = [];
165  $this->dataStorage->expects($this->once())->method('get')->with('methods')->will(
166  $this->returnValue($expected)
167  );
168  $this->assertEquals($expected, $this->config->getMethodsInfo());
169  }
170 
171  public function testGetGroups()
172  {
173  $expected = [];
174  $this->dataStorage->expects($this->once())->method('get')->with('groups')->will(
175  $this->returnValue($expected)
176  );
177  $this->assertEquals($expected, $this->config->getGroups());
178  }
179 
180  public function testGetMonths()
181  {
182  $this->localeResolver->expects($this->once())->method('getLocale')->willReturn('en_US');
183  $this->assertEquals($this->expectedMonthList, $this->config->getMonths());
184  }
185 
186  public function testGetYears()
187  {
188  $this->date->expects($this->once())->method('date')->with('Y')->will($this->returnValue(self::CURRENT_YEAR));
189  $this->assertEquals($this->_getPreparedYearsList(), $this->config->getYears());
190  }
191 
197  private function _getPreparedYearsList()
198  {
199  $expectedYearsList = [];
200  for ($index = 0; $index <= Config::YEARS_RANGE; $index++) {
201  $year = (int)self::CURRENT_YEAR + $index;
202  $expectedYearsList[$year] = $year;
203  }
204  return $expectedYearsList;
205  }
206 }
$adapter
Definition: webapi_user.php:16
$index
Definition: list.phtml:44