2 declare(strict_types = 1);
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
35 'excludedParameters' => [
'exclude1',
'exclude2'],
36 'cachedParametersWhiteList' => [],
37 'requireCacheHashPresenceParameters' => [
'req1',
'req2'],
38 'excludedParametersIfEmpty' => [],
39 'excludeAllEmptyParameters' => false
42 protected function setUp()
44 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'] =
't3lib_cacheHashTest';
50 unset($this->subject);
60 self::assertEquals($expected, $this->subject->calculateCacheHash($params));
69 'Empty parameters should not return a hash' => [
73 'Trivial key value combination should generate hash' => [
75 'encryptionKey' =>
't3lib_cacheHashTest',
78 '5cfdcf826275558b3613dd51714a0a17'
80 'Multiple parameters should generate hash' => [
84 'encryptionKey' =>
't3lib_cacheHashTest'
86 '0f40b089cdad149aea99e9bf4badaa93'
97 $actual = $this->subject->getRelevantParameters($params);
98 self::assertEquals($expected, array_keys($actual));
107 'Empty list should be passed through' => [
'', []],
108 'Simple parameter should be passed through and the encryptionKey should be added' => [
110 [
'encryptionKey',
'id',
'key']
112 'Simple parameter should be passed through' => [
113 'key1=v&key2=v&id=42',
114 [
'encryptionKey',
'id',
'key1',
'key2']
116 'System and exclude parameters should be omitted' => [
117 'id=1&type=3&exclude1=x&no_cache=1',
120 'System and exclude parameters (except id) should be omitted, others should stay' => [
121 'id=1&type=3&key=x&no_cache=1',
122 [
'encryptionKey',
'id',
'key']
124 'System and exclude parameters should be omitted and id is not required to be specified' => [
137 self::assertEquals($expected, $this->subject->generateForParameters($params));
147 $this->subject->generateForParameters(
'&key=x');
155 $knowHash =
'fac112f7e662c83c19b57142c3a921f5';
157 'Empty parameters should not return an hash' => [
'&id=42',
''],
158 'Querystring has no relevant parameters so we should not have a cacheHash' => [
'&exclude1=val',
''],
159 'Querystring has only system parameters so we should not have a cacheHash' => [
'&id=42&type=val',
''],
160 'Trivial key value combination should generate hash' => [
'&id=42&key=value', $knowHash],
161 'Only the relevant parts should be taken into account' => [
'&id=42&key=value&exclude1=val', $knowHash],
162 'Only the relevant parts should be taken into account(exclude2 before key)' => [
'&id=42&exclude2=val&key=value', $knowHash],
163 'System parameters should not be taken into account (except id)' => [
'&id=42&type=23&key=value', $knowHash],
164 'Admin panel parameters should not be taken into account' => [
'&id=42&TSFE_ADMIN_PANEL[display]=7&key=value', $knowHash],
165 'Trivial hash for sorted parameters should be right' => [
'&id=42&a=v&b=v',
'52c8a1299e20324f90377c43153c4987'],
166 'Parameters should be sorted before cHash is created' => [
'&id=42&b=v&a=v',
'52c8a1299e20324f90377c43153c4987'],
167 'Empty argument names are filtered out before cHash calculation' => [
'&id=42&b=v&a=v&=dummy',
'52c8a1299e20324f90377c43153c4987']
177 self::assertEquals($expected, $this->subject->doParametersRequireCacheHash($params));
186 'Empty parameter strings should not require anything.' => [
'',
false],
187 'Normal parameters aren\'t required.' => [
'key=value',
false],
188 'Configured "req1" to be required.' => [
'req1=value',
true],
189 'Configured "req1" to be required, should also work in combined context' => [
'&key=value&req1=value',
true],
190 'Configured "req1" to be required, should also work in combined context (key at the end)' => [
'req1=value&key=value',
true]
204 'cachedParametersWhiteList' => [
'whitep1',
'whitep2']
207 self::assertEquals($expected, $this->subject->generateForParameters($params));
215 $oneParamHash =
'eae50a13101afd53a9d2c543230eb5bb';
216 $twoParamHash =
'701e2d2f1becc9d1b71d327e5cb1c3ed';
218 'Even with the whitelist enabled, empty parameters should not return an hash.' => [
'',
''],
219 'Whitelisted parameters should have a hash.' => [
'&id=42&whitep1=value', $oneParamHash],
220 'Blacklisted parameter should not influence hash.' => [
'&id=42&whitep1=value&black=value', $oneParamHash],
221 'Multiple whitelisted parameters should work' => [
'&id=42&whitep1=value&whitep2=value', $twoParamHash],
222 'The order should not influce the hash.' => [
'&id=42&whitep2=value&black=value&whitep1=value', $twoParamHash]
232 $this->subject->setConfiguration($settings);
233 $actual = $this->subject->getRelevantParameters($params);
234 self::assertEquals($expected, array_keys($actual));
243 'The default configuration does not allow to skip an empty key.' => [
244 '&id=42&key1=v&key2=&key3=',
245 [
'excludedParametersIfEmpty' => [],
'excludeAllEmptyParameters' =>
false],
246 [
'encryptionKey',
'id',
'key1',
'key2',
'key3']
248 'Due to the empty value, "key2" should be skipped(with equals sign' => [
249 '&id=42&key1=v&key2=&key3=',
250 [
'excludedParametersIfEmpty' => [
'key2'],
'excludeAllEmptyParameters' =>
false],
251 [
'encryptionKey',
'id',
'key1',
'key3']
253 'Due to the empty value, "key2" should be skipped(without equals sign)' => [
254 '&id=42&key1=v&key2&key3',
255 [
'excludedParametersIfEmpty' => [
'key2'],
'excludeAllEmptyParameters' =>
false],
256 [
'encryptionKey',
'id',
'key1',
'key3']
258 'Due to the empty value, "key2" and "key3" should be skipped' => [
259 '&id=42&key1=v&key2=&key3=',
260 [
'excludedParametersIfEmpty' => [],
'excludeAllEmptyParameters' =>
true],
261 [
'encryptionKey',
'id',
'key1']