diff --git a/typo3/sysext/frontend/Classes/Page/CacheHashCalculator.php b/typo3/sysext/frontend/Classes/Page/CacheHashCalculator.php index ab69b1724b391aaddeb8235c78c3cc341fdec3ff..112aaec57cf1deb96802271e5ae8dc449376a603 100644 --- a/typo3/sysext/frontend/Classes/Page/CacheHashCalculator.php +++ b/typo3/sysext/frontend/Classes/Page/CacheHashCalculator.php @@ -49,10 +49,13 @@ class CacheHashCalculator implements SingletonInterface /** * Initialise class properties by using the relevant TYPO3 configuration + * + * @param array $configuration */ - public function __construct() + public function __construct(array $configuration = null) { - $this->setConfiguration($GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] ?? []); + $configuration = $configuration ?? $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] ?? []; + $this->setConfiguration($configuration); } /** diff --git a/typo3/sysext/frontend/Tests/Unit/Page/CacheHashCalculatorTest.php b/typo3/sysext/frontend/Tests/Unit/Page/CacheHashCalculatorTest.php index a0ac2e3da2b7a77aeea61c468587848ed143bb3b..8ef00ca5302acf13d3de89d3a99eb1c16120408b 100644 --- a/typo3/sysext/frontend/Tests/Unit/Page/CacheHashCalculatorTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Page/CacheHashCalculatorTest.php @@ -24,24 +24,32 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class CacheHashCalculatorTest extends UnitTestCase { /** - * @var \TYPO3\CMS\Frontend\Page\CacheHashCalculator + * @var CacheHashCalculator */ protected $subject; + /** + * @var array + */ + protected $configuration = [ + 'excludedParameters' => ['exclude1', 'exclude2'], + 'cachedParametersWhiteList' => [], + 'requireCacheHashPresenceParameters' => ['req1', 'req2'], + 'excludedParametersIfEmpty' => [], + 'excludeAllEmptyParameters' => false + ]; + protected function setUp(): void { parent::setUp(); $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 't3lib_cacheHashTest'; - $this->subject = $this->getMockBuilder(CacheHashCalculator::class) - ->setMethods(['foo']) - ->getMock(); - $this->subject->setConfiguration([ - 'excludedParameters' => ['exclude1', 'exclude2'], - 'cachedParametersWhiteList' => [], - 'requireCacheHashPresenceParameters' => ['req1', 'req2'], - 'excludedParametersIfEmpty' => [], - 'excludeAllEmptyParameters' => false - ]); + $this->subject = new CacheHashCalculator($this->configuration); + } + + protected function tearDown(): void + { + unset($this->subject); + parent::tearDown(); } /** @@ -193,9 +201,10 @@ class CacheHashCalculatorTest extends UnitTestCase */ public function canWhitelistParameters($params, $expected) { - $method = new \ReflectionMethod(CacheHashCalculator::class, 'setCachedParametersWhiteList'); - $method->setAccessible(true); - $method->invoke($this->subject, ['whitep1', 'whitep2']); + $configuration = array_merge($this->configuration, [ + 'cachedParametersWhiteList' => ['whitep1', 'whitep2'] + ]); + $this->subject = new CacheHashCalculator($configuration); self::assertEquals($expected, $this->subject->generateForParameters($params)); }