/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
dev/tests/integration/testsuite/Magento/Security/Model/ResourceModel/AdminSessionInfoTest.php
116 строк
3 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 10:44
22 окт 2025, 10:44
264bea2
Код
Авторство
О чём код?
<?php /** * Copyright 2016 Adobe * All Rights Reserved. */ 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); } }