TYPO3 CMS  TYPO3_8-7
SplitStorageTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
24 class SplitStorageTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
25 {
31  protected $xmlDatabaseFixtures = [
32  'typo3/sysext/rsaauth/Tests/Functional/Fixtures/tx_rsaauth_keys.xml'
33  ];
34 
40  protected $testExtensionsToLoad = [
41  'typo3/sysext/rsaauth'
42  ];
43 
47  protected $subject;
48 
52  protected $testKey = '666cb6d79dc65973df67571bbdc5beca';
53 
57  protected $testKeyLeftPart = '666cb6d79dc65973';
58 
62  protected $testKeyRightPart = 'df67571bbdc5beca';
63 
67  protected function setUp()
68  {
69  parent::setUp();
70  foreach ($this->xmlDatabaseFixtures as $fixture) {
71  $this->importDataSet($fixture);
72  }
73  $this->subject = GeneralUtility::makeInstance(SplitStorage::class);
74  // same timestamp as in Fixtures/tx_rsaauth_keys.xml
75  $GLOBALS['EXEC_TIME'] = 1465391843;
76  $_SESSION['tx_rsaauth_key'] = [1, $this->testKeyLeftPart];
77  }
78 
82  public function getReturnsKeyFromDatabase()
83  {
84  $key = $this->subject->get();
85  $this->assertEquals($this->testKey, $key);
86  }
87 
91  public function putInsertsKeyIntoDatabase()
92  {
93  $this->subject->put($this->testKey);
94  $this->assertEquals($this->testKey, $this->subject->get());
95  }
96 
101  {
102  $outDatedKeyId = 3;
103  $_SESSION['tx_rsaauth_key'] = [1, $this->testKeyLeftPart];
104 
105  $key = GeneralUtility::makeInstance(ConnectionPool::class)
106  ->getConnectionForTable('tx_rsaauth_keys')
107  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
108  ->fetchColumn();
109 
110  $this->assertEquals($this->testKeyRightPart, $key);
111 
112  $this->subject->get();
113 
114  $key = GeneralUtility::makeInstance(ConnectionPool::class)
115  ->getConnectionForTable('tx_rsaauth_keys')
116  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
117  ->fetchColumn();
118 
119  $this->assertFalse($key);
120  }
121 
126  {
127  $outDatedKeyId = 3;
128  $_SESSION['tx_rsaauth_key'] = [1, $this->testKeyLeftPart];
129 
130  $key = GeneralUtility::makeInstance(ConnectionPool::class)
131  ->getConnectionForTable('tx_rsaauth_keys')
132  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
133  ->fetchColumn();
134 
135  $this->assertEquals($this->testKeyRightPart, $key);
136 
137  $this->subject->put('testkey');
138 
139  $key = GeneralUtility::makeInstance(ConnectionPool::class)
140  ->getConnectionForTable('tx_rsaauth_keys')
141  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
142  ->fetchColumn();
143 
144  $this->assertFalse($key);
145  }
146 
151  {
152  $keyToBeDeleted = 1;
153  $_SESSION['tx_rsaauth_key'] = [$keyToBeDeleted, $this->testKeyLeftPart];
154 
155  $key = GeneralUtility::makeInstance(ConnectionPool::class)
156  ->getConnectionForTable('tx_rsaauth_keys')
157  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $keyToBeDeleted])
158  ->fetchColumn();
159 
160  $this->assertEquals($this->testKeyRightPart, $key);
161 
162  $this->subject->put(null);
163 
164  $key = GeneralUtility::makeInstance(ConnectionPool::class)
165  ->getConnectionForTable('tx_rsaauth_keys')
166  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $keyToBeDeleted])
167  ->fetchColumn();
168 
169  $this->assertFalse($key);
170  }
171 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']