2 namespace TYPO3\CMS\Frontend\Tests\Unit\Page;
34 $this->confCache = array(
35 'encryptionKey' =>
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey']
37 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'] =
't3lib_cacheHashTest';
38 $this->subject = $this->getMock(\TYPO3\CMS\Frontend\Page\CacheHashCalculator::class, array(
'foo'));
39 $this->subject->setConfiguration(array(
40 'excludedParameters' => array(
'exclude1',
'exclude2'),
41 'cachedParametersWhiteList' => array(),
42 'requireCacheHashPresenceParameters' => array(
'req1',
'req2'),
43 'excludedParametersIfEmpty' => array(),
44 'excludeAllEmptyParameters' =>
false
54 $this->assertEquals($expected, $this->subject->calculateCacheHash($params));
63 'Empty parameters should not return a hash' => array(
67 'Trivial key value combination should generate hash' => array(
69 'encryptionKey' =>
't3lib_cacheHashTest',
72 '5cfdcf826275558b3613dd51714a0a17'
74 'Multiple parameters should generate hash' => array(
78 'encryptionKey' =>
't3lib_cacheHashTest'
80 '0f40b089cdad149aea99e9bf4badaa93'
91 $actual = $this->subject->getRelevantParameters($params);
92 $this->assertEquals($expected, array_keys($actual));
101 'Empty list should be passed through' => array(
'', array()),
102 'Simple parameter should be passed through and the encryptionKey should be added' => array(
104 array(
'encryptionKey',
'key')
106 'Simple parameter should be passed through' => array(
108 array(
'encryptionKey',
'key1',
'key2')
110 'System and exclude parameters should be omitted' => array(
111 'id=1&type=3&exclude1=x&no_cache=1',
114 'System and exclude parameters should be omitted, others should stay' => array(
115 'id=1&type=3&key=x&no_cache=1',
116 array(
'encryptionKey',
'key')
127 $this->assertEquals($expected, $this->subject->generateForParameters($params));
135 $knowHash =
'5cfdcf826275558b3613dd51714a0a17';
137 'Empty parameters should not return an hash' => array(
'',
''),
138 'Querystring has no relevant parameters so we should not have a cacheHash' => array(
'&exclude1=val',
''),
139 'Querystring has only system parameters so we should not have a cacheHash' => array(
'id=1&type=val',
''),
140 'Trivial key value combination should generate hash' => array(
'&key=value', $knowHash),
141 'Only the relevant parts should be taken into account' => array(
'&key=value&exclude1=val', $knowHash),
142 'Only the relevant parts should be taken into account(exclude2 before key)' => array(
'&exclude2=val&key=value', $knowHash),
143 'System parameters should not be taken into account' => array(
'&id=1&key=value', $knowHash),
144 'Admin panel parameters should not be taken into account' => array(
'&TSFE_ADMIN_PANEL[display]=7&key=value', $knowHash),
145 'Trivial hash for sorted parameters should be right' => array(
'a=v&b=v',
'0f40b089cdad149aea99e9bf4badaa93'),
146 'Parameters should be sorted before is created' => array(
'b=v&a=v',
'0f40b089cdad149aea99e9bf4badaa93')
156 $this->assertEquals($expected, $this->subject->doParametersRequireCacheHash($params));
165 'Empty parameter strings should not require anything.' => array(
'',
false),
166 'Normal parameters aren\'t required.' => array(
'key=value',
false),
167 'Configured "req1" to be required.' => array(
'req1=value',
true),
168 'Configured "req1" to be required, should also work in combined context' => array(
'&key=value&req1=value',
true),
169 'Configured "req1" to be required, should also work in combined context (key at the end)' => array(
'req1=value&key=value',
true)
182 $method = new \ReflectionMethod(\TYPO3\CMS\Frontend\Page\CacheHashCalculator::class,
'setCachedParametersWhiteList');
183 $method->setAccessible(
true);
184 $method->invoke($this->subject, array(
'whitep1',
'whitep2'));
185 $this->assertEquals($expected, $this->subject->generateForParameters($params));
193 $oneParamHash =
'e2c0f2edf08be18bcff2f4272e11f66b';
194 $twoParamHash =
'f6f08c2e10a97d91b6ec61a6e2ddd0e7';
196 'Even with the whitelist enabled, empty parameters should not return an hash.' => array(
'',
''),
197 'Whitelisted parameters should have a hash.' => array(
'whitep1=value', $oneParamHash),
198 'Blacklisted parameter should not influence hash.' => array(
'whitep1=value&black=value', $oneParamHash),
199 'Multiple whitelisted parameters should work' => array(
'&whitep1=value&whitep2=value', $twoParamHash),
200 'The order should not influce the hash.' => array(
'whitep2=value&black=value&whitep1=value', $twoParamHash)
210 $this->subject->setConfiguration($settings);
211 $actual = $this->subject->getRelevantParameters($params);
212 $this->assertEquals($expected, array_keys($actual));
221 'The default configuration does not allow to skip an empty key.' => array(
222 'key1=v&key2=&key3=',
223 array(
'excludedParametersIfEmpty' => array(),
'excludeAllEmptyParameters' =>
false),
224 array(
'encryptionKey',
'key1',
'key2',
'key3')
226 'Due to the empty value, "key2" should be skipped(with equals sign' => array(
227 'key1=v&key2=&key3=',
228 array(
'excludedParametersIfEmpty' => array(
'key2'),
'excludeAllEmptyParameters' =>
false),
229 array(
'encryptionKey',
'key1',
'key3')
231 'Due to the empty value, "key2" should be skipped(without equals sign)' => array(
233 array(
'excludedParametersIfEmpty' => array(
'key2'),
'excludeAllEmptyParameters' =>
false),
234 array(
'encryptionKey',
'key1',
'key3')
236 'Due to the empty value, "key2" and "key3" should be skipped' => array(
237 'key1=v&key2=&key3=',
238 array(
'excludedParametersIfEmpty' => array(),
'excludeAllEmptyParameters' =>
true),
239 array(
'encryptionKey',
'key1')