2 declare(strict_types = 1);
21 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
38 'ses_id' =>
'76898588caa1baee7984f4dc8adfed3b',
41 'ses_data' =>
'a:2:{s:3:"foo";s:3:"bar";s:3:"boo";s:3:"far";}',
47 protected function setUp()
50 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'] =
'12345';
53 $this->subject->initialize(
'default', [
54 'table' =>
'fe_sessions',
55 'has_anonymous' =>
true,
64 $this->subject->validateConfiguration();
73 $record = $this->subject->set(
'randomSessionId', $this->testSessionRecord);
75 $expected = array_merge($this->testSessionRecord, [
'ses_tstamp' =>
$GLOBALS[
'EXEC_TIME']]);
77 $this->assertEquals($record, $expected);
78 $this->assertArraySubset($expected, $this->subject->get(
'randomSessionId'));
86 $record = $this->subject->set(
'randomSessionId', array_merge($this->testSessionRecord, [
'ses_anonymous' => 1]));
88 $expected = array_merge($this->testSessionRecord, [
'ses_anonymous' => 1,
'ses_tstamp' =>
$GLOBALS[
'EXEC_TIME']]);
90 $this->assertEquals($record, $expected);
91 $this->assertArraySubset($expected, $this->subject->get(
'randomSessionId'));
100 $this->expectException(SessionNotFoundException::class);
101 $this->expectExceptionCode(1481885483);
102 $this->subject->get(
'IDoNotExist');
111 $this->subject->set(
'randomSessionId', $this->testSessionRecord);
114 'ses_data' => serialize([
'foo' =>
'baz',
'idontwantto' =>
'set the world on fire']),
117 $expectedMergedData = array_merge($this->testSessionRecord, $updateData);
118 $this->subject->update(
'randomSessionId', $updateData);
119 $fetchedRecord = $this->subject->get(
'randomSessionId');
120 $this->assertArraySubset($expectedMergedData, $fetchedRecord);
129 $this->expectException(SessionNotCreatedException::class);
130 $this->expectExceptionCode(1481895005);
132 $this->subject->set(
'randomSessionId', $this->testSessionRecord);
134 $newData = array_merge($this->testSessionRecord, [
'ses_data' => serialize([
'foo' =>
'baz',
'idontwantto' =>
'set the world on fire'])]);
135 $this->subject->set(
'randomSessionId', $newData);
144 $this->subject->set(
'randomSessionId', $this->testSessionRecord);
146 $newSessionId =
'newRandomSessionId';
148 $newData[
'ses_id'] = $newSessionId;
151 $this->subject->get(
'randomSessionId');
154 $this->subject->update(
'randomSessionId', $newData);
157 $this->expectException(SessionNotFoundException::class);
158 $this->expectExceptionCode(1481885483);
159 $this->subject->get(
'newRandomSessionId');
168 $this->subject->set(
'randomSessionId', $this->testSessionRecord);
171 $this->assertTrue($this->subject->remove(
'randomSessionId'));
174 $this->expectException(SessionNotFoundException::class);
175 $this->expectExceptionCode(1481885483);
176 $this->subject->get(
'randomSessionId');
185 $this->subject->set(
'randomSessionId', $this->testSessionRecord);
186 $this->subject->set(
'randomSessionId2', $this->testSessionRecord);
189 $this->assertEquals(2, count($this->subject->getAll()));
198 $authenticatedSession = array_merge($this->testSessionRecord, [
'ses_id' =>
'authenticatedSession']);
199 $anonymousSession = array_merge($this->testSessionRecord, [
'ses_id' =>
'anonymousSession',
'ses_anonymous' => 1]);
201 $this->subject->set(
'authenticatedSession', $authenticatedSession);
202 $this->subject->set(
'anonymousSession', $anonymousSession);
206 $authenticatedSession[
'ses_data'],
207 $this->subject->get(
'authenticatedSession')[
'ses_data']
212 $anonymousSession[
'ses_data'],
213 $this->subject->get(
'anonymousSession')[
'ses_data']
219 $this->subject->collectGarbage(60, 10);
223 $authenticatedSession[
'ses_data'],
224 $this->subject->get(
'authenticatedSession')[
'ses_data']
228 $this->expectException(SessionNotFoundException::class);
229 $this->expectExceptionCode(1481885483);
230 $this->subject->get(
'anonymousSession');
238 $updatedRecord = array_merge(
239 $this->testSessionRecord,
242 $sessionId =
'randomSessionId';
243 $this->subject->set($sessionId, $this->testSessionRecord);
244 $this->subject->update($sessionId, []);
245 $this->assertArraySubset($updatedRecord, $this->subject->get($sessionId));