ltsecurityinc安防产品在线商城代码
This commit is contained in:
+94
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Security\Model\ResourceModel\AdminSessionInfo;
|
||||
|
||||
use Magento\Framework\Stdlib\DateTime\DateTime;
|
||||
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection
|
||||
*/
|
||||
protected $collectionModel;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* Set up
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->collectionModel = $this->objectManager
|
||||
->create(\Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* updateActiveSessionsStatus() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/adminsession.php
|
||||
*/
|
||||
public function testUpdateActiveSessionsStatus()
|
||||
{
|
||||
$quantity = $this->collectionModel->updateActiveSessionsStatus(
|
||||
\Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_BY_LOGIN,
|
||||
1,
|
||||
'569e2277752e9'
|
||||
);
|
||||
$this->assertGreaterThanOrEqual(1, $quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* filterByUser() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/adminsession.php
|
||||
*/
|
||||
public function testFilterByUser()
|
||||
{
|
||||
$this->collectionModel->filterByUser(
|
||||
1,
|
||||
\Magento\Security\Model\AdminSessionInfo::LOGGED_IN,
|
||||
'569e2e3d752e9'
|
||||
);
|
||||
$this->collectionModel->load();
|
||||
$this->assertGreaterThanOrEqual(1, $this->collectionModel->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* filterExpiredSessions() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/adminsession.php
|
||||
*/
|
||||
public function testFilterExpiredSessions()
|
||||
{
|
||||
$startTime = strtotime('2016-01-19 15:42:13') - 1;
|
||||
$dateTime = $this->objectManager
|
||||
->get(DateTime::class);
|
||||
$currentTime = $dateTime->gmtTimestamp();
|
||||
$sessionLifetime = $currentTime - $startTime;
|
||||
|
||||
$this->collectionModel->filterExpiredSessions($sessionLifetime);
|
||||
$this->collectionModel->load();
|
||||
$this->assertGreaterThanOrEqual(1, $this->collectionModel->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteSessionsOlderThen() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/adminsession.php
|
||||
*/
|
||||
public function testDeleteSessionsOlderThen()
|
||||
{
|
||||
$startTime = strtotime('2016-01-19 15:42:13');
|
||||
$this->collectionModel->deleteSessionsOlderThen($startTime);
|
||||
$this->collectionModel->load();
|
||||
$this->assertGreaterThanOrEqual(1, $this->collectionModel->getSize());
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Security\Model\ResourceModel;
|
||||
|
||||
class AdminSessionInfoTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Model\AbstractModel
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->model = $this->objectManager->create(\Magento\Security\Model\AdminSessionInfo::class);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->objectManager = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test data for saving
|
||||
* @return array
|
||||
*/
|
||||
public function getTestData()
|
||||
{
|
||||
return [
|
||||
'user_id' => 1,
|
||||
'status' => 1,
|
||||
'created_at' => '2016-01-21 15:00:00',
|
||||
'updated_at' => '2016-01-21 18:00:00'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function saveTestData()
|
||||
{
|
||||
foreach ($this->getTestData() as $key => $value) {
|
||||
$this->model->setData($key, $value);
|
||||
}
|
||||
$this->model->save();
|
||||
return $this->model->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that model is saving data to database
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testIsModelSavingDataToDatabase()
|
||||
{
|
||||
$modelId = $this->saveTestData();
|
||||
$newModel = $this->model->load($modelId);
|
||||
$testData = $this->getTestData();
|
||||
$newModelData = [];
|
||||
foreach (array_keys($testData) as $key) {
|
||||
$newModelData[$key] = $newModel->getData($key);
|
||||
}
|
||||
$this->assertEquals($testData, $newModelData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for deleteSessionsOlderThen() method
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/adminsession.php
|
||||
*/
|
||||
public function testDeleteSessionsOlderThen()
|
||||
{
|
||||
$session = $this->objectManager->create(\Magento\Security\Model\AdminSessionInfo::class);
|
||||
/** @var $session \Magento\Security\Model\AdminSessionInfo */
|
||||
$session->getResource()->deleteSessionsOlderThen(strtotime('2016-01-20 12:00:00'));
|
||||
$collection = $session->getResourceCollection()
|
||||
->addFieldToFilter('main_table.updated_at', ['lt' => '2016-01-20 12:00:00'])
|
||||
->load();
|
||||
$count = $collection->count();
|
||||
$this->assertEquals(0, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for updateStatusByUserId() method
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/adminsession.php
|
||||
*/
|
||||
public function testUpdateStatusByUserId()
|
||||
{
|
||||
$session = $this->objectManager->create(\Magento\Security\Model\AdminSessionInfo::class);
|
||||
/** @var $session \Magento\Security\Model\AdminSessionInfo */
|
||||
$session->getResource()->updateStatusByUserId(
|
||||
\Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_BY_LOGIN,
|
||||
1,
|
||||
[1],
|
||||
[1],
|
||||
'2016-01-19 12:00:00'
|
||||
);
|
||||
$collection = $session->getResourceCollection()
|
||||
->addFieldToFilter('main_table.user_id', 1)
|
||||
->addFieldToFilter('main_table.status', \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_BY_LOGIN)
|
||||
->load();
|
||||
$count = $collection->count();
|
||||
$this->assertGreaterThanOrEqual(1, $count);
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Security\Model\ResourceModel\PasswordResetRequestEvent;
|
||||
|
||||
use Magento\Framework\Stdlib\DateTime\DateTime;
|
||||
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Security\Model\ResourceModel\PasswordResetRequestEvent\Collection
|
||||
*/
|
||||
protected $collectionModel;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* Set up
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->collectionModel = $this->objectManager
|
||||
->create(\Magento\Security\Model\ResourceModel\PasswordResetRequestEvent\Collection::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* filterByAccountReference() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/password_reset_request_events.php
|
||||
*/
|
||||
public function testFilterByAccountReference()
|
||||
{
|
||||
$this->collectionModel->filterByAccountReference('test27.dev@gmail.com')
|
||||
->load();
|
||||
|
||||
$this->assertEquals(1, $this->collectionModel->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* filterByIp() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/password_reset_request_events.php
|
||||
*/
|
||||
public function testFilterByIp()
|
||||
{
|
||||
$this->collectionModel->filterByIp('3232249856')
|
||||
->load();
|
||||
|
||||
$this->assertEquals(1, $this->collectionModel->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* filterByRequestType() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/password_reset_request_events.php
|
||||
*/
|
||||
public function testFilterByRequestType()
|
||||
{
|
||||
$this->collectionModel
|
||||
->filterByRequestType(\Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST)
|
||||
->load();
|
||||
|
||||
$this->assertGreaterThanOrEqual(3, $this->collectionModel->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* filterByLifetime() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/password_reset_request_events.php
|
||||
*/
|
||||
public function testFilterByLifetime()
|
||||
{
|
||||
$startTime = strtotime('2016-01-19 15:42:13') - 10;
|
||||
$dateTime = $this->objectManager
|
||||
->create(DateTime::class);
|
||||
$currentTime = $dateTime->gmtTimestamp();
|
||||
$sessionLifetime = $currentTime - $startTime;
|
||||
|
||||
$this->collectionModel->filterByLifetime($sessionLifetime)
|
||||
->load();
|
||||
|
||||
$this->assertGreaterThanOrEqual(1, $this->collectionModel->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* filterLastItem() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/password_reset_request_events.php
|
||||
*/
|
||||
public function testFilterLastItem()
|
||||
{
|
||||
$this->collectionModel->filterLastItem()
|
||||
->load();
|
||||
$this->assertEquals('2016-01-20 13:00:13', $this->collectionModel->getFirstItem()->getData('created_at'));
|
||||
}
|
||||
|
||||
/**
|
||||
* filterByIpOrAccountReference() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/password_reset_request_events.php
|
||||
*/
|
||||
public function testFilterByIpOrAccountReference()
|
||||
{
|
||||
$this->collectionModel->filterByIpOrAccountReference('3232249856', 'test273.dev@gmail.com')
|
||||
->load();
|
||||
$this->assertEquals(2, $this->collectionModel->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteRecordsOlderThen() test
|
||||
*
|
||||
* @magentoDataFixture Magento/Security/_files/password_reset_request_events.php
|
||||
*/
|
||||
public function testDeleteRecordsOlderThen()
|
||||
{
|
||||
$startTime = strtotime('2016-01-20 13:00:13');
|
||||
$this->collectionModel->deleteRecordsOlderThen($startTime)
|
||||
->load();
|
||||
$this->assertGreaterThanOrEqual(1, $this->collectionModel->getSize());
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Security\Model\ResourceModel;
|
||||
|
||||
/**
|
||||
* Class PasswordResetRequestEventTest
|
||||
* @package Magento\Security\Model
|
||||
*/
|
||||
class PasswordResetRequestEventTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Model\AbstractModel
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Security\Model\ResourceModel\PasswordResetRequestEvent
|
||||
*/
|
||||
protected $resourceModel;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->model = $this->objectManager->create(\Magento\Security\Model\PasswordResetRequestEvent::class);
|
||||
$this->resourceModel = $this->model->getResource();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->objectManager = null;
|
||||
$this->resourceModel = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test data
|
||||
* @return array
|
||||
*/
|
||||
public function getTestData()
|
||||
{
|
||||
return [
|
||||
'request_type' => \Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST,
|
||||
'account_reference' => 'test27.dev@gmail.com',
|
||||
'created_at' => '2016-01-20 13:00:13',
|
||||
'ip' => '3232249856'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving test data to database
|
||||
* @return mixed
|
||||
*/
|
||||
protected function saveTestData()
|
||||
{
|
||||
foreach ($this->getTestData() as $key => $value) {
|
||||
$this->model->setData($key, $value);
|
||||
}
|
||||
$this->model->save();
|
||||
return $this->model->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking that test data is saving to database
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testIsModelSavingDataToDatabase()
|
||||
{
|
||||
$modelId = $this->saveTestData();
|
||||
$newModel = $this->model->load($modelId);
|
||||
$testData = $this->getTestData();
|
||||
$newModelData = [];
|
||||
foreach (array_keys($testData) as $key) {
|
||||
$newModelData[$key] = $newModel->getData($key);
|
||||
}
|
||||
$this->assertEquals($testData, $newModelData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Security/_files/password_reset_request_events.php
|
||||
*/
|
||||
public function testDeleteRecordsOlderThen()
|
||||
{
|
||||
/** @var \Magento\Security\Model\PasswordResetRequestEvent $passwordResetRequestEvent */
|
||||
$countBefore = $this->model->getCollection()->count();
|
||||
$this->resourceModel->deleteRecordsOlderThen(strtotime('2016-01-20 12:00:00'));
|
||||
$countAfter = $this->model->getCollection()->count();
|
||||
$this->assertLessThan($countBefore, $countAfter);
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Security\Model\ResourceModel\UserExpiration;
|
||||
|
||||
/**
|
||||
* Test UserExpiration collection filters.
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Security\Model\ResourceModel\UserExpiration\CollectionFactory
|
||||
*/
|
||||
protected $collectionModelFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* Set up
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->collectionModelFactory = $this->objectManager
|
||||
->create(\Magento\Security\Model\ResourceModel\UserExpiration\CollectionFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Security/_files/expired_users.php
|
||||
*/
|
||||
public function testAddExpiredActiveUsersFilter()
|
||||
{
|
||||
/** @var \Magento\Security\Model\ResourceModel\UserExpiration\Collection $collectionModel */
|
||||
$collectionModel = $this->collectionModelFactory->create();
|
||||
$collectionModel->addActiveExpiredUsersFilter();
|
||||
static::assertEquals(1, $collectionModel->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Security/_files/expired_users.php
|
||||
*/
|
||||
public function testAddUserIdsFilter()
|
||||
{
|
||||
$adminUserNameFromFixture = 'adminUserExpired';
|
||||
$user = $this->objectManager->create(\Magento\User\Model\User::class);
|
||||
$user->loadByUsername($adminUserNameFromFixture);
|
||||
|
||||
/** @var \Magento\Security\Model\ResourceModel\UserExpiration\Collection $collectionModel */
|
||||
$collectionModel = $this->collectionModelFactory->create()->addUserIdsFilter([$user->getId()]);
|
||||
static::assertEquals(1, $collectionModel->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Security/_files/expired_users.php
|
||||
*/
|
||||
public function testAddExpiredRecordsForUserFilter()
|
||||
{
|
||||
$adminUserNameFromFixture = 'adminUserExpired';
|
||||
$user = $this->objectManager->create(\Magento\User\Model\User::class);
|
||||
$user->loadByUsername($adminUserNameFromFixture);
|
||||
|
||||
/** @var \Magento\Security\Model\ResourceModel\UserExpiration\Collection $collectionModel */
|
||||
$collectionModel = $this->collectionModelFactory->create()->addExpiredRecordsForUserFilter($user->getId());
|
||||
static::assertEquals(1, $collectionModel->getSize());
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Security\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Locale\ResolverInterface;
|
||||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
||||
use Magento\Security\Model\UserExpirationFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\User\Model\ResourceModel\User as UserResource;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Verify user expiration resource model.
|
||||
*/
|
||||
class UserExpirationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var UserExpiration
|
||||
*/
|
||||
private $userExpirationResource;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->userExpirationResource = Bootstrap::getObjectManager()->get(UserExpiration::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify user expiration saved with correct date.
|
||||
*
|
||||
* @magentoDataFixture Magento/User/_files/dummy_user.php
|
||||
* @dataProvider userExpirationSaveDataProvider
|
||||
* @magentoAppArea adminhtml
|
||||
* @return void
|
||||
*/
|
||||
public function testUserExpirationSave(string $locale): void
|
||||
{
|
||||
$localeResolver = Bootstrap::getObjectManager()->get(ResolverInterface::class);
|
||||
$timeZone = Bootstrap::getObjectManager()->get(TimezoneInterface::class);
|
||||
$localeResolver->setLocale($locale);
|
||||
$initialExpirationDate = $timeZone->date()->modify('+10 day');
|
||||
$expireDate = $timeZone->formatDateTime(
|
||||
$initialExpirationDate,
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
\IntlDateFormatter::MEDIUM
|
||||
);
|
||||
$userExpirationFactory = Bootstrap::getObjectManager()->get(UserExpirationFactory::class);
|
||||
$userExpiration = $userExpirationFactory->create();
|
||||
$userExpiration->setExpiresAt($expireDate);
|
||||
$userExpiration->setUserId($this->getUserId());
|
||||
$this->userExpirationResource->save($userExpiration);
|
||||
$loadedUserExpiration = $userExpirationFactory->create();
|
||||
$this->userExpirationResource->load($loadedUserExpiration, $userExpiration->getId());
|
||||
|
||||
self::assertEquals($initialExpirationDate->format('Y-m-d H:i:s'), $loadedUserExpiration->getExpiresAt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides locale codes for validation test.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function userExpirationSaveDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'default' => [
|
||||
'locale_code' => 'en_US',
|
||||
],
|
||||
'non_default_english_textual' => [
|
||||
'locale_code' => 'de_DE',
|
||||
],
|
||||
'non_default_non_english_textual' => [
|
||||
'locale_code' => 'uk_UA',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve user id from db.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function getUserId(): int
|
||||
{
|
||||
$userResource = Bootstrap::getObjectManager()->get(UserResource::class);
|
||||
$data = $userResource->loadByUsername('dummy_username');
|
||||
|
||||
return (int)$data['user_id'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user