TYPO3 CMS  TYPO3_8-7
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 
20 
21 class SessionManagerTest extends FunctionalTestCase
22 {
26  protected $subject;
27 
31  protected $testSessionRecords = [
32  [
33  'ses_id' => 'randomSessionId1',
34  'ses_userid' => 1,
35  ],
36  [
37  'ses_id' => 'randomSessionId2',
38  'ses_userid' => 1,
39  ],
40  [
41  'ses_id' => 'randomSessionId3',
42  'ses_userid' => 2,
43  ]
44  ];
45 
49  protected function setUp()
50  {
51  parent::setUp();
52  $this->subject = new SessionManager();
53  $frontendSessionBackend = $this->subject->getSessionBackend('FE');
54  foreach ($this->testSessionRecords as $testSessionRecord) {
55  $frontendSessionBackend->set($testSessionRecord['ses_id'], $testSessionRecord);
56  }
57  $backendSessionBackend = $this->subject->getSessionBackend('BE');
58  foreach ($this->testSessionRecords as $testSessionRecord) {
59  $backendSessionBackend->set($testSessionRecord['ses_id'], $testSessionRecord);
60  }
61  }
62 
67  {
68  $backendSessionBackend = $this->subject->getSessionBackend('BE');
69  $allActiveSessions = $backendSessionBackend->getAll();
70  $this->assertCount(3, $allActiveSessions);
71  $this->subject->invalidateAllSessionsByUserId($backendSessionBackend, 1);
72  $allActiveSessions = $backendSessionBackend->getAll();
73  $this->assertCount(1, $allActiveSessions);
74  $this->assertSame('randomSessionId3', $allActiveSessions[0]['ses_id']);
75  $this->assertSame(2, (int)$allActiveSessions[0]['ses_userid']);
76  }
77 
82  {
83  $frontendSessionBackend = $this->subject->getSessionBackend('FE');
84  $allActiveSessions = $frontendSessionBackend->getAll();
85  $this->assertCount(3, $allActiveSessions);
86  $this->subject->invalidateAllSessionsByUserId($frontendSessionBackend, 1);
87  $allActiveSessions = $frontendSessionBackend->getAll();
88  $this->assertCount(1, $allActiveSessions);
89  $this->assertSame('randomSessionId3', $allActiveSessions[0]['ses_id']);
90  $this->assertSame(2, (int)$allActiveSessions[0]['ses_userid']);
91  }
92 }