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