Skip to content

Commit

Permalink
[TASK] Provide encryptionKey in unit tests
Browse files Browse the repository at this point in the history
Since TYPO3 12.4.11 and 11.5.35 the encryptionKey is not initialized
in the default configuration, thus some unit tests will fail.

This commit ensures an encryptionKey is set for the unit tests.

Ports: #3959
Resolves: #3958
  • Loading branch information
dkd-friedrich committed Feb 22, 2024
1 parent 1f382ce commit cba463b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
20 changes: 1 addition & 19 deletions Tests/Unit/Domain/Variants/IdBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,14 @@
*/
class IdBuilderTest extends UnitTest
{
/**
* @var string
*/
protected $oldEncryptionKey;

protected function setUp(): void
{
$this->oldEncryptionKey = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'testkey';
parent::setUp();
}

protected function tearDown(): void
{
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = $this->oldEncryptionKey;
parent::tearDown();
}

/**
* @test
*/
public function canBuildVariantId()
{
$build = new IdBuilder();
$variantId = $build->buildFromTypeAndUid('pages', 4711);
self::assertSame('e99b3552a0451f1a2e7aca4ac06ccaba063393de/pages/4711', $variantId);
self::assertSame('c523304ea47711019595d2bb352b623d1db40427/pages/4711', $variantId);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions Tests/Unit/UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,25 @@
abstract class UnitTest extends UnitTestCase
{
protected $resetSingletonInstances = true;
protected ?string $originalEncryptionKey;

protected function setUp(): void
{
date_default_timezone_set('Europe/Berlin');
$this->originalEncryptionKey = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] ?? null;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'solr-tests-secret-encryption-key';
parent::setUp();
}

protected function tearDown(): void
{
unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']);
if ($this->originalEncryptionKey !== null) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = $this->originalEncryptionKey;
}
parent::tearDown();
}

/**
* Returns a mock class where every behaviour is mocked, just to full fill
* the datatype and have the possibility to mock the behaviour.
Expand Down

0 comments on commit cba463b

Please sign in to comment.