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
7 
9 
13 class ConfigTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $scopeConfigMock;
19 
23  protected $scopeMock;
24 
28  protected $model;
29 
34  protected function setUp()
35  {
36  $this->scopeConfigMock = $this->createPartialMock(
37  \Magento\Framework\App\Config\ScopeConfigInterface::class,
38  ['getValue', 'isSetFlag']
39  );
40 
41  $this->scopeMock = $this->createMock(\Magento\Framework\Config\ScopeInterface::class);
42 
43  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
44  $this->model = $objectManager->getObject(
45  \Magento\Security\Model\Config::class,
46  [
47  'scopeConfig' => $this->scopeConfigMock,
48  'scope' => $this->scopeMock
49  ]
50  );
51  }
52 
53  public function testGetLimitationTimePeriod()
54  {
55  $this->assertEquals(
56  \Magento\Security\Model\Config::LIMITATION_TIME_PERIOD,
57  $this->model->getLimitationTimePeriod()
58  );
59  }
60 
65  public function testGetCustomerServiceEmail()
66  {
68  $this->scopeConfigMock->expects($this->once())
69  ->method('getValue')
70  ->with(
71  \Magento\Security\Model\Config::XML_PATH_EMAIL_RECIPIENT,
72  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
73  )
74  ->will(
75  $this->returnValue($email)
76  );
77  $this->assertEquals($email, $this->model->getCustomerServiceEmail());
78  }
79 
84  public function testGetAdminSessionLifetime()
85  {
86  $lifetime = 10;
87  $this->scopeConfigMock->expects($this->once())
88  ->method('getValue')
89  ->with(\Magento\Backend\Model\Auth\Session::XML_PATH_SESSION_LIFETIME)
90  ->will(
91  $this->returnValue($lifetime)
92  );
93  $this->assertEquals($lifetime, $this->model->getAdminSessionLifetime());
94  }
95 
100  public function testIsAdminAccountSharingIsEnabled($isShared)
101  {
102  $this->scopeConfigMock->expects($this->once())
103  ->method('isSetFlag')
104  ->with(\Magento\Security\Model\Config::XML_PATH_ADMIN_ACCOUNT_SHARING)
105  ->will(
106  $this->returnValue($isShared)
107  );
108  $this->assertEquals($isShared, $this->model->isAdminAccountSharingEnabled());
109  }
110 
114  public function dataProviderBoolValues()
115  {
116  return [[true], [false]];
117  }
118 
124  public function testGetPasswordResetProtectionType($resetMethod, $scope)
125  {
126  $this->scopeConfigMock->expects($this->once())
127  ->method('getValue')
128  ->with(
129  $this->getXmlPathPrefix($scope)
130  . \Magento\Security\Model\Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE
131  )
132  ->willReturn($resetMethod);
133  $this->scopeMock->expects($this->once())
134  ->method('getCurrentScope')
135  ->willReturn($scope);
136  $this->assertEquals($resetMethod, $this->model->getPasswordResetProtectionType($scope));
137  }
138 
143  {
144  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
145  $resetMethodSource = $objectManager->getObject(
146  \Magento\Security\Model\Config\Source\ResetMethod::class
147  );
148 
149  $optionKeys = array_keys($resetMethodSource->toArray());
150  $data = [];
151  foreach ($optionKeys as $key) {
154  }
155 
156  return $data;
157  }
158 
165  protected function getXmlPathPrefix($scope)
166  {
167  if ($scope == \Magento\Framework\App\Area::AREA_ADMINHTML) {
168  return \Magento\Security\Model\Config::XML_PATH_ADMIN_AREA;
169  }
170  return \Magento\Security\Model\Config::XML_PATH_FRONTEND_AREA;
171  }
172 
178  public function testGetMaxNumberPasswordResetRequests($limitNumber, $scope)
179  {
180  $this->scopeConfigMock->expects($this->once())
181  ->method('getValue')
182  ->with(
183  $this->getXmlPathPrefix($scope)
184  . \Magento\Security\Model\Config::XML_PATH_MAX_NUMBER_PASSWORD_RESET_REQUESTS
185  )
186  ->willReturn($limitNumber);
187  $this->scopeMock->expects($this->once())
188  ->method('getCurrentScope')
189  ->willReturn($scope);
190  $this->assertEquals($limitNumber, $this->model->getMaxNumberPasswordResetRequests());
191  }
192 
198  public function testGetMinTimeBetweenPasswordResetRequests($limitTime, $scope)
199  {
200  $this->scopeConfigMock->expects($this->once())
201  ->method('getValue')
202  ->with(
203  $this->getXmlPathPrefix($scope)
204  . \Magento\Security\Model\Config::XML_PATH_MIN_TIME_BETWEEN_PASSWORD_RESET_REQUESTS
205  )
206  ->willReturn($limitTime);
207  $this->scopeMock->expects($this->once())
208  ->method('getCurrentScope')
209  ->willReturn($scope);
210  $this->assertEquals($limitTime * 60, $this->model->getMinTimeBetweenPasswordResetRequests());
211  }
212 
217  {
218  return [
221  ];
222  }
223 }
$objectManager
Definition: bootstrap.php:17
$email
Definition: details.phtml:13
testGetMinTimeBetweenPasswordResetRequests($limitTime, $scope)
Definition: ConfigTest.php:198
testGetMaxNumberPasswordResetRequests($limitNumber, $scope)
Definition: ConfigTest.php:178
testGetPasswordResetProtectionType($resetMethod, $scope)
Definition: ConfigTest.php:124