‪TYPO3CMS  10.4
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 
21 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
22 
23 class ‪SessionManagerTest extends FunctionalTestCase
24 {
28  protected ‪$subject;
29 
33  protected ‪$testSessionRecords = [
34  'randomSessionId1' => [
35  // DatabaseSessionBackend::hash('randomSessionId1') with encryption key 12345
36  'ses_id' => 'e1ad65e4bad3c29e12c754c8e9f5927e',
37  'ses_userid' => 1,
38  ],
39  'randomSessionId2' => [
40  // DatabaseSessionBackend::hash('randomSessionId2') with encryption key 12345
41  'ses_id' => '72b1cf1fccc010ddb760c6db03f668db',
42  'ses_userid' => 1,
43  ],
44  'randomSessionId3' => [
45  // DatabaseSessionBackend::hash('randomSessionId3') with encryption key 12345
46  'ses_id' => '7ee0836849b95d884108486c4a8973f3',
47  'ses_userid' => 2,
48  ]
49  ];
50 
54  protected function ‪setUp(): void
55  {
56  parent::setUp();
57  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '12345';
58 
59  $this->subject = new ‪SessionManager();
60  $frontendSessionBackend = $this->subject->getSessionBackend('FE');
61  foreach ($this->testSessionRecords as $sessionId => $testSessionRecord) {
62  $frontendSessionBackend->set($sessionId, $testSessionRecord);
63  }
64  $backendSessionBackend = $this->subject->getSessionBackend('BE');
65  foreach ($this->testSessionRecords as $sessionId => $testSessionRecord) {
66  $backendSessionBackend->set($sessionId, $testSessionRecord);
67  }
68  }
69 
74  {
75  $backendSessionBackend = $this->subject->getSessionBackend('BE');
76  $allActiveSessions = $backendSessionBackend->getAll();
77  self::assertCount(3, $allActiveSessions);
78  $this->subject->invalidateAllSessionsByUserId($backendSessionBackend, 1);
79  $allActiveSessions = $backendSessionBackend->getAll();
80  self::assertCount(1, $allActiveSessions);
81  self::assertSame($this->testSessionRecords['randomSessionId3']['ses_id'], $allActiveSessions[0]['ses_id']);
82  self::assertSame(2, (int)$allActiveSessions[0]['ses_userid']);
83  }
84 
89  {
90  $frontendSessionBackend = $this->subject->getSessionBackend('FE');
91  $allActiveSessions = $frontendSessionBackend->getAll();
92  self::assertCount(3, $allActiveSessions);
93  $this->subject->invalidateAllSessionsByUserId($frontendSessionBackend, 1);
94  $allActiveSessions = $frontendSessionBackend->getAll();
95  self::assertCount(1, $allActiveSessions);
96  self::assertSame($this->testSessionRecords['randomSessionId3']['ses_id'], $allActiveSessions[0]['ses_id']);
97  self::assertSame(2, (int)$allActiveSessions[0]['ses_userid']);
98  }
99 }
‪TYPO3\CMS\Core\Tests\Functional\Session
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:39
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest\clearAllSessionsByUserIdDestroyAllSessionsForBackend
‪clearAllSessionsByUserIdDestroyAllSessionsForBackend()
Definition: SessionManagerTest.php:71
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest\$testSessionRecords
‪array $testSessionRecords
Definition: SessionManagerTest.php:31
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest
Definition: SessionManagerTest.php:24
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest\$subject
‪SessionManager $subject
Definition: SessionManagerTest.php:27
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest\setUp
‪setUp()
Definition: SessionManagerTest.php:52
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Functional\Session\SessionManagerTest\clearAllSessionsByUserIdDestroyAllSessionsForFrontend
‪clearAllSessionsByUserIdDestroyAllSessionsForFrontend()
Definition: SessionManagerTest.php:86