123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Security\Test\Unit\Model;
- use Magento\Security\Model\ConfigInterface;
- /**
- * Test class for \Magento\Security\Model\Config testing
- */
- class ConfigTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
- */
- protected $scopeConfigMock;
- /**
- * @var \Magento\Framework\Config\ScopeInterface
- */
- protected $scopeMock;
- /**
- * @var ConfigInterface
- */
- protected $model;
- /**
- * Init mocks for tests
- * @return void
- */
- protected function setUp()
- {
- $this->scopeConfigMock = $this->createPartialMock(
- \Magento\Framework\App\Config\ScopeConfigInterface::class,
- ['getValue', 'isSetFlag']
- );
- $this->scopeMock = $this->createMock(\Magento\Framework\Config\ScopeInterface::class);
- $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->model = $objectManager->getObject(
- \Magento\Security\Model\Config::class,
- [
- 'scopeConfig' => $this->scopeConfigMock,
- 'scope' => $this->scopeMock
- ]
- );
- }
- public function testGetLimitationTimePeriod()
- {
- $this->assertEquals(
- \Magento\Security\Model\Config::LIMITATION_TIME_PERIOD,
- $this->model->getLimitationTimePeriod()
- );
- }
- /**
- * Test get customer service email
- * @return void
- */
- public function testGetCustomerServiceEmail()
- {
- $email = 'test@example.com';
- $this->scopeConfigMock->expects($this->once())
- ->method('getValue')
- ->with(
- \Magento\Security\Model\Config::XML_PATH_EMAIL_RECIPIENT,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
- )
- ->will(
- $this->returnValue($email)
- );
- $this->assertEquals($email, $this->model->getCustomerServiceEmail());
- }
- /**
- * Test get admin session lifetime
- * @return void
- */
- public function testGetAdminSessionLifetime()
- {
- $lifetime = 10;
- $this->scopeConfigMock->expects($this->once())
- ->method('getValue')
- ->with(\Magento\Backend\Model\Auth\Session::XML_PATH_SESSION_LIFETIME)
- ->will(
- $this->returnValue($lifetime)
- );
- $this->assertEquals($lifetime, $this->model->getAdminSessionLifetime());
- }
- /**
- * @param bool $isShared
- * @dataProvider dataProviderBoolValues
- */
- public function testIsAdminAccountSharingIsEnabled($isShared)
- {
- $this->scopeConfigMock->expects($this->once())
- ->method('isSetFlag')
- ->with(\Magento\Security\Model\Config::XML_PATH_ADMIN_ACCOUNT_SHARING)
- ->will(
- $this->returnValue($isShared)
- );
- $this->assertEquals($isShared, $this->model->isAdminAccountSharingEnabled());
- }
- /**
- * @return array
- */
- public function dataProviderBoolValues()
- {
- return [[true], [false]];
- }
- /**
- * @param int $resetMethod
- * @param int $scope
- * @dataProvider dataProviderResetMethodValues
- */
- public function testGetPasswordResetProtectionType($resetMethod, $scope)
- {
- $this->scopeConfigMock->expects($this->once())
- ->method('getValue')
- ->with(
- $this->getXmlPathPrefix($scope)
- . \Magento\Security\Model\Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE
- )
- ->willReturn($resetMethod);
- $this->scopeMock->expects($this->once())
- ->method('getCurrentScope')
- ->willReturn($scope);
- $this->assertEquals($resetMethod, $this->model->getPasswordResetProtectionType($scope));
- }
- /**
- * @return array
- */
- public function dataProviderResetMethodValues()
- {
- $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $resetMethodSource = $objectManager->getObject(
- \Magento\Security\Model\Config\Source\ResetMethod::class
- );
- $optionKeys = array_keys($resetMethodSource->toArray());
- $data = [];
- foreach ($optionKeys as $key) {
- $data[] = [$key, \Magento\Framework\App\Area::AREA_ADMINHTML];
- $data[] = [$key, \Magento\Framework\App\Area::AREA_FRONTEND];
- }
- return $data;
- }
- /**
- * Get xml path by scope
- *
- * @param int $scope
- * @return string
- */
- protected function getXmlPathPrefix($scope)
- {
- if ($scope == \Magento\Framework\App\Area::AREA_ADMINHTML) {
- return \Magento\Security\Model\Config::XML_PATH_ADMIN_AREA;
- }
- return \Magento\Security\Model\Config::XML_PATH_FRONTEND_AREA;
- }
- /**
- * @param int $limitNumber
- * @param int $scope
- * @dataProvider dataProviderNumberValueWithScope
- */
- public function testGetMaxNumberPasswordResetRequests($limitNumber, $scope)
- {
- $this->scopeConfigMock->expects($this->once())
- ->method('getValue')
- ->with(
- $this->getXmlPathPrefix($scope)
- . \Magento\Security\Model\Config::XML_PATH_MAX_NUMBER_PASSWORD_RESET_REQUESTS
- )
- ->willReturn($limitNumber);
- $this->scopeMock->expects($this->once())
- ->method('getCurrentScope')
- ->willReturn($scope);
- $this->assertEquals($limitNumber, $this->model->getMaxNumberPasswordResetRequests());
- }
- /**
- * @param int $limitTime
- * @param int $scope
- * @dataProvider dataProviderNumberValueWithScope
- */
- public function testGetMinTimeBetweenPasswordResetRequests($limitTime, $scope)
- {
- $this->scopeConfigMock->expects($this->once())
- ->method('getValue')
- ->with(
- $this->getXmlPathPrefix($scope)
- . \Magento\Security\Model\Config::XML_PATH_MIN_TIME_BETWEEN_PASSWORD_RESET_REQUESTS
- )
- ->willReturn($limitTime);
- $this->scopeMock->expects($this->once())
- ->method('getCurrentScope')
- ->willReturn($scope);
- $this->assertEquals($limitTime * 60, $this->model->getMinTimeBetweenPasswordResetRequests());
- }
- /**
- * @return array
- */
- public function dataProviderNumberValueWithScope()
- {
- return [
- [5, \Magento\Framework\App\Area::AREA_ADMINHTML],
- [5, \Magento\Framework\App\Area::AREA_FRONTEND]
- ];
- }
- }
|