Skip to content
Snippets Groups Projects
Commit 50b5e861 authored by Oliver Hader's avatar Oliver Hader Committed by Benni Mack
Browse files

[TASK] Streamline CacheHashCalculator test case

Injects configuration to constructor directly, avoids using
MockBuilder to define internal values (part of configuration).

Resolves: #90230
Releases: master, 9.5
Change-Id: I7759b071192ed09572f3a7ed7e7779e51a4eb9f4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63058


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
parent 5d5e263a
Branches
Tags
No related merge requests found
......@@ -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);
}
/**
......
......@@ -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));
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment