‪TYPO3CMS  ‪main
SessionManagerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
22 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23 
24 final class ‪SessionManagerTest extends FunctionalTestCase
25 {
29  protected ‪$subject;
30 
34  protected ‪$testSessionRecords = [
35  'randomSessionId1' => [
36  // DatabaseSessionBackend::hash('randomSessionId1') with encryption key 12345
37  'ses_id' => '92728358061fb01f95498e33ec4661e1edac4b59c18a06f2f80047747c749515',
38  'ses_userid' => 1,
39  ],
40  'randomSessionId2' => [
41  // DatabaseSessionBackend::hash('randomSessionId2') with encryption key 12345
42  'ses_id' => '531b1305780519abe3e2c6b8857d2efc51ed1944242a597c0b2dd76f94876897',
43  'ses_userid' => 1,
44  ],
45  'randomSessionId3' => [
46  // DatabaseSessionBackend::hash('randomSessionId3') with encryption key 12345
47  'ses_id' => '696a4c67e53a429327c82f09eaf20b2c634deed68a96d5c1d6cc28cf3d009654',
48  'ses_userid' => 2,
49  ],
50  ];
51 
55  protected function ‪setUp(): void
56  {
57  parent::setUp();
58  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '12345';
59 
60  $this->subject = new ‪SessionManager();
61  $frontendSessionBackend = $this->subject->getSessionBackend('FE');
62  foreach ($this->testSessionRecords as $sessionId => $testSessionRecord) {
63  $frontendSessionBackend->set($sessionId, $testSessionRecord);
64  }
65  $backendSessionBackend = $this->subject->getSessionBackend('BE');
66  foreach ($this->testSessionRecords as $sessionId => $testSessionRecord) {
67  $backendSessionBackend->set($sessionId, $testSessionRecord);
68  }
69  }
70 
71  #[Test]
73  {
74  $backendSessionBackend = $this->subject->getSessionBackend('BE');
75  $allActiveSessions = $backendSessionBackend->getAll();
76  self::assertCount(3, $allActiveSessions);
77  $this->subject->invalidateAllSessionsByUserId($backendSessionBackend, 1);
78  $allActiveSessions = $backendSessionBackend->getAll();
79  self::assertCount(1, $allActiveSessions);
80  self::assertSame($this->testSessionRecords['randomSessionId3']['ses_id'], $allActiveSessions[0]['ses_id']);
81  self::assertSame(2, (int)$allActiveSessions[0]['ses_userid']);
82  }
83 
84  #[Test]
86  {
87  $frontendSessionBackend = $this->subject->getSessionBackend('FE');
88  $allActiveSessions = $frontendSessionBackend->getAll();
89  self::assertCount(3, $allActiveSessions);
90  $this->subject->invalidateAllSessionsByUserId($frontendSessionBackend, 1);
91  $allActiveSessions = $frontendSessionBackend->getAll();
92  self::assertCount(1, $allActiveSessions);
93  self::assertSame($this->testSessionRecords['randomSessionId3']['ses_id'], $allActiveSessions[0]['ses_id']);
94  self::assertSame(2, (int)$allActiveSessions[0]['ses_userid']);
95  }
96 }
‪TYPO3\CMS\Core\Tests\Functional\Session
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:41
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest\clearAllSessionsByUserIdDestroyAllSessionsForBackend
‪clearAllSessionsByUserIdDestroyAllSessionsForBackend()
Definition: SessionManagerTest.php:70
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest\$testSessionRecords
‪array $testSessionRecords
Definition: SessionManagerTest.php:32
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest
Definition: SessionManagerTest.php:25
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest\$subject
‪SessionManager $subject
Definition: SessionManagerTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest\setUp
‪setUp()
Definition: SessionManagerTest.php:53
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest\clearAllSessionsByUserIdDestroyAllSessionsForFrontend
‪clearAllSessionsByUserIdDestroyAllSessionsForFrontend()
Definition: SessionManagerTest.php:83